After I finished the first test with the Ethernet shield and serving your own page from Arduino (see post here Arduino - Talking plant, with HTTP server (or how to see sensor data via internet)) I said, ok, but if I don't have my own static IP address!?!? Most of us don't have a static IP address at home. Yeah it was fun with the other one to play in a LAN or use the university network to get an own IP, but at home this device renders useless. I tried with other social networks or email providers but it looks like Facebook, Yahoo mail and Gmail have quite some problems talking with Arduino and Arduino has some problems talking with them, the only one available remained Twitter.

 

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();
}

 Now you can get more creative and do more out of it.

We use cookies

We use cookies on our website. Some of them are essential for the operation of the site, while others help us to improve this site and the user experience (tracking cookies). You can decide for yourself whether you want to allow cookies or not. Please note that if you reject them, you may not be able to use all the functionalities of the site.