1.Get a token to post a message using OAuth.
- Click at "Authorize app"
- Save you Token: xxxYouTokenxxx
2.Add some Libraries to your Arduino IDE.
- Download the Arduino Tweet Library http://arduino-tweet.appspot.com/Library-Twitter-1.3.zip
- Unzip and copy Twitter folder to you install arduino C:\Software\Arduino\arduino-1.0.3\libraries
- Re-start the Arduino IDE.
3. Run a sample sketch SimplePost to tweet!
- Open Sketch > Twitter > SimplePort
- Config you IP and Twitter Token
byte ip[] = { 192, 168, 200, 200 };
Twitter twitter(" xxxYouTokenxxx");
- Compile and Upload
- Open Serial to Check Eror
- Open you twitter to check tweet from Arduino
5.Test Tweet Temperature & Humidity from DHT11 Sensor
Source TwitterDHT11.ino
#include <SPI.h> // needed in Arduino 0019 or later
#include <Ethernet.h>
#include <Twitter.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, 200, 200};
// Your Token to Tweet (get it from http://arduino-tweet.appspot.com/)
Twitter twitter("xxxTwitterTokenxxx");
// DHT11 Defint Libraries
/*-----( Import needed libraries )-----*/
#include <dht11.h>
/*-----( Declare objects )-----*/
dht11 DHT11;
/*-----( Declare Constants,Digital Pin Numbers )-----*/
#define DHT11PIN 2
void setup()
{
delay(1000);
Ethernet.begin(mac, ip);
// or you can use DHCP for autoomatic IP address configuration.
// Ethernet.begin(mac);
Serial.begin(9600);
}
void loop()
{
String message;
int chk = DHT11.read(DHT11PIN);
switch (chk)
{
case 0: Serial.print("OK! "); break;
case -1: Serial.print("Checksum error! "); break;
case -2: Serial.print("Time out error! "); break;
default: Serial.print("Unknown error! "); break;
}
message = "Temperature (C): " + String(DHT11.temperature);
message += " Humidity (%): " + String(DHT11.humidity) ;
Serial.println(message);
tweet(message);
delay(60000);
}
void tweet(String message)
{
char msg[100] = "";
message.toCharArray(msg, 100);
Serial.println("connecting ...");
if (twitter.post(msg)) {
int status = twitter.wait();
if (status == 200) {
Serial.println("OK.");
} else {
Serial.print("failed : code ");
Serial.println(status);
}
} else {
Serial.println("connection failed.");
}
delay(1000); }
#include <Ethernet.h>
#include <Twitter.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, 200, 200};
// Your Token to Tweet (get it from http://arduino-tweet.appspot.com/)
Twitter twitter("xxxTwitterTokenxxx");
// DHT11 Defint Libraries
/*-----( Import needed libraries )-----*/
#include <dht11.h>
/*-----( Declare objects )-----*/
dht11 DHT11;
/*-----( Declare Constants,Digital Pin Numbers )-----*/
#define DHT11PIN 2
void setup()
{
delay(1000);
Ethernet.begin(mac, ip);
// or you can use DHCP for autoomatic IP address configuration.
// Ethernet.begin(mac);
Serial.begin(9600);
}
void loop()
{
String message;
int chk = DHT11.read(DHT11PIN);
switch (chk)
{
case 0: Serial.print("OK! "); break;
case -1: Serial.print("Checksum error! "); break;
case -2: Serial.print("Time out error! "); break;
default: Serial.print("Unknown error! "); break;
}
message = "Temperature (C): " + String(DHT11.temperature);
message += " Humidity (%): " + String(DHT11.humidity) ;
Serial.println(message);
tweet(message);
delay(60000);
}
void tweet(String message)
{
char msg[100] = "";
message.toCharArray(msg, 100);
Serial.println("connecting ...");
if (twitter.post(msg)) {
int status = twitter.wait();
if (status == 200) {
Serial.println("OK.");
} else {
Serial.print("failed : code ");
Serial.println(status);
}
} else {
Serial.println("connection failed.");
}
delay(1000); }
0 comments:
Post a Comment