Missing readings - using server.sleepfor

Hi I’m sure it’s me but I’ve got 2 imps measuring temp & temp + humidity both deep sleep for 5mins wake do an I2C read. Now and then I get a missed reading it’s as if the imp has slept before completing it’s reads and output port sets.This is happening on both imps with different code but is apparent in server logs and my cloud DB. Is it the wee sleep used I2C write-delay-read?

Also get diffrent sleep state log entries
Power state: online=>offline
Power state: online=>asleep (very occasionally preceded by sleeping until 1353860557000)

Sunday, November 25, 2012 15:51:58: Power state: offline=>online
Sunday, November 25, 2012 15:51:58: Device booting
Sunday, November 25, 2012 15:51:58: Device configured to be "Temp/Humidity v1.1"
Sunday, November 25, 2012 15:51:58: temp 16.4C humidity 72.9%
Sunday, November 25, 2012 15:51:58: Power state: online=>offline
// no reading
Sunday, November 25, 2012 15:57:04: Power state: offline=>online
Sunday, November 25, 2012 15:57:04: Device booting
Sunday, November 25, 2012 15:57:04: Device configured to be "Temp/Humidity v1.1"
Sunday, November 25, 2012 15:57:04: Power state: online=>offline

`// Temperature and Humidity Monitor using Honeywell HIH6130 sensor
hardware.configure(I2C_12);
local i2c = hardware.i2c12;

// Output to web service
local _wsOut = OutputPort(“wsOut”,“string”);
imp.configure(“Temp/Humidity v1.1”, [],[_wsOut]);

function getDateTime(){
local _iTime = date(time()).year + “-” + (date(time()).month+1) + “-” + date(time()).day + “T” + (date(time()).hour) + “:” + date(time()).min+ “:” + date(time()).sec;
return _iTime;
}

function getsample() {

// Start conversion
i2c.write(0x4e, “”);

// Wait at least 36ms
imp.sleep(0.05);

// Read out temperature and humidity, zero length subaddress means the write
// subaddr phase will be totally skipped and we’ll just do the read
local th = i2c.read(0x4e, “”, 4);

// Form temp and humidity
local temperature = ((((th[2] << 6 ) | (th[3] >> 2)) * 165) / 16383.0) - 40;
local humidity = ((((th[0] & 0x3F) << 8 ) | (th[1] )) / 163.83 );

// log and print
server.log(format(“temp %.1fC humidity %.1f%%”,temperature, humidity));

local tempOut=format("%.1f",temperature);
local _httpOut=“l|023|”+tempOut+"|"+getDateTime()+"|studyTemp2|C";
_wsOut.set(_httpOut);

local humOut=format("%.1f",humidity);
local _httpOut=“l|024|”+humOut+"|"+getDateTime()+"|studyHumidity|%";
_wsOut.set(_httpOut);
}

// Get a sample, then sleep
getsample();
imp.onidle(function() { server.sleepfor(300); });
`
Thanks
Lawrence

In the current release, server.sleepfor puts the imp to sleep immediately, even if there’s still unacked data hanging around in the TCP send buffer (which there might be in case of transient wifi congestion, for instance). This is a bug and is FITNR, but a partial workaround for now would be to replace imp.onidle(f) with imp.wakeup(1,f) to give TCP an extra second to get its packet out. Though of course that’s another second with the power on, plus there’s no firm guarantee that a second is long enough either.

Peter

We have customers using the “extra delay after the .set but before sleepfor” for whom this is a workable workaround… but as Peter says - fixed in the next release :slight_smile:

Is the HIH6130 working for you? I’ve been trying to get the AM2315 from Adafruit working on ports 1 & 2, but without success. It always works fine on ports 8 & 9, but I’d like to be able to have more than one sensor and they have fixed addresses.

The HIH6130 is in the Nora reference design and works fine, but is pricey. Bosch has a new temp/pressure/humidity sensor that apparently has become available as samples. If things go will with it, hopefully it can go into a new revision of the Nora, and bring the price down significantly.

In any case, there is an HIH6130 class available on the EI GitHub page.

@MakeDeck, do you mean the Bosch BME280? Any word on how people are getting samples? If anyone knows how to get a sample, please do share!

Yes, I haven’t tried to get any yet, but I know EI has reached out to Bosch to try to get some. The website says that samples are available to key customers… I’m sure MakeDeck isn’t one of them. :slight_smile: There is no harm in asking, right?

exactly. no harm in asking. i sent a few emails to Bosch earlier today asking. figured it was worth a try.

Hi guys, did you get working the BME280? looking for some code if you may share. thanks

Any news about a working Code for the BME280? The only Code on GitHub is not final ported.