Page 1 of 1

OneWireError exception

Posted: Sat Aug 15, 2020 9:26 am
by spoz
Hi all,
I'm using an ESP8266 with a DS18B20 temperature sensor and the OneWire library. I'm trying to handle an exception in the case where the sensor becomes disconnected during runtime.

Without any error handling if I disconnect the sensor and run:

Code: Select all

sensor.convert_temp()
then I see:

Code: Select all

>>> sensor.convert_temp()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "ds18x20.py", line 19, in convert_temp
  File "onewire.py", line 22, in reset
OneWireError:
If I try to catch the exception, my code looks like:

Code: Select all

try:
	sensor.convert_temp()
except OneWireError:
	print("Error")	
Then I get:

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
NameError: name 'OneWireError' isn't defined
Looking in the onewire library, the OneWireError exception class is just a "pass". Is this the problem? What is the correct way to handle this error?

Re: OneWireError exception

Posted: Sat Aug 15, 2020 12:54 pm
by kevinkk525
you have to catch "onewire.OneWireError" if you import onewire at the top of the module.

Re: OneWireError exception

Posted: Sat Aug 15, 2020 1:32 pm
by spoz
D'oh. Thanks so much for the reply.