@gerritv Thank you for pointing the problem. I was updating my code, while library was updated and found that i had funtion, that does not exists in library - i've added it in local copy in library, then it updated and my local patch was gone.
I've investigated previosly mentioned PR - and must admit that later they removed that re-initialisation when reading.
I will try a PR to slightly improve that behaviour, but looks like library is becoming abandoned.
Now look it should work next way: after previous measurement done you must run lightSensor.configure(ONE_TIME_) so it starts measuring - this is shown in their example BH1750onetime.ino. Then we have to wait, but measurementReady() relies on _delay_ms, which (as i remember) won't tick during sleep so you can't sleep. We can sleep but we can't get exact measurement time for current settings. Soto save battery we sleep max time - which, according to library is 180ms. Then we get reading. On next cycle - repeat.
As i understand maximum battery saving code will look like:
void setup() {
Wire.begin(); // Initialize the I2C bus (BH1750 library doesn't do this automatically)
lux_init_status = lightMeter.begin(BH1750::ONE_TIME_LOW_RES_MODE); //init ONE_TIME - at same time it will start measuring, but we will ignore this and double-call start measuring
if (lux_init_status == false) {
send(deb_msg.set("ErrorInitLux")); //notify us about failure
}
}
void loop() {
if (lux_init_status) { //making it fail-safe - if BH1750 brokes then other sensors will still work
lightMeter.configure(BH1750::ONE_TIME_LOW_RES_MODE); //this will start measuring, after it sensor will go into power-down mode
//note, that configure has 10ms sleep built-in
sleep(180); //this is guarantee time in this library with any config. We can't get that externally as for v1.3.0
long lux = lightMeter.readLightLevel(); //actually get results
}
sleep(SLEEP_TIME);//sleep between measurements
}
note that .configure() that is also called by .begin has built-in 10ms delay