Hello, I’m trying to make my own custom module to turn a relay on to activate a beacon light. I followed the instructions on the rsudp documentation, declared it in the client.py and the settings file, but it still wont show on the consumers when an event is detected. I was wondering if someone has made a custom module before or can point to where my mistake is on the code.
Module:
import sys
from rsudp.raspberryshake import ConsumerThread
from rsudp import printM
import RPi.GPIO as GPIO
import time
class MyModule(ConsumerThread):
def __init__(self, q):
super().__init__()
self.sender = 'MyModule'
self.alive = True
self.queue = q
# ... lots of other stuff to initialize your module
printM(self.thing1, sender=self.sender)
def getq(self):
'''
Reads data from the queue and returns the queue object.
Since this function returns something, it has return
strings (*rtype* stands for return type) so that the
user reading the documentation knows what they'll get
back if they call it.
:rtype: bytes
:return: The queue object.
'''
d = self.queue.get()
self.queue.task_done()
return d
def run(self):
printM('Starting.', sender=self.sender)
# some stuff to execute here at runtime before looping
GPIO.setmode(GPIO.BCM)
pin_rele = 22
GPIO.setup(pin_rele, GPIO.OUT)
while self.alive:
# main loop, do something until self.alive == False
d = self.queue.get()
self.queue.task_done()
if 'TERM' in str(d):
self.alive = False
printM('Exiting.', self.sender)
sys.exit()
elif 'ALARM' in str(d):
printM('Got ALARM message...', sender=self.sender)
# Se enciende la alarma
time.sleep(1)
GPIO.output(pin_rele, GPIO.HIGH)
# Se apaga la alarma
time.sleep(5)
GPIO.output(pin_rele, GPIO.LOW)
GPIO.cleanup()
self.alive = False
and in the client:
if settings['mymodule']['enabled']:
# put settings in namespace
q = mk_q()
mymod = MyModule(q=q)
mk_p(mymod)