2 LM35´s with a ethernet shield posting to pachube

Hello,

the Temperature in my "Workroom": (its in °C, over the last 24h)

or combined: http://www.designer2k2.at/pachube.php

the Hardware:


its a Arduino Duemilanove + a Ethernet shield + small Breadboard + 80mm PC Fan (running at only 5V) + Lego

the Fan is running at 5V, so very slow, but enough to get the LM35´s very precise :slight_smile:

i calibratet the LM35´s with a thermocouple (about 1,4°C error on both)

here both sensors can be seen idividual: http://www.pachube.com/feeds/1761/

on the Arduino im running the "Pachube code" nothing special there...

the Charts are drawn with the Google Chart Api, nice stuff :wink:

im Powering this thing with a USB MP3 Charger, couldnt finde a cheaper and easier powersource ::slight_smile:

maybe later i will replace the breadboard with a small print, but thats so much work, compared to the breadboard :stuck_out_tongue:

uhm i like it! :slight_smile:

Rommtemp:

Outside:


(Thats the current Temperature in Innsbruck/Austria :D)


About the code on the Arduino:

im running this code on the Arduino: http://community.pachube.com/node/112

only modification is here:

in the void setup():

  analogReference(INTERNAL);                      //gets nicer precision for the the LM35´s

and the "pachube_update"

char data[128];
boolean found_status_200 = false;
boolean found_content_length = false;
boolean found_CSV = false;
char *found;
unsigned int successes = 0;
unsigned int failures = 0;
boolean ready_to_update = true;
boolean reading_pachube = false;

boolean request_pause = false;
boolean found_content = false;

int val1 = 0;
int val2 = 0;
int val3 = 0;
int val4 = 0;

unsigned long last_connect;

void pachube_in_out(){
  if (request_pause){
    if ((millis() - last_connect) > interval){
      
      ready_to_update = true;
      reading_pachube = false;
      request_pause = false;
      found_status_200 = false;
      found_content_length = false;
      found_CSV = false;

      Serial.print("Ready to connect: ");
      Serial.print(last_connect);
      Serial.print(" - ");
      Serial.print(interval);
      Serial.print(" - ");
      Serial.println(millis());
    }
  }

  if (ready_to_update){
    Serial.println("Connecting...");
    if (localClient.connect()) {
      
      // here we assign comma-separated values to 'data', which will update Pachube datastreams
      // we use all the analog-in values, but could of course use anything else (millis(), digital
      // inputs, etc. . i also like to keep track of successful and failed connection
      // attempts, sometimes useful for determining whether there are major problems.
      
      //sprintf(data,"%d,%d,%d,%d,%d,%d,%d,%d",analogRead(0),analogRead(1),analogRead(2),analogRead(3),analogRead(4),analogRead(5), successes + 1, failures);
      
            
            val1 = 0;
            val2 = 0;
            val4 = 0;
            
            for (int i2 = 0; i2 < 10; i2++) {
              delay(10);
              val1 = val1 + analogRead(0);
              delay(10);
              val2 = val2 + analogRead(1);
              delay(10);
              val4 = val4 + analogRead(2);
            }
            
            val1 = val1 / 10.0;
            val2 = val2 / 10.0;
            val4 = val4 / 10.0;
                 
      val1 = ((val1*110.0/1023.0)-1.55)*1000.0;
      val2 = ((val2*110.0/1023.0)-1.45)*1000.0;
      val4 = ((val4*110.0/1023.0)-4.60)*1000.0;
     
      val3 = val1/2+val2/2;
      
      
      Serial.print("Temp0: ");
      Serial.print(val1);
      Serial.print(" C Temp1: ");
      Serial.print(val2);
      Serial.print(" C Temp2: "); 
      Serial.print(val4);
      Serial.println(" C"); 
      
            
      sprintf(data,"%d,%d,%d,%d,%d,%d,%d,%d",val1,val2,val4,val2/1000,val3,val3/1000, successes + 1, failures);

      Serial.println("GET request to retrieve");

      localClient.print("GET /api/");
      localClient.print(REMOTE_FEED_ID);
      localClient.print(".csv HTTP/1.1\nHost: pachube.com\nX-PachubeApiKey: ");
      localClient.print(PACHUBE_API_KEY);
      localClient.println("\n");

      Serial.println("finished GET now PUT, to update");

      localClient.print("PUT /api/");
      localClient.print(SHARE_FEED_ID);
      localClient.print(".csv HTTP/1.1\nHost: pachube.com\nX-PachubeApiKey: ");
      localClient.print(PACHUBE_API_KEY);
      localClient.print("\nContent-Type: text/csv\nContent-Length: ");
      localClient.print(strlen(data));
      localClient.print("\nConnection: close\n\n");
      localClient.print(data);
      localClient.print("\n");

      ready_to_update = false;
      reading_pachube = true;
      request_pause = false;
      interval = UPDATE_INTERVAL;
      

      Serial.print("finished PUT: ");
      Serial.println(millis());

    } 
    else {
      Serial.print("connection failed! ");
      Serial.println(++failures);
      found_status_200 = false;
      found_content_length = false;
      found_CSV = false;
      ready_to_update = false;
      reading_pachube = false;
      request_pause = true;
      last_connect = millis();
      interval = RESET_INTERVAL;
      setupEthernet();
    }
  }

  while (reading_pachube){
    while (localClient.available()) {
      checkForResponse();
    } 

    if (!localClient.connected()) {
      disconnect_pachube();
    }
  } 
}

