Closed renandw closed 3 years ago
Well, as I usually say, a lot of problems come from bad formatting. First format your code nicely, then it will be easier to spot the problem. First, in your sensor_task() you have two infinite loops nested inside each other, so that your success variable never gets updated. Speaking of which, you assign result of bh1750_read() to a boolean variable which is incorrect, since the function returns lux value (as uint16_t).
When you check to see if "fault" value needs to be updated, you should check fault.value.uint8_value
, not fault.value.int_value
, since you might be reading some garbage data, because uint8_value takes only one byte, while int_value - 4, and those 3 extra bytes might not be initialized.
For motion sensor I recommend using my toggle library (which is part of esp-button), it will trigger you callback when pin state changes (so you do not have to deal with interrupts and remembering old value). Though it does not use interrupts, but instead uses timers. Also, it kind of bad idea to do prints inside interrupt callback, since print is blocking and it might take it waaay too long to output stuff to console and you'll miss a bunch of subsequent pin changes.
Also, you're using High Res Mode 2 on BH1750 which reports halves of lux units. I couldn't find it anywhere in datasheet, but since it returns an unsigned integer for lux values, you might need to divide it by either 2 or 10 to get fractions.
wow. I worked in the code during the day. Really thank you for the inputs. I've changed the motion sensor like you oriented. The BH1750 was a bit difficult but you really showed me the way. Thanks a lot
Hello. In the following lines, there is a code for a light sensor that use the BH170 hardware, a temperature sensor using a DHT22 hardware and a motion sensor. I can flash to the ESP8266 Wemos D1 mini, pair it in Home.app, and get the info of the sensors. But I am facing an issue. Right after the pairing process is complete, the light sensor shows in Home.app and in logs: ""Couldn't read data from sensor”. When I press the reset button in the board and it reconnect to wifi and to home.app, the light sensor works like a charm. I really can't see what I am missing :/ Any help? Thanks in advance