Rob
Rob

Reputation: 11788

Why does bme280.startreadout() only trigger once?

I'm using an ESP-12F (ESP8266) module with the NodeMCU-firmware that has the BME280 module enabled. I have tested the sensor by manually querying the temperature and humidity, everything is fine.

Now, I wanted to use the bme280.startreadout(...) function in order to periodically send the values to my server (or simply print them out to the serial terminal in ESPlorer for now). The following code does not throw any errors, but the callback function only runs once - can anybody tell me why that is?

bme280.init(7, 6, nil, nil, nil, 0)
bme280.startreadout(2000, function ()
    T = bme280.temp()
    print(string.format("T=%d.%02d", T/100, T%100))
end)

When I send this script to the module and run it, the correct temperature gets written out once after 2 seconds, that's it.

Here are some details about the firmware:

NodeMCU custom build by frightanic.com
    branch: dev
    commit: 79013ae79a85798cba470ac1168e75c755f58f42
    SSL: true
    modules: adc,adxl345,am2320,apa102,bme280,crypto,dht,file,gpio,hmc5883l,http,i2c,l3g4200d,mqtt,net,node,ow,pwm,spi,tmr,tsl2561,uart,websocket,wifi
 build  built on: 2016-12-05 17:30
 powered by Lua 5.1.4 on SDK 1.5.4.1(39cb9a32)

Update: Haven't thought of that before: is startreadout meant to trigger the callback function only once? Or to put it in JavaScript terms: does it work like setTimeout as opposed to setInterval?

Upvotes: 0

Views: 234

Answers (1)

Marcel Stör
Marcel Stör

Reputation: 23535

There are a few issues with that module but none that affects you AFAICT.

The docs are IMO quite clear that your callback is only fired once. The first parameter is called delay rather than "interval" or the like. So, you need a timer to read sensor values periodically.

Upvotes: 1

Related Questions