I found that very helpful @ArduinoDeurbel! However, I have done what you did and it doesn’t work.
I want Arduino to get the last tweet from my account (@tuitduino) through the PHP script where I wrote the oauth keys, the user, etc. and display the tweet in the serial monitor.
I installed “Wampserver2.4-x86” and I put it online. In the path “C:\wamp\www” I put the file “TwitterAPIExchange.php” and I created a text note called “tuitduino.txt” with this code:
<?php
require_once('TwitterAPIExchange.php');
$settings = array(
'oauth_access_token' => "XXX",
'oauth_access_token_secret' => "XXX",
'consumer_key' => "XXX",
'consumer_secret' => "XXX"
);
$url = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
$getfield = '?screen_name=tuitduino';
$requestMethod = 'GET';
$twitter = new TwitterAPIExchange($settings);
$json = $twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest();
$obj = json_decode($json, true);
$tweet = $obj["statuses"][0]["text"];
echo "$tweet";
?>
and I saved it as PHP file (“tuitduino.php”).
Then, I loaded my Arduino sketch:
#include <SPI.h>
#include <Ethernet.h>
#include <TextFinder.h>
byte Mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x01 };
byte Ip[] = { 192, 168, 1, 3 };
byte Dns[] = { 62, 81, 16, 164 };
byte Gateway[] = { 192, 168, 1, 1 };
byte Subnet[] = { 255, 255, 255, 0 };
char host[] = “http://localhost/”;
EthernetClient client;
char tweet[140] = “”, oldTweet[140] = “”;
void setup()
{
Serial.begin(9600);
Ethernet.begin(Mac, Ip, Dns, Gateway, Subnet);
for (int i = 0; i < 140; i++)
{
oldTweet[i] = 0;
tweet[i] = 0;
}
delay(1000);
}
void loop()
{
int i;
Serial.println(“Connecting to server…”);
if (client.connect(host, 80))
{
Serial.println(“Connected”);
client.println("GET /tuitduino.php HTTP/1.1");
client.print("Host: ");
client.println(host);
client.println("User-Agent: Arduino/1.0");
client.println();
TextFinder finder(client);
while (client.connected())
{
Serial.println("Client is still connected");
if (client.available())
{
Serial.println("Client available");
Serial.println("Searching for the last tweet...");
if ( finder.getString("<tweet>", "</tweet>", tweet, 140) != 0 )
{
for (i = 0; i < 140; i++)
if (oldTweet[i] != tweet[i]) break;
if (i != 140)
{
Serial.println(tweet);
for (i = 0; i < 140; i++)
oldTweet[i] = tweet[i];
break;
}
}
Serial.println("End of finder");
}
Serial.println("Client not available");
}
delay(1);
client.stop();
Serial.println("Client stopped");
}
else { Serial.println(“Connection failed”); }
delay (30000);
}
but I get the following response in the serial monitor:
Connecting to server…
Connected
Client stopped
It doesn’t find any tweet. I don’t understand it. Coud someone help me please?
And can I see the tweet by writing on the browser “localhost/tuitduino.php”? I write this but it’s all in blank.