Stability of Output ports

Hi

I have an imp reading uart data from my appartments powermeter, im using the Deepsleep example to get started - but it seems unreliable.

`
t <- time();

function hourly() {
if(nv.data != “”) {
local output = OutputPort(“data”, “string”);
imp.configure(“Kamstrup”, [], [output]);
output.set(nv.data);
} else {
server.log(“Nothing to send, first boot?”);
}

nv.data = "";
server.expectonlinein(3600);
//server.expectonlinein(120);

}

function log() {
if (!(“nv” in getroottable())) {
nv <- { data = “” };
hourly();
}
local min = (t/60) % 60;
readEverything();
if (min == 59) {
hourly();
}
imp.onidle(function() { imp.deepsleepfor(60 - (time() % 60)); });

}

log();
`

Ive modified the code to fit my needs, at first it seemed that the imp was going to deepsleep before it had time to deliver all the data .set() to the Output port, i thought i’ve fixed this issue by wrapping the deepsleep api call inside onidle. (It worked for some hours, but then this morning it stopped delivering outputs every hour, only deliverying say 1 out of 5 times).

In the logging i can see that the imp powers up on the minutte, and then goes offline again without having sent the data to my web app.

I have about ~ 2.8Kb of data in the nv. is there any way to make the delivery more stable, or somehow make it retry if it fails?

Here’s some logging:

7/3/2013 1:59:21 PM: Device booting
7/3/2013 1:59:21 PM: Device configured to be "Kamstrup"
7/3/2013 2:59:13 PM: Device booting
7/3/2013 2:59:13 PM: Device configured to be "Kamstrup"
7/3/2013 2:59:13 PM: Power state: online=>asleep

7/3/2013 3:59:14 PM: Power state: asleep=>online
7/3/2013 3:59:14 PM: Device booting
7/3/2013 3:59:14 PM: Device configured to be "Kamstrup"
7/3/2013 3:59:34 PM: Power state: online=>offline
7/3/2013 4:59:14 PM: Power state: offline=>online
7/3/2013 4:59:14 PM: Device booting
7/3/2013 4:59:14 PM: Device configured to be "Kamstrup"
7/3/2013 5:59:16 PM: Device booting
7/3/2013 5:59:16 PM: Device configured to be "Kamstrup"
7/3/2013 6:59:19 PM: Device booting
7/3/2013 6:59:19 PM: Device configured to be "Kamstrup"
7/3/2013 7:59:21 PM: Device booting
7/3/2013 7:59:21 PM: Device configured to be "Kamstrup"
7/3/2013 8:59:14 PM: Device booting
7/3/2013 8:59:39 PM: Power state: online=>offline

The text in bold is where it have actually sent some data to my webserver - The other entries the imp just seems to wake up and go offline a few seconds later (not sending my webserver any data)

Just tried to update the script with some additional logging:

The whole script can be found here logger.nut

`t <- time();

function hourly() {
if(nv.data != “”) {
local output = OutputPort(“data”, “string”);
imp.configure(“Kamstrup”, [], [output]);
server.log(“Sending data…”);
local responseCode = output.set(nv.data);
if(responseCode != 0) {
if(responseCode == SEND_ERROR_NOT_CONNECTED) {
server.log(“Send error not connected”);
}
if(responseCode == SEND_ERROR_TIMEOUT) {
server.log(“Send error timeout”);
}
if(responseCode == SEND_ERROR_DISCONNECTED) {
server.log(“The connection was disconnected before all data was sent to the server.”);
}
}
server.log("Data sent… ");
} else {
server.log(“Nothing to send, first boot?”);
}

nv.data = "";
server.expectonlinein(3600);
//server.expectonlinein(120);

}

function log() {
if (!(“nv” in getroottable())) {
nv <- { data = “” };
hourly();
}
local min = (t/60) % 60;
readEverything();
if (min == 59) {
hourly();
}
imp.onidle(function() { imp.deepsleepfor(60 - (time() % 60)); });

}

log();`

And heres the output while it was running this night:

7/4/2013 1:59:13 AM: Power state: asleep=>online
7/4/2013 1:59:13 AM: Device booting
7/4/2013 1:59:14 AM: Device configured to be "Kamstrup"
7/4/2013 1:59:14 AM: Sending data…
7/4/2013 2:59:14 AM: Device booting
7/4/2013 2:59:14 AM: Device configured to be "Kamstrup"
7/4/2013 2:59:14 AM: Sending data…
7/4/2013 3:59:19 AM: Device booting
7/4/2013 3:59:19 AM: Device configured to be "Kamstrup"
7/4/2013 3:59:19 AM: Sending data…
7/4/2013 4:59:13 AM: Device booting
7/4/2013 4:59:14 AM: Device configured to be "Kamstrup"
7/4/2013 4:59:14 AM: Sending data…
7/4/2013 4:59:34 AM: Power state: online=>offline
7/4/2013 5:59:14 AM: Power state: offline=>online
7/4/2013 5:59:14 AM: Device booting
7/4/2013 5:59:14 AM: Device configured to be "Kamstrup"
7/4/2013 5:59:14 AM: Sending data…
7/4/2013 5:59:14 AM: Data sent…
7/4/2013 5:59:14 AM: Power state: online=>asleep
7/4/2013 6:59:14 AM: Power state: asleep=>online
7/4/2013 6:59:14 AM: Device booting
7/4/2013 6:59:14 AM: Device configured to be "Kamstrup"
7/4/2013 6:59:14 AM: Sending data…
7/4/2013 7:59:14 AM: Device booting
7/4/2013 7:59:14 AM: Device configured to be "Kamstrup"
7/4/2013 7:59:14 AM: Sending data…
7/4/2013 8:59:21 AM: Device booting
7/4/2013 8:59:46 AM: Power state: online=>offline
7/4/2013 9:59:13 AM: Power state: offline=>online
7/4/2013 9:59:13 AM: Device booting
7/4/2013 9:59:13 AM: Device configured to be "Kamstrup"
7/4/2013 9:59:13 AM: Sending data…

It did send data once (where the log says data sent :slight_smile:

Yep, this is a known bug in release 25 - the buffer is not getting flushed before the disconnect.

Try adding server.flush(5) before you call expectonlinein

That seemed to do the trick - 24 hours without any dropout :slight_smile:

Thanks