hi all,
i just do my first tweet using the GSM shield,
I modify a little bit the twitter.h library, than I mix the code of the examples in the arduino software.
I mix the GsmTwitterClient example and the SimplePost example of the Twitter library.
I will post all here following waiting some feedbacks and off course to simplify it and fix some bugs in it.
as in the simplepost example you need to get YOUR TOKEN to tweet here: http://arduino-tweet.appspot.com/
in the Twitter.h lib at line 21 I substitute first the
#include <Ethernet.h>
#if defined(ARDUINO) && ARDUINO < 100 // earlier than Arduino 1.0
#include <EthernetDNS.h>
#endif
with
#include <GSM.h>
//#if defined(ARDUINO) && ARDUINO < 100 // earlier than Arduino 1.0
//#include <EthernetDNS.h>
//#endif
i comment the last three lines because we don't need it any more.
than at line 35 I substitute this other thing
EthernetClient client;
with
GSM3MobileClientService client;
that's it for the twitter.h lib... may be we can call it twitterGSM.h
here following i will show you the codes I mix.
this is working with my configuration (arduino UNO R3 and GSM R3 shield) even if not always post the tweet, but unfortunately i think this only depend on the italian GSM provider TIM (telecom italia mobile).
that's it.
looking forward some feedbacks and don't forget to include me @ales9000 when you tweet from your GMS shield...
arduino rock!
alessandro
#include <SPI.h> // needed in Arduino 0019 or later
#include <Twitter.h>
//#include <Ethernet.h>
#include <GSM.h>
// PIN Number
#define PINNUMBER ""
// APN data
#define GPRS_APN "APN" // replace your GPRS APN
#define GPRS_LOGIN "login" // replace with your GPRS login
#define GPRS_PASSWORD "password" // replace with your GPRS password
// The includion of EthernetDNS is not needed in Arduino IDE 1.0 or later.
// Please uncomment below in Arduino IDE 0022 or earlier.
//#include <EthernetDNS.h>
// initialize the library instance
GSMClient client;
GPRS gprs;
GSM gsmAccess;
//const unsigned long requestInterval = 30*1000; // delay between requests: 30 seconds
// API Twitter URL
char server[] = "api.twitter.com";
//twitter talk
Twitter twitter("TWITTER TALK");
// Message to post
char msg[] = "Hello, World!";
void setup() {
{
// initialize serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// connection state
boolean notConnected = true;
// After starting the modem with GSM.begin()
// attach the shield to the GPRS network with the APN, login and password
while(notConnected)
{
if((gsmAccess.begin(PINNUMBER)==GSM_READY) &
(gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY))
notConnected = false;
else
{
Serial.println("Not connected");
delay(1000);
}
}
Serial.println("Connected to GPRS network");
}
{
delay(1000);
Serial.println("connecting ...");
if (twitter.post(msg)) {
// Specify &Serial to output received response to Serial.
// If no output is required, you can just omit the argument, e.g.
// int status = twitter.wait();
int status = twitter.wait(&Serial);
if (status == 200) {
Serial.println("OK.");
} else {
Serial.print("failed : code ");
Serial.println(status);
}
} else {
Serial.println("connection failed.");
}
}
}
void loop()
{
}