Imp.rssi() reported as 0

I have a situation that’s a bit perplexing. I have an device that boots up, reports temperature, humidity and battery voltage and then goes into deep for about a minute. It then wakes up and does the same–everything works just fine.

I thought I’d like to have the RSSI reported to confirm how well the device is connected. Here’s the interesting part…it reports just fine the first time through, but then will report RSSI as 0 (zero) via server.log on all follow wake-ups. I haven’t checked to see what is being sent to the agent, which I’m assuming is the same.

Perhaps I’m simply tired and can’t see the error in my logic, but here’s the relevant code:
`
drssi <-"";

startup();

chkBat();
chkSensor();
drssi = imp.rssi();
//data <- {“temperature” : format("%0.1f", temperature), “humidity” : format("%0.1f", humidity), “batt” : format("%0.2f", vbat)};
data <- {“temperature” : format("%0.1f", temperature), “humidity” : format("%0.1f", humidity), “batt” : format("%0.2f", vbat),“rssi” : format("%i",drssi)};
server.log(“rssi: “+ format(”%i”,drssi));
agent.send(“gs”, data);

imp.setpowersave(true);

imp.onidle(function() {
server.expectonlinein(updatePeriod + 1);
imp.deepsleepfor(updatePeriod);
});`

This happens because you are not connected when you call imp.rssi.

In order to save power, the imp doesn’t turn on WiFi until it’s required. You could either manually call server.connect() or make any other call that requires a connection to the server (like server.log).

`server.log(“device started”); // force device to connect so you can read rssi
drssi <-"";

startup();

chkBat();
chkSensor();
drssi = imp.rssi();
//data <- {“temperature” : format("%0.1f", temperature), “humidity” : format("%0.1f", humidity), “batt” : format("%0.2f", vbat)};
data <- {“temperature” : format("%0.1f", temperature), “humidity” : format("%0.1f", humidity), “batt” : format("%0.2f", vbat),“rssi” : format("%i",drssi)};
agent.send(“gs”, data);

imp.setpowersave(true);

imp.onidle(function() {
server.expectonlinein(updatePeriod + 1);
imp.deepsleepfor(updatePeriod);
});`