void temperatureJob() { float gotTemp = 0; Serial << "the device count is " << deviceCount << endl; sensor.requestTemperatures(); // get all the tempratures first to speed up, moved up from getTemp() for (int i =0; i < deviceCount; i++ ) { gotTemp = sensor.getTempF(*deviceAddressArray[i]); if (gotTemp < -195 ) continue; Serial << "gotTemp() = " << i << " " << gotTemp << endl; request.body = formatTempToBody(gotTemp, i); // if (mycounter % PUSHFREQ == 0 && PUSHTOUBIFLAG == 1 ) { if (mycounter % PUSHFREQ == 0 && PUSHTOUBIFLAG == 1) { String mypath = String("/api/v1.6/variables/"); mypath.concat(ubivar[i]); mypath.concat("/values"); Serial << "going to push "<< request.body << " to " << mypath << endl; request.path = mypath; http.post(request, response, headers); if( debug ) Serial << "http body: " << request.body << endl; Serial << " Did we reboot? I hope not "; } if( debug) debugSerial(i); } }
void sendData() { //float temp = sensors.getTempC(thermometer); float temp = sensors.getTempF(thermometer); Serial.print("Temp="); Serial.println(temp); Serial.println("connecting..."); if (client.connect()) { Serial.println("connected"); client.print( "PUT /store/fluffy/arduinoTempA/" ); client.print(" HTTP/1.1" CRLF "User-Agent: Fluffy Arduino Ver 0.01" CRLF "Host: www.fluffyhome.com" CRLF "Accept: */" "*" CRLF // need to fix this "Content-Length: 5" CRLF "Content-Type: application/x-www-form-urlencoded" CRLF CRLF ); client.println(temp); unsigned long reqTime = millis(); // wait for a response and disconnect while ( millis() < reqTime + 10000) // wait 10 seconds for response { if (client.available()) { char c = client.read(); Serial.print(c); } if (!client.connected()) { Serial.println(); Serial.println("server disconnected"); break; } } Serial.println("client disconnecting"); Serial.println(""); client.stop(); } else { Serial.println("connection failed"); } }
char *getTemp(int tempIndex) { static char retbuf[64]; //sensor.requestTemperatures(); // I am getting the tempratures each time in the loop, try moving this up to the fuction prior to the loop // Maybe this is bad, to do it this way, I am resetting the index each time. //sensor.getAddress(deviceIndexArray[tempIndex], tempIndex); //Why do I need to get the address here? //temperature=sensor.getTempC(deviceIndexArray[tempIndex]); temperature=sensor.getTempF(deviceIndexArray[tempIndex]); //temperature=sensor.getTempCByIndex( tempIndex );// moved off of get address by index to get it by address //sprintf(retbuf, "{\"value\":%.4f}", temperature*1.8 + 32); String s = "{\"value\": "; s.concat(String(temperature)); s.concat("}"); s.toCharArray(retbuf, 64); oDispatch(tempIndex, temperature, deviceIndexArray[tempIndex]); return retbuf; }