twitter and GSM shield

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()
{
}

Hi Alessandro:

It's great to have that porting. I have taken the liberty to use your bridge for some demos and it runs smooth, so it's great to have an "official" implementation, I'll use it if you don't mind. I've found no problems using the Bluevia SIM, as it is pure outgoing TCP/IP traffic.

Have you thought of changing the library so it runs with any kind of client class? Or do you want me to take a try?

Best regards.

Hi zorzano,

nice to hear that everything is working... thank you!

off course will be great to have the library working on every kind of client class...
will be great if you can do it...

thank you

alessandro

hi, i have only a question, where i should put the token and if it is oauth_token from twitter

thank´s

You get the token at http://arduino-tweet.appspot.com/

I think the token goes instead of "TWITTER TALK"

ok´s its fine but i have problems to acces via apn to mi shield its a atwin 139
http://www.linksprite.com/product/showproduct.php?lang=en&id=187
it doesn´t has a library, but has a datasheet of at command, can you bring me some help ?? whit apn autentification thank¨s

hi andresorihuela,

about the talk... is correct what zorzano sad, you can get the token and put it in the "TWITTER TALK" field...

unfortunately my code depend on the GSM.h library... so i think that it should work only with the official arduino GSM shield.

have fun

alessandro

hi, alessandro

i think i have some skills about AT commands and perharps for the modification about the libraries on gsm.h
unfortunally i can´t success the APN autentification, because my shield use command and its hard to handle LOL
i wish to cooperate on this projects together

you know anything about oauth API v1.1 on twitter it will change the way to access and it might be make don´t work the actual Twitter.h
library

Hi Alessandro,
it´s really great to have this porting.
I have tested it with original arduino GSM Shield from Telefónica (with Bluevia SIM Card) and works fine.
Tks to share this solution.

hi , i have this:

#include <GSM.h>
#include <SPI.h>
#include<ThingSpeak.h>
#define PINNUMBER ""

//DEFINIR EL APN ,LOGIN Y PASSWORD

#define GPRS_APN "internet.itelcel.com" // replace with your GPRS APN
#define GPRS_LOGIN "webgprs" // replace with your GPRS login
#define GPRS_PASSWORD "webgprs2002" // replace with your GPRS password
GSMClient instanciaclient;//accede ala web
GPRS instanciagprs;
GSM instanciagsm;

//definir el servidor y el API key

char * servidor = "api.thingspeak.com";
String thingtweetAPIKey = "U9LH1YJPDMBZSKH9";
//DEFINIR LOS TIEMPOS DE MUESTREO
unsigned long tiempoUltimaConexion = 0;
const unsigned long Intervalo = 16000;
boolean ultimavezConectado = false;

long lastConnectionTime = 0;
boolean lastConnected = false;
int failedCounter = 0;

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
boolean noConectado=true;

while(noConectado)
{
if((instanciagsm.begin(PINNUMBER)==GSM_READY)&&
(instanciagprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY))
noConectado = false;
else
{
Serial.println("No conectado");
delay(1000);
}
}
updateTwitterStatus("mensaje a enviar, message to send to twitter");

}

void loop() {
// put your main code here, to run repeatedly:

//SI HAY DATOS del SERVIDOR al cliente
if(instanciaclient.available())
{
char c =
Serial.print(c);
}

if(!instanciaclient.connected() && ultimavezConectado)
{
instanciaclient.stop();
}

if(!instanciaclient.connected() && ((millis()- tiempoUltimaConexion)>Intervalo))
{
}

ultimavezConectado = instanciaclient.connected();
}

void updateTwitterStatus(String tsData)
{
if (instanciaclient.connect(servidor, 80))
{
// Create HTTP POST Data

tsData = "api_key="+thingtweetAPIKey+"&status="+tsData;

instanciaclient.print("POST /apps/thingtweet/1/statuses/update HTTP/1.1\n");
instanciaclient.print("Host: api.thingspeak.com\n");
instanciaclient.print("Connection: close\n");
instanciaclient.print("Content-Type: application/x-www-form-urlencoded\n");
instanciaclient.print("Content-Length: ");
instanciaclient.print(tsData.length());
instanciaclient.print("\n\n");

instanciaclient.print(tsData);

lastConnectionTime = millis();

if (instanciaclient.connected())
{
Serial.println("Connecting to ThingSpeak...");
Serial.println();

failedCounter = 0;
}
else
{
failedCounter++;

Serial.println("Connection to ThingSpeak failed ("+String(failedCounter, DEC)+")");
Serial.println();
}

}
else
{
failedCounter++;

Serial.println("Connection to ThingSpeak Failed ("+String(failedCounter, DEC)+")");
Serial.println();

lastConnectionTime = millis();
}
}

//////////////////////////////////////////////////
this is using one GSM Shield v2 with modem M10 and arduino uno for connect via thingspeak toward Twitter
I hope you serve them... if someone, You can improve it, thank you good night