Pages: [1]   Go Down
Author Topic: 2 LM35´s with a ethernet shield posting to pachube  (Read 2752 times)
0 Members and 1 Guest are viewing this topic.
Austria
Offline Offline
Sr. Member
****
Karma: 3
Posts: 260
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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  smiley

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  smiley-wink

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

maybe later i will replace the breadboard with a small print, but thats so much work, compared to the breadboard  smiley-razz
« Last Edit: April 21, 2009, 02:36:40 pm by designer2k2 » Logged


0
Offline Offline
Newbie
*
Karma: 0
Posts: 48
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

uhm i like it! smiley
Logged

Austria
Offline Offline
Sr. Member
****
Karma: 3
Posts: 260
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Rommtemp:



Outside:


(Thats the current Temperature in Innsbruck/Austria  smiley-grin)



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():

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

and the "pachube_update"

Code:
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...

« Last Edit: April 24, 2009, 03:09:40 am by designer2k2 » Logged


0
Offline Offline
Newbie
*
Karma: 0
Posts: 1
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

Code:
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!
Logged

Austria
Offline Offline
Sr. Member
****
Karma: 3
Posts: 260
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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...
Logged


0
Offline Offline
Newbie
*
Karma: 0
Posts: 15
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Code:
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 ???

Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 654
Posts: 50931
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 15
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Austria
Offline Offline
Sr. Member
****
Karma: 3
Posts: 260
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

the inputs have changed, so my old first post is wrong  smiley-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...

Logged


0
Offline Offline
Sr. Member
****
Karma: 18
Posts: 402
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 15
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ?
« Last Edit: December 07, 2009, 05:04:09 am by Yan78 » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 15
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

see it here !

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

smiley
Logged

Rural Arizona
Offline Offline
Edison Member
*
Karma: 7
Posts: 1711
Incorrigible tinkerer
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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...
Logged

Pages: [1]   Go Up
Jump to: