Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPIO Digital Interrupts not working #85

Closed
CrazyIvan359 opened this issue Dec 17, 2020 · 1 comment · Fixed by #87
Closed

GPIO Digital Interrupts not working #85

CrazyIvan359 opened this issue Dec 17, 2020 · 1 comment · Fixed by #87
Labels
bug Something isn't working GPIO GPIO Module
Projects

Comments

@CrazyIvan359
Copy link
Owner

Describe the bug

Interrupts for digital pins are not working, debounce time seems to never end.

Environment

  • MQTTany version: v0.12.0
  • Platform: RPi 2B and 3B

Configuration

gpio:
  testinput27:
    pin: 27
    digital:
      interrupt: both

Diagnosed and solved in #84, problem is incorrect operator on line 239 of mqttany/gpio/pins/digital.py should be / not *. Multiplication results in default 50,000 second debounce time.

self._debounce_us = pin._interrupt_debounce * 1000.0

Also should not be casting to int on line 295 as the value for epoch microseconds will not fit in a 32bit integer.

return edge == periphery_PinEdge[PinEdge.RISING], int(ns / 1000.0) / 1000000.0

@CrazyIvan359 CrazyIvan359 added bug Something isn't working GPIO GPIO Module labels Dec 17, 2020
@CrazyIvan359 CrazyIvan359 pinned this issue Dec 17, 2020
@CrazyIvan359 CrazyIvan359 unpinned this issue Dec 20, 2020
@CrazyIvan359 CrazyIvan359 pinned this issue Dec 20, 2020
@CrazyIvan359 CrazyIvan359 added this to Bugs in v1.0.0 Dec 24, 2020
@CrazyIvan359 CrazyIvan359 moved this from Bugs to Done in v1.0.0 Dec 24, 2020
@CrazyIvan359 CrazyIvan359 unpinned this issue Oct 11, 2021
@jujoparo
Copy link

Describe the bug

Interrupts for digital pins are not working, only polling. The debug messages show an exception.

Environment

MQTTany version: v0.14.3
Platform: RPi 3B+
Linux version 5.10.63-v7+ 

Configuration

gpio:

  mode: 'SOC'
  debounce: 50

  sensor-voltaje:
    pin: 10
    pin mode: input
    resistor: pullup
    digital:
      interrupt: both
      invert: false

  sensor-puerta-entrada:
    pin: 9
    pin mode: 'input'
    resistor: 'pullup'
    digital:
      interrupt: 'both'
      invert: false

DEBUG


openhabian@Dagobah:/opt/mqttany $ python3 mqttany/mqttany.py -v
2022-01-25 18:51:01,633 [INFO ] [core    ] [core                    ] MQTTany 0.14.3 starting
2022-01-25 18:51:01,970 [INFO ] [core    ] [core.gpio               ] Detected board: RASPBERRY_PI_3B_PLUS
2022-01-25 18:51:01,973 [DEBUG] [core    ] [core.gpio               ] Detected GPIO character device
2022-01-25 18:51:01,974 [DEBUG] [core    ] [core.gpio               ] Detected sysfs GPIO interface
2022-01-25 18:51:01,976 [DEBUG] [core    ] [config                  ] Loading config file
2022-01-25 18:51:02,237 [DEBUG] [core    ] [core                    ] Loading module 'mqtt'
2022-01-25 18:51:02,590 [DEBUG] [core    ] [core                    ] Module 'mqtt' is a communication module
2022-01-25 18:51:02,593 [DEBUG] [core    ] [mqtt                    ] Parsing config
2022-01-25 18:51:02,595 [DEBUG] [core    ] [mqtt                    ] Config loaded successfully
2022-01-25 18:51:02,597 [DEBUG] [core    ] [core                    ] Module 'mqtt' loaded successfully
2022-01-25 18:51:02,599 [DEBUG] [core    ] [bus                     ] Module 'mqtt' added as a receiver
2022-01-25 18:51:02,605 [DEBUG] [core    ] [bus                     ] Module 'mqtt' added as a transmitter
2022-01-25 18:51:02,606 [DEBUG] [core    ] [core                    ] Loading module 'gpio'
2022-01-25 18:51:02,744 [DEBUG] [core    ] [core                    ] Module 'gpio' is an interface module
2022-01-25 18:51:02,751 [DEBUG] [core    ] [gpio                    ] Parsing config
2022-01-25 18:51:02,759 [DEBUG] [core    ] [gpio                    ] Config loaded
2022-01-25 18:51:02,792 [DEBUG] [core    ] [core.gpio.board         ] 'gpio.pin.digital' acquired lock on GPIO10 (GPIO10)
2022-01-25 18:51:02,794 [DEBUG] [core    ] [gpio.digital            ] Configured 'sensor-voltaje' on GPIO10 with options: {'ID': 'sensor-voltaje', 'pin mode': 'INPUT', 'interrupt': 'BOTH', 'resistor': 'PULL_UP', 'invert': False, 'initial state': 'OFF'}
2022-01-25 18:51:02,801 [DEBUG] [core    ] [core.gpio.board         ] 'gpio.pin.digital' acquired lock on GPIO09 (GPIO09)
2022-01-25 18:51:02,804 [DEBUG] [core    ] [gpio.digital            ] Configured 'sensor-puerta-entrada' on GPIO09 with options: {'ID': 'sensor-puerta-entrada', 'pin mode': 'INPUT', 'interrupt': 'BOTH', 'resistor': 'PULL_UP', 'invert': False, 'initial state': 'OFF'}
2022-01-25 18:51:02,811 [DEBUG] [core    ] [core.gpio.board         ] 'gpio.pin.digital' acquired lock on GPIO18 (GPIO18)
2022-01-25 18:51:02,813 [DEBUG] [core    ] [gpio.digital            ] Configured 'telerruptor-luces' on GPIO18 with options: {'ID': 'telerruptor-luces', 'pin mode': 'OUTPUT', 'interrupt': 'NONE', 'resistor': 'NONE', 'invert': True, 'initial state': 'ON'}
2022-01-25 18:51:02,820 [DEBUG] [core    ] [core.gpio.board         ] 'gpio.pin.digital' acquired lock on GPIO23 (GPIO23)
2022-01-25 18:51:02,822 [DEBUG] [core    ] [gpio.digital            ] Configured 'toma-enchufe-1' on GPIO23 with options: {'ID': 'toma-enchufe-1', 'pin mode': 'OUTPUT', 'interrupt': 'NONE', 'resistor': 'NONE', 'invert': True, 'initial state': 'ON'}
2022-01-25 18:51:02,829 [DEBUG] [core    ] [core.gpio.board         ] 'gpio.pin.digital' acquired lock on GPIO24 (GPIO24)
2022-01-25 18:51:02,831 [DEBUG] [core    ] [gpio.digital            ] Configured 'toma-enchufe-2' on GPIO24 with options: {'ID': 'toma-enchufe-2', 'pin mode': 'OUTPUT', 'interrupt': 'NONE', 'resistor': 'NONE', 'invert': True, 'initial state': 'OFF'}
2022-01-25 18:51:02,838 [DEBUG] [core    ] [core.gpio.board         ] 'gpio.pin.digital' acquired lock on GPIO25 (GPIO25)
2022-01-25 18:51:02,840 [DEBUG] [core    ] [gpio.digital            ] Configured 'toma-enchufe-3' on GPIO25 with options: {'ID': 'toma-enchufe-3', 'pin mode': 'OUTPUT', 'interrupt': 'NONE', 'resistor': 'NONE', 'invert': True, 'initial state': 'ON'}
2022-01-25 18:51:02,847 [DEBUG] [core    ] [core.gpio.board         ] 'gpio.pin.digital' acquired lock on GPIO16 (GPIO16)
2022-01-25 18:51:02,849 [DEBUG] [core    ] [gpio.digital            ] Configured 'telefonillo-apertura' on GPIO16 with options: {'ID': 'telefonillo-apertura', 'pin mode': 'OUTPUT', 'interrupt': 'NONE', 'resistor': 'NONE', 'invert': True, 'initial state': 'ON'}
2022-01-25 18:51:02,851 [DEBUG] [core    ] [core                    ] Module 'gpio' loaded successfully
2022-01-25 18:51:02,853 [DEBUG] [core    ] [bus                     ] Module 'gpio' added as a publisher
2022-01-25 18:51:02,857 [DEBUG] [core    ] [bus                     ] Module 'gpio' added as a subscriber
2022-01-25 18:51:02,872 [INFO ] [core    ] [core                    ] Module 'mqtt' started successfully
2022-01-25 18:51:02,883 [DEBUG] [mqtt    ] [mqtt                    ] Creating MQTT client
2022-01-25 18:51:02,884 [INFO ] [core    ] [core                    ] Module 'gpio' started successfully
2022-01-25 18:51:02,891 [DEBUG] [mqtt    ] [mqtt                    ] Attaching callbacks
2022-01-25 18:51:02,891 [DEBUG] [core    ] [bus                     ] Starting Message Bus Receive thread
2022-01-25 18:51:02,895 [DEBUG] [mqtt    ] [mqtt                    ] Queuing connect event
2022-01-25 18:51:02,896 [DEBUG] [core    ] [bus                     ] Starting Message Bus Transmit thread
2022-01-25 18:51:02,897 [DEBUG] [mqtt    ] [mqtt                    ] Starting MQTT client thread
2022-01-25 18:51:02,897 [DEBUG] [gpio    ] [gpio                    ] Setting up hardware
2022-01-25 18:51:02,901 [INFO ] [gpio    ] [gpio.digital            ] Setting up 'sensor-voltaje' on GPIO10 as INPUT
2022-01-25 18:51:02,905 [DEBUG] [gpio    ] [core.gpio.pin.digital   ] Setting up pin GPIO10 using chardev
2022-01-25 18:51:02,920 [INFO ] [gpio    ] [gpio.digital            ] Setting up 'sensor-puerta-entrada' on GPIO09 as INPUT
2022-01-25 18:51:02,925 [DEBUG] [gpio    ] [core.gpio.pin.digital   ] Setting up pin GPIO09 using chardev
2022-01-25 18:51:02,935 [INFO ] [gpio    ] [gpio.digital            ] Setting up 'telerruptor-luces' on GPIO18 as OUTPUT
2022-01-25 18:51:02,939 [DEBUG] [gpio    ] [core.gpio.pin.digital   ] Setting up pin GPIO18 using chardev
2022-01-25 18:51:02,947 [INFO ] [mqtt    ] [mqtt                    ] Connected to broker 'localhost:1883'
2022-01-25 18:51:02,949 [DEBUG] [mqtt    ] [mqtt                    ] Resuming previous session
2022-01-25 18:51:02,952 [DEBUG] [mqtt    ] [mqtt                    ] Heartbeat
2022-01-25 18:51:02,945 [DEBUG] [gpio    ] [gpio.digital            ] Set 'telerruptor-luces' on GPIO18 to OFF logic HIGH
2022-01-25 18:51:02,962 [INFO ] [gpio    ] [gpio.digital            ] Setting up 'toma-enchufe-1' on GPIO23 as OUTPUT
2022-01-25 18:51:03,000 [DEBUG] [gpio    ] [core.gpio.pin.digital   ] Setting up pin GPIO23 using chardev
2022-01-25 18:51:03,003 [DEBUG] [gpio    ] [gpio.digital            ] Set 'toma-enchufe-1' on GPIO23 to OFF logic HIGH
2022-01-25 18:51:03,006 [INFO ] [gpio    ] [gpio.digital            ] Setting up 'toma-enchufe-2' on GPIO24 as OUTPUT
2022-01-25 18:51:03,009 [DEBUG] [gpio    ] [core.gpio.pin.digital   ] Setting up pin GPIO24 using chardev
2022-01-25 18:51:03,016 [DEBUG] [gpio    ] [gpio.digital            ] Set 'toma-enchufe-2' on GPIO24 to ON logic LOW
2022-01-25 18:51:03,021 [INFO ] [gpio    ] [gpio.digital            ] Setting up 'toma-enchufe-3' on GPIO25 as OUTPUT
2022-01-25 18:51:03,026 [DEBUG] [gpio    ] [core.gpio.pin.digital   ] Setting up pin GPIO25 using chardev
2022-01-25 18:51:03,088 [DEBUG] [gpio    ] [gpio.digital            ] Set 'toma-enchufe-3' on GPIO25 to OFF logic HIGH
2022-01-25 18:51:03,093 [INFO ] [gpio    ] [gpio.digital            ] Setting up 'telefonillo-apertura' on GPIO16 as OUTPUT
2022-01-25 18:51:03,095 [DEBUG] [gpio    ] [core.gpio.pin.digital   ] Setting up pin GPIO16 using chardev
2022-01-25 18:51:03,097 [DEBUG] [gpio    ] [gpio.digital            ] Set 'telefonillo-apertura' on GPIO16 to OFF logic HIGH
2022-01-25 18:51:03,103 [DEBUG] [gpio    ] [gpio                    ] Starting polling timer with interval of 60s
2022-01-25 18:51:03,117 [DEBUG] [gpio    ] [gpio                    ] Polling all pins
2022-01-25 18:51:03,129 [DEBUG] [gpio    ] [gpio.digital            ] Read state OFF logic LOW from 'sensor-voltaje' on GPIO10
2022-01-25 18:51:03,137 [DEBUG] [gpio    ] [gpio.digital            ] Read state OFF logic LOW from 'sensor-puerta-entrada' on GPIO09
2022-01-25 18:51:03,144 [DEBUG] [gpio    ] [gpio.digital            ] Read state OFF logic HIGH from 'telerruptor-luces' on GPIO18
2022-01-25 18:51:03,152 [DEBUG] [gpio    ] [gpio.digital            ] Read state OFF logic HIGH from 'toma-enchufe-1' on GPIO23
2022-01-25 18:51:03,174 [DEBUG] [gpio    ] [gpio.digital            ] Read state ON logic LOW from 'toma-enchufe-2' on GPIO24
2022-01-25 18:51:03,210 [DEBUG] [gpio    ] [gpio.digital            ] Read state OFF logic HIGH from 'toma-enchufe-3' on GPIO25
2022-01-25 18:51:03,219 [DEBUG] [gpio    ] [gpio.digital            ] Read state OFF logic HIGH from 'telefonillo-apertura' on GPIO16
Exception in thread Thread-5:
Traceback (most recent call last):
  File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.7/threading.py", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "/opt/mqttany/mqttany/gpio/pins/digital.py", line 281, in _poll
    self._debounce_thread.join()
