Hi! I'm relatively new to the world of electronics so please bare with me.
I'm using an Arduino Uno and a compatible ethernet shield to try to tweet various weather measurements (eg. temperature, light intensity etc.). I have come across many online tutorials on using an ethernet shield to tweet but I have yet to succeed in even tweeting "Hello world!".
I found my IP address using the 'dhcpAddressPrinter' ethernet example. I know that to enable the Arduino to access twitter, an access token is needed. I have used two different approaches in getting this. The first of which, was to become a 'Twitter developer' and to create an app. I got this method from APC’s May 2023 issue is on sale now! | TechRadar . I was surprised that this didn't work especially seen as I was using the same sensor (DHT11) so I wouldn't have to change the code provided.
When this approach failed, I got an access token by using an app on http://arduino-tweet.appspot.com/ . I ran the 'SimplePost' program from the Twitter examples and 'connection failed' was the output on the serial monitor.
Here is the code for the 'SimplePost' example. I used my IP address and tried both access tokens. Anybody have any ideas what I could be doing wrong?
#include <SPI.h> // needed in Arduino 0019 or later
#include <Ethernet.h>
#include <Twitter.h>
// 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>
// Ethernet Shield Settings
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// If you don't specify the IP address, DHCP is used(only in Arduino 1.0 or later).
byte ip[] = { 192, 168, 2, 250 };
// Your Token to Tweet (get it from http://arduino-tweet.appspot.com/)
Twitter twitter("YOUR-TOKEN-HERE");
// Message to post
char msg[] = "Hello, World! I'm Arduino!";
void setup()
{
delay(1000);
Ethernet.begin(mac, ip);
// or you can use DHCP for autoomatic IP address configuration.
// Ethernet.begin(mac);
Serial.begin(9600);
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()
{
}
Apologies for any lack of information, please ask me if more is needed.
At the end of the day, all I want to do is to receive the data read by the Arduino on a device which it is not connected to (preferably a smartphone). An alternative method to using twitter would be acceptable (other than buying a GSM shield).
Thank you!