Avoid code crash and exit
Posted: Tue Dec 31, 2019 1:26 pm
i do have a code that measures temperature from two sensors : DHT22 and DS1820. Both work fine until something happens. Either it does not receive reading back or get's response in a wrong format and then code crashes and exists. I do then restart ESP32 via reset button and all works fine again until next crash.
I would like the code not to exit if the reading is not received or it is in wrong format. I just want to disregard it. I do readings pretty often, so missing one cycle is not a problem at all. Bigger problem is that the whole process is down that might have bad result. I am using it in small in house greenhouse with LED grow lights and have temperature control using PC fans. So if the code exits and LED lamps are on, there is a risk that temperature will go too high, something I need to avoid.
I use command "sensor.measure()" to read from DHT22 sensor. And I use following code for DS1820:
How can I tell code to disregard wrong readings?
Also, is there any way to write log into the file on ESP32? something that would tell me what line of the code it crashed, so that I can hopefully address it?
I would like the code not to exit if the reading is not received or it is in wrong format. I just want to disregard it. I do readings pretty often, so missing one cycle is not a problem at all. Bigger problem is that the whole process is down that might have bad result. I am using it in small in house greenhouse with LED grow lights and have temperature control using PC fans. So if the code exits and LED lamps are on, there is a risk that temperature will go too high, something I need to avoid.
I use command "sensor.measure()" to read from DHT22 sensor. And I use following code for DS1820:
Code: Select all
roms = ds.scan()
print('found devices:', roms)
addr = roms.pop()
ds.convert_temp()
temp = ds.read_temp(addr)
Also, is there any way to write log into the file on ESP32? something that would tell me what line of the code it crashed, so that I can hopefully address it?