Hello!!
I got SIM900 modem and its connected to arduino, and I do have code to fetch my twitter account, I want to do something similar to TwitterClientlient http://arduino.cc/en/Tutorial/TwitterClient
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3);
void setup()
{
mySerial.begin(19200);
Serial.begin(19200);
Serial.println("Config SIM900...");
delay(20000);
Serial.println("Done!...");
mySerial.flush();
Serial.flush();
mySerial.println("AT+CSQ");
delay(100);
mostraDadosSerial();
mySerial.println("AT+CGATT?");
delay(100);
mostraDadosSerial();
mySerial.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");
delay(2000);
mostraDadosSerial();
mySerial.println("AT+SAPBR=3,1,\"APN\",\"gprs.oi.com.br\"");
delay(2000);
mostraDadosSerial();
mySerial.println("AT+SAPBR=1,1");
delay(2000);
mostraDadosSerial();
}
void loop()
{
mySerial.println("AT+HTTPINIT");
delay(3500);
mostraDadosSerial();
mySerial.println("AT+HTTPPARA=\"URL\",\"http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=remopte\"");
delay(1000);
mostraDadosSerial();
mySerial.println("AT+HTTPACTION=0");
delay(10000);
mostraDadosSerial();
mySerial.println("AT+HTTPREAD");
mostraDadosSerial();
delay(300);
mySerial.println("AT+HTTPTERM");
mostraDadosSerial();
delay(300);
mySerial.println("");
delay(40000);
}
void mostraDadosSerial()
{
while(mySerial.available()!=0)
{
Serial.write(mySerial.read());
}
}
And here is what I get from serial output:
Config SIM900...
Done!...
AT+CSQ
+CSQ: 28,0
OK
AT+CGATT?
+CGATT: 1
OK
AT+SAPBR=3,1,"CONTYPE","GPRS"
OK
AT+SAPBR=3,1,"APN","gprs.oi.com.br"
OK
AT+SAPBR=1,1
OK
AT+HTTPINIT
OK
AT+HTTPPARA="URL","http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=remopte"
OK
AT+HTTPACTION=0
OK
+HTTPACTION:0,200,2543
AT+HTTPREAD
+HTTPREAD:2543
<?xml version="1.0" encoding="UTF-8"?>
<statuses type="array">
<status>
<created_at>Tue Aug 21 03:05:52 +0000 2012</created_at>
<id>237747319347499009</id>
<text>Tweet Remote Control</text>
<source>web</sou a/muapai
it//lgoaetr ono/ rl>fdDkroooorlrlorDil io/aoeftt +e _vn_o <
ea:chgem ag>wemfuh rabiragio a/ er<ts<ntnaira o_ fu
tglaoo ul_n>ie/alo>_w >rw< /O
I need to take the tweet, that is between "here is the tweet"
Can someone please help ?
system
September 18, 2012, 3:05pm
2
I need to take the tweet, that is between "here is the tweet"
Can someone please help ?
In mostraDadosSerial(), you have to do more than print the software serial data to the hardware serial port. You need to collect it in a NULL terminated character array, dealing with the data in that array whenever an end-of-record marker (carriage return or line feed, maybe) appears.
You can use strstr() to determine if the string contains "", and, if so, you can then locate the start of the data of interest. You can then determine if the string contains "<\text>". If so, put another NULL in place of the "<", and all that will be left will be the text of interest.
Thank you =)
its done:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3);
String linhaAtual = "";
String tweet = "";
boolean lendoTweet = false;
void setup()
{
mySerial.begin(19200);
Serial.begin(19200);
Serial.println("Config SIM900...");
delay(20000);
Serial.println("Done!...");
mySerial.flush();
Serial.flush();
mySerial.println("AT+CSQ");
delay(100);
mostraDadosSerial();
mySerial.println("AT+CGATT?");
delay(100);
mostraDadosSerial();
mySerial.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");
delay(2000);
mostraDadosSerial();
mySerial.println("AT+SAPBR=3,1,\"APN\",\"gprs.oi.com.br\"");
delay(2000);
mostraDadosSerial();
mySerial.println("AT+SAPBR=1,1");
delay(2000);
mostraDadosSerial();
}
void loop()
{
mySerial.println("AT+HTTPINIT");
delay(3500);
mostraDadosSerial();
mySerial.println("AT+HTTPPARA=\"URL\",\"http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=remopte\"");
delay(1000);
mostraDadosSerial();
mySerial.println("AT+HTTPACTION=0");
delay(15000);
mostraDadosSerial();
mySerial.println("AT+HTTPREAD");
delay(15000);
while (mySerial.available()>0)
{
char inChar = mySerial.read();
linhaAtual += inChar;
if (inChar == '\n')
{
linhaAtual = "";
}
if (linhaAtual.endsWith("<text>"))
{
lendoTweet = true;
tweet = "";
}
if (lendoTweet)
{
if (inChar != '<')
{
tweet += inChar;
}
else
{
lendoTweet = false;
Serial.println(tweet);
Serial.println(tweet);
}
}
}
mySerial.println("");
mySerial.println("AT+HTTPTERM");
mostraDadosSerial();
delay(300);
mySerial.println("");
delay(50000);
}
void mostraDadosSerial()
{
while(mySerial.available()!=0)
{
Serial.write(mySerial.read());
}
}
Config SIM900...
Done!...
AT+CSQ
+CSQ: 29,0
OK
AT+CGATT?
+CGATT: 1
OK
AT+SAPBR=3,1,"CONTYPE","GPRS"
OK
AT+SAPBR=3,1,"APN","gprs.oi.com.br"
OK
AT+SAPBR=1,1
OK
AT+HTTPINIT
OK
AT+HTTPPARA="URL","http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=remopte"
OK
AT+HTTPACTION=0
OK
+HTTPACTION:0,200,2543
>Tweet Remote Control
>Tweet Remote Control
system
September 18, 2012, 3:17pm
4
String linhaAtual = "";
String tweet = "";
Bzzzt. Who said anything about Strings? This will bite you in the ass sooner or later.