Having as starting point http://arduino-tweet.appspot.com/ I modified my previous code to this one:
#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, 9, 122 }; // 192.168.9.122
// Your Token to Tweet (get it from http://arduino-tweet.appspot.com/)
Twitter twitter("please put here your token");
// Message to post - just to initialize the variable
char msg[] = "Hello, World! I'm Arduino!";
void setup()
{
delay(10000);
Serial.begin(9600);
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
for(;;)
;
}
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.");
}
}
//Temperaturmessung
//*
int temp = 1;
int oldtemp = 1;
int val;
void loop()
{
delay(30000);
val = analogRead(0);
if (val > 40) { temp = 1; }
if (val <20 ) { temp = 0; }
if (oldtemp != temp) {
oldtemp = temp;
if (temp == 1) {
//Serial.println("FEUER!");
sendTwitterUpdate("Im Gewächshaus brennt es!");
}
else {
//Serial.println("Kalt!");
sendTwitterUpdate("Es ist zu kalt für die Pflanzen!");
}
}
fetchTwitterUpdate();
}
No comments:
Post a Comment