I must be doing something wrong. I have stripped my code down to the bare essentials, and added server.log() at almost every step of the process. Things still hang after a day or so.
Server log looks like IMP went to sleep and never wakes up.
Section of log ... Tuesday, October 23, 2012 23:24:42: show: Capture: 68.05F Tuesday, October 23, 2012 23:24:42: Main: ran Capture Tuesday, October 23, 2012 23:24:42: Main: Going to call OnIdle Tuesday, October 23, 2012 23:24:42: sleeping until 1351056315000 Tuesday, October 23, 2012 23:25:21: Main: finished imp config ========================================== Tuesday, October 23, 2012 23:25:21: Capture: entered capture: Next will call get_temp.... Tuesday, October 23, 2012 23:25:21: get_temp : entered get_temp Tuesday, October 23, 2012 23:25:21: get_temp : little sleep before reading A-D Tuesday, October 23, 2012 23:25:22: get_temp : read the A-D Tuesday, October 23, 2012 23:25:22: get_temp : caculate reading in F Tuesday, October 23, 2012 23:25:22: get_temp :** Ver 1.4 ** Tuesday, October 23, 2012 23:25:22: get_temp :F : 67.761 Tuesday, October 23, 2012 23:25:22: get_temp :WIFI Signal : -54 dBm Tuesday, October 23, 2012 23:25:22: Capture: goint to put temp in output. Tuesday, October 23, 2012 23:25:22: Main: ran Capture Tuesday, October 23, 2012 23:25:22: Main: Going to call OnIdle Tuesday, October 23, 2012 23:25:22: sleeping until 1351056355000 Tuesday, October 23, 2012 23:25:22: show: Capture: 67.76F
The log stops there.
Here is a full listing of my code
`// Read Temp sensor on pin 2
// My test setup has
// Analog Devices TMP36 connected to pin 2
// 10 K pot connected to pin 1
// Switch connected to pin 8
// Ver 1.1 added server log after sleep at end of code (trying to find why code is hanging up)
// Ver 1.2 Moved deep sleep stuff into function instead of main. Also bunched togethor conversion to F from counts
// Ver 1.3 Averaging of multi A-D throeing out one
// Ver 1.4 Not averaging (simplified trying to find out why things hang up)
// Set up to output data to server
local output = OutputPort(“Temperature”, “number”);
function get_temp()
{
// Variable to store A-D (raw countes)
server.log(“get_temp : entered get_temp”)
local counts;
local readingF;
// letting IMP rest before hitting the A-D
server.log(“get_temp : little sleep before reading A-D”)
imp.sleep(0.5);
server.log(“get_temp : read the A-D”)
counts = hardware.pin2.read();
server.log(“get_temp : caculate reading in F”)
readingF = (9.0/5.0) * (((counts / 19859.09) - 0.5) * 100) + 32;
server.log(“get_temp :** Ver 1.4 **”);
server.log("get_temp :F : " + readingF);
server.log(format(“get_temp :WIFI Signal : %d dBm”, imp.rssi()));
return readingF;
}
function capture()
{
server.log(“Capture: entered capture: Next will call get_temp…”);
// Output the temperature
local temp = get_temp();
// Display the temp
server.show(format(“Capture: %3.2fF”, temp));
// Put the temp out on the server
server.log(“Capture: goint to put temp in output.”);
output.set(temp);
}
// On the forums I found that you are not supposed to put sleepfor in the main (can block firmware upgrades)
// They sudgest putting it in an sub function like this.
function onidle()
{
// Try Deep sleep fo 1 min
server.sleepfor(30);
}
// Configure pin 2 as Analog input
hardware.pin2.configure(ANALOG_IN);
// Register with the server
imp.configure(“Temp Mon”, [], [output]);
server.log(“Main: finished imp config ==========================================”);
// Read temp
capture();
server.log(“Main: ran Capture”);
// Call Idel function which will then call the deep sleep
server.log(“Main: Going to call OnIdle”);
imp.wakeup(0.5, onidle);
// End of code.`
My intent is to read the A-D pin every 30s (give or take a few seconds). Convert the A-D value into temperature. Show that temperature on the planer, and update that temp on COSM. It works fine for a while, and then something gets stuck.