Hi - I was wondering if I can get someone to help me
I am testing the imp to wakeup on a trigger on pin 1 and write data to the server. If it has no connectivity, I want it to store the data in nv (that part is working) and send the data when connection is established. What I have noticed is that this works when I use the default suspend_on_error policy, but when I try return_on_error, the imp goes to sleep seemingly permanently with nothing (neither the timer nor the wakeup pin) seems to wake it up.
I have posted the functional code below. Please help!
`
sense ← hardware.pin1;
sense.configure(DIGITAL_IN_WAKEUP);local dataread = 25;
local sleeptime = 20;function bootup()
{
local reasonString = “Unknown”
switch(hardware.wakereason())
{
case WAKEREASON_POWER_ON:
reasonString = “The power was turned on”
sense.configure(DIGITAL_IN_WAKEUP);
breakcase WAKEREASON_TIMER: reasonString = "An event timer fired" sense.configure(DIGITAL_IN_WAKEUP); break case WAKEREASON_SW_RESET: reasonString = "A software reset took place" break case WAKEREASON_PIN: reasonString = "Pulse detected on Wakeup Pin" sense.configure(DIGITAL_IN); break case WAKEREASON_NEW_SQUIRREL: reasonString = "New Squirrel code downloaded" break case WAKEREASON_SQUIRREL_ERROR: reasonString = "Squirrel runtime error" break case WAKEREASON_NEW_FIRMWARE: reasonString = "impOS update" break case WAKEREASON_SNOOZE: reasonString = "A snooze-and-retry event" break } server.connect(function(reason) { transmitter() } ) server.log("Reason for waking/reboot: " + reasonString)
}
function transmitter()
{
if (server.isconnected())
{
// At this point we have WiFi connected so try to add dataToSend to TCP send bufferlocal outcome = agent.send("postdata", dataread); if (outcome == 0) { // Record successful addition of data to impOS buffer by zero-ing dataToSend // This can be used to indicate dataToSend is free for more data dataread = dataread+1; //change the data to see if it has cycled through this section } else { // Couldn’t add dataToSend to the buffer OR // WiFi has been lost OR some other failure // RETURN_ON_ERROR in force so we need to re-connect before // attempting to add dataToSend to the buffer again imp.wakeup(10.0, transmitter()); } } else { // WiFi is disconnected, so attempt to reconnect as per RETURN_ON_ERROR // Whatever the outcome, we come back to transmitter(). // We can't schedule transmitter() directly as server.connect()'s // callback expects a single parameter to take outcome indicator integer server.connect(function(reason) { transmitter() } ) }
}
//run time
server.setsendtimeoutpolicy(RETURN_ON_ERROR, WAIT_TIL_SENT, 10);
//server.setsendtimeoutpolicy(SUSPEND_ON_ERROR, WAIT_TIL_SENT, 10);
bootup();
imp.onidle(function() {
server.log("Data read was" + dataread + ", now going to sleep"); server.expectonlinein(sleeptime); imp.deepsleepfor(sleeptime);
});
`