void disconnect_pachube(){
  Serial.println("disconnecting.");
  localClient.stop();
  localClient.flush();
  ready_to_update = false;
  reading_pachube = false;
  request_pause = true;
  last_connect = millis();
  found_content = false;
  resetEthernetShield();
}


void checkForResponse(){  
  char c = localClient.read();
  //Serial.print(c);
  buff[pointer] = c;
  if (pointer < 64) pointer++;
  if (c == '\n') {
    found = strstr(buff, "200 OK");
    if (found != 0){
      found_status_200 = true; 
      Serial.println("Status 200");
    }
    buff[pointer]=0;
    found_content = true;
    clean_buffer();    
  }

  if ((found_content_length) && (!found_CSV)){
    found = strstr(buff, "HTTP/1.1");
    if (found != 0){
      char csvLine[strlen(buff)-9];
      strncpy (csvLine,buff,strlen(buff)-9);

      //Serial.println("This is the retrieved CSV:");     
      //Serial.println("---");     
      //Serial.println(csvLine);
      //Serial.println("---");   
      //Serial.println("\n--- updated: ");
      //Serial.println(data);
      //Serial.println("\n--- retrieved: ");
      char delims[] = ",";
      char *result = NULL;
      char * ptr;
      result = strtok_r( buff, delims, &ptr );
      int counter = 0;
      while( result != NULL ) {
        remoteSensor[counter++] = atof(result); 
        result = strtok_r( NULL, delims, &ptr );
      }  
      for (int i = 0; i < REMOTE_FEED_DATASTREAMS; i++){
        Serial.print( (int)remoteSensor[i]); // because we can't print floats
        Serial.print("\t");
      }

      found_CSV = true;

      Serial.println(" ");
      Serial.print("successful updates=");
      Serial.println(++successes);

    }
  }

  if (found_status_200){
    found = strstr(buff, "Content-Length: ");
    if (found != 0){
      found_content_length = true; 
    }
  }
}

this outputs the analog0,1 and 2 to Pachube, and makes a mean of 10 measurements before sending...

Hi designer2k2, your project is very nice! I'm trying to use pachube too, but have some troubles understanding the code of the example you used. Where did you read in the Arduino code your sensors...?
Should be around here:

void loop()
{
  
  // call 'pachube_in_out' at the beginning of the loop, handles timing, requesting
  // and reading. use serial monitor to view debug messages
  
  pachube_in_out();
  
  // then put your code here, you can access remote sensor values
  // by using the remoteSensor float array, e.g.: 
  
  analogWrite(3, (int)remoteSensor[3] * 10); // remoteSensor is a float
  analogWrite(5, (int)remoteSensor[1]); 

  // you can have code that is time sensitive (e.g. using 'delay'), but 
  // be aware that it will be affected by a short pause during connecting
  // to and reading from ethernet (approx. 0.5 to 1 sec).
  // e.g. this code should carry on flashing regularly, with brief pauses
  // every few seconds during Pachube update.
  
  digitalWrite(6, HIGH);
  delay(100);
  digitalWrite(6, LOW);
  delay(100);
  
}

And what's the "remote sensor", I actually don't need to read other's pachube sensors feed.
Hope you have clearer ideas than mine... :-/

Thankyou

Ciao!

you should go with the new lib from pachube: http://community.pachube.com/arduino/ethernet

my code is based on the old one and works not so stable...

Great job ! I'm trying to do the same thing but I don't understand how to upload floating data . In your code you upload decimal data

sprintf(data,"%d,%d,%d,%d,%d,%d,%d,%d",val1,val2,val4,val2/1000,val3,val3/1000, successes + 1, failures);

but on the pachube I see you have floating numbers . HOW can I do the same ???

1.22C indoors and 17.79 outdoors? I'd open a door, I think.

Here is my data .
http://www.pachube.com/feeds/3742

please see my feed: http://www.pachube.com/feeds/1761/

the inputs have changed, so my old first post is wrong :wink:

but the output sensor ist not right, currently we have around -5°C at night but the sensor never goes below 3°C as the LM35 in basic circuit cannot show negative numbers...

Hi,

Use LM34's
They have better resolution and can go negative °C
You need to convert from °F to °C within your code

Nice job

I still have some questions !

I don't understand how to upload floating data . In my arduino temp is 26.52 C . But i have to uplod 26 C because of the sprintf .

One way is to upload 26.52 * 100 = 2652 and in pachube to divide the value by 100 . Is it possible ?

finally ! I did it ! Now I do upload data with floating point .

see it here !

http://www.pachube.com/feeds/3747

:slight_smile:

I'd open a door, I think.

Or call the SETI hotline, and ask if there's a reward for directing them to a visitor from a really cold planet...