My goal is: to get the temperature data from bme280 sensor.
My actions are: I’ve already added the bme280 library in my mos.yml file
“- origin: https://github.com/mongoose-os-libs/bme280” and load the “load(‘api_bme280.js’);” I’ve also done mos build and flash. Here’s my actual code:
BME280Data is a structure which contains the result of BME280.readAll(data) where data is a BME280Data object.
If you want to read the temperature
load('api_timer.js');
load('api_bme280.js');
// https://github.com/mongoose-os-libs/bme280/blob/4f17b96aa8153c5eb07583dcd0ee669fc4234134/mjs_fs/api_bme280.js#L59-L66
let myBME = BME280.createI2C(0x76); // Have to check the datasheeet of your sensor. Might be 0x76 or 0x77
Timer.set(10000, Timer.REPEAT, function () {
print('Temperature: ', myBME.readTemp()); // https://github.com/mongoose-os-libs/bme280/blob/4f17b96aa8153c5eb07583dcd0ee669fc4234134/mjs_fs/api_bme280.js#L93-L98
}, null);
To read temperature, humidity and pressure:
load('api_timer.js');
load('api_bme280.js');
// https://github.com/mongoose-os-libs/bme280/blob/4f17b96aa8153c5eb07583dcd0ee669fc4234134/mjs_fs/api_bme280.js#L59-L66
let myBME = BME280.createI2C(0x76);
let myBMEData=BME280Data.create(); // create the data object
Timer.set(10000 , Timer.REPEAT, function () {
myBME.readAll(myBMEData); // https://github.com/mongoose-os-libs/bme280/blob/4f17b96aa8153c5eb07583dcd0ee669fc4234134/mjs_fs/api_bme280.js#L86-L91
print('Temperature:', myBMEData.temp(), 'Humidity:', myBMEData.humid(), 'Pressure:', myBMEData.press());
}, null);
I try all the code that you provided, the first one is showing Temperature: -128 and the second code show like this:
[Nov 9 18:15:25.979] mgos_bme280.c:184 BMP/BME280 device not found - -2
[Nov 9 18:15:26.014] mgos_mongoose.c:66 New heap free LWM: 26528
[Nov 9 18:15:26.018] mgos_ota_core.c:1329 UID: 0307171199375ef5, license: none
[Nov 9 18:15:36.033] Temperature: 0 Humidity: 0 Pressure: 0
[Nov 9 18:15:46.032] Temperature: 0 Humidity: 0 Pressure: 0