AttributeError: 'NoneType' object has no attribute 'join'

2022-01-25 18:52:03,113 [DEBUG] [gpio    ] [gpio                    ] Polling timer fired
2022-01-25 18:52:03,118 [DEBUG] [gpio    ] [gpio                    ] Polling all pins
2022-01-25 18:52:03,121 [DEBUG] [gpio    ] [gpio.digital            ] Read state ON logic HIGH from 'sensor-voltaje' on GPIO10
2022-01-25 18:52:03,123 [DEBUG] [gpio    ] [gpio.digital            ] Read state ON logic HIGH from 'sensor-puerta-entrada' on GPIO09
2022-01-25 18:52:03,128 [DEBUG] [gpio    ] [gpio.digital            ] Read state OFF logic HIGH from 'telerruptor-luces' on GPIO18
2022-01-25 18:52:03,132 [DEBUG] [gpio    ] [gpio.digital            ] Read state OFF logic HIGH from 'toma-enchufe-1' on GPIO23
2022-01-25 18:52:03,137 [DEBUG] [gpio    ] [gpio.digital            ] Read state ON logic LOW from 'toma-enchufe-2' on GPIO24
2022-01-25 18:52:03,140 [DEBUG] [gpio    ] [gpio.digital            ] Read state OFF logic HIGH from 'toma-enchufe-3' on GPIO25
2022-01-25 18:52:03,157 [DEBUG] [gpio    ] [gpio.digital            ] Read state OFF logic HIGH from 'telefonillo-apertura' on GPIO16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working GPIO GPIO Module
Projects
v1.0.0
  
Done
Development

Successfully merging a pull request may close this issue.

2 participants