2

I am using PIGPIO library to read temperature and humidity from a DHT22 sensor. This is the script I am using.

import os
import sys
import time
import pigpio
pi = pigpio.pi()
import DHT22
s = DHT22.sensor(pi,4,17)
s.trigger()
time.sleep(0.2)
print("{} {} {:3.2f} {} {} {} {}".format(
    s.humidity(), s.temperature(), s.staleness(),
    s.bad_checksum(), s.short_message(), s.missing_message(),
    s.sensor_resets()))
s.cancel()
pi.stop()

the script runs well and return the temperature and humidity as expected. However, in my terminal I got the following error:

Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "/usr/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "/home/pi/share/dht_py/pigpio_dht22/DHT22.py", line 238, in cancel
    self.pi.set_watchdog(self.gpio, 0)
  File "/usr/local/lib/python2.7/dist-packages/pigpio.py", line 1764, in set_watchdog
    self.sl, _PI_CMD_WDOG, user_gpio, int(wdog_timeout)))
  File "/usr/local/lib/python2.7/dist-packages/pigpio.py", line 983, in _pigpio_command
    sl.s.send(struct.pack('IIII', cmd, p1, p2, 0))
AttributeError: 'NoneType' object has no attribute 'send'
Error in sys.exitfunc:
Traceback (most recent call last):
  File "/usr/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "/home/pi/share/dht_py/pigpio_dht22/DHT22.py", line 238, in cancel
    self.pi.set_watchdog(self.gpio, 0)
  File "/usr/local/lib/python2.7/dist-packages/pigpio.py", line 1764, in set_watchdog
    self.sl, _PI_CMD_WDOG, user_gpio, int(wdog_timeout)))
  File "/usr/local/lib/python2.7/dist-packages/pigpio.py", line 983, in _pigpio_command
    sl.s.send(struct.pack('IIII', cmd, p1, p2, 0))
AttributeError: 'NoneType' object has no attribute 'send'

What is the cause of this error and how to avoid that? Thank you in advance.

1

Odd. It looks like the connection to the Pi has been terminated by the pi.stop() before s.cancel() has completed all it needed to do in the background.

I'd try adding a time.sleep(0.2) after the s.cancel() to see if that gets around the problem.

  • thank you for your answer. I added the time.sleep(0.2) but unfortunately I still got the error. I also try to execute the script line by line in the terminal instead of executing a script file. The error appeared after I execute the exit() command after pi.stop(). – Leonard AB Dec 28 '17 at 5:29
  • I think this post is relevant github.com/joan2937/pigpio/issues/16 . My question now is, should I remove the atexit import and atexit call on the DHT22.py? is that safe? – Leonard AB Dec 28 '17 at 5:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.