2 LM35´s with a ethernet shield posting to pachube

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