OneWireError exception

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
spoz
Posts: 2
Joined: Sat Aug 15, 2020 9:20 am

OneWireError exception

Post by spoz » Sat Aug 15, 2020 9:26 am

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?

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: OneWireError exception

Post by kevinkk525 » Sat Aug 15, 2020 12:54 pm

you have to catch "onewire.OneWireError" if you import onewire at the top of the module.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

spoz
Posts: 2
Joined: Sat Aug 15, 2020 9:20 am

Re: OneWireError exception

Post by spoz » Sat Aug 15, 2020 1:32 pm

D'oh. Thanks so much for the reply.

Post Reply