Hello everyone!
I'm having some problems with my Arduino and Twitter. I'm using an Arduino Mega 2560 with the official Arduino WiFi Shield and a 4x4 Keypad.
I want my Arduino to tweet a message every time the right password is entered on the keypad. I've managed to get the code working fine, I can tweet once, with a message that changes everytime using millis().
However, I cannot send two or more tweets unless I reset my Arduino. The problem shouldn't be related to Twitters duplicate tweet prevention system, and it shouldn't be a network or hardware related problem either.
I'm posting my code below, if you have any questions, please ask
#include <SPI.h> // needed in Arduino 0019 or later
#include <WiFi.h> // for the WiFi-shield
#include <Twitter.h> //for Twitter
#include <Keypad.h> // for the keypad
#include <Password.h> // for the password functions
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keys[ROWS][COLS] = {
{
'1','2','3','A' }
,
{
'4','5','6','B' }
,
{
'7','8','9','C' }
,
{
'*','0','#','D' }
};
byte rowPins[ROWS] = {
30, 32, 34, 36}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {
22, 24, 26, 28}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
char ssid[] = "Qwerty"; // your network SSID (name)
char pass[] = "Qwerty"; // your network password
Password password = Password( "1234" );
// Your Token to Tweet (get it from http://arduino-tweet.appspot.com/)
Twitter twitter("Qwerty");
// Message to post
char msg[140];
void setup()
{
delay(1000); //Ihan varmuuden vuoksi
WiFi.begin(ssid, pass);
sprintf(msg,"Tweet, %ld",millis());
keypad.addEventListener(keypadEvent); // Add an event listener for this keypad
}
void loop()
{
keypad.getKey(); //Get key presses
}
void keypadEvent(KeypadEvent eKey){
switch (keypad.getState()){
case PRESSED:
Serial.print("Pressed: ");
Serial.println(eKey);
switch (eKey){
case '*':
checkPassword();
break; //Check password
case '#':
password.reset();
break; // reset pass
default:
password.append(eKey);
}
}
}
void checkPassword(){
if (password.evaluate()){
(twitter.post(msg));
}
else{
//do nothing
}
}
}