Advertisement
phillips321

Untitled

Sep 21st, 2011
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.27 KB | None | 0 0
  1. void loop()
  2. {
  3.   //--------------------------------------
  4.   // 1) Measurements and data preparation
  5.   //--------------------------------------
  6.   if ((millis()-lastupdate)>10000)
  7.   {
  8.     Serial.println("Powered up");
  9.     es.ES_enc28j60PowerUp();
  10.     ethernet_setup_dhcp_dns(mac,PACHUBE_VHOST,80,8);
  11.     delay(4000);
  12.     lastupdate = millis();
  13.      
  14.     float temperature = getVoltage(0);  //getting the voltage reading from the temperature sensor
  15.     temperature = (temperature - .5) * 100;          //converting from 10 mv per degree wit 500 mV offset
  16.    
  17.     // Convert int/double to string, add it to main string, add csv commas
  18.     // dtostrf - converts a double to a string!
  19.     // strcat  - adds a string to another string
  20.     // strcpy  - copies a string
  21.     strcpy(str,"TEMP,");
  22.     dtostrf(temperature,0,1,fstr); strcat(str,fstr);
  23.     dataReady = 1;
  24.   }
  25.  
  26.   //----------------------------------------
  27.   // 2) Send the data
  28.   //----------------------------------------
  29.   if (ethernet_ready_dhcp_dns() && dataReady==1)
  30.   {
  31.     ethernet_send_post(PSTR(PACHUBEAPIURL),PSTR(PACHUBE_VHOST),PSTR(PACHUBEAPIKEY), PSTR("PUT "),str);
  32.     Serial.println("sent"); dataReady = 0;
  33.   }
  34.     Serial.println("Powered down");
  35.     es.ES_enc28j60PowerDown();
  36.     delay(2000);
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement