If I pub from another session on the broker SS picks it up on the client and executes the script. I can modify the delay etc but setting it to False does not skip to the else: in rpiGPIOActuator.py from what I can see. everything thing else checks out.
Here is the output from mqttreporter when I send a publish
2016-11-26 21:58:31,560 INFO - Toggling pin 2 HIGH to LOW
2016-11-26 21:58:35,565 INFO - Toggling pin 2 LOW to HIGH
Here is my ini
[Actuator1]
Class: rpiGPIOActuator.rpiGPIOActuator
; The chosen connection must support a register(path, handler) method the actuators can call
; to receive specific incoming messages. See mqttConn.py for an example
; restConnection is not supported.
Connection: MQTT
Pin: 2
Topic: kit/barlight
; When true set the pin to ON for half a second then turn off, otherwise switch the pin from one state to the oth$
Toggle: False
Poll: 0
[Actuator2]
Class: rpiGPIOActuator.rpiGPIOActuator
; The chosen connection must support a register(path, handler) method the actuators can call
; to receive specific incoming messages. See mqttConn.py for an example
; restConnection is not supported.
Connection: MQTT
Pin: 3
Topic: kit/counterlight
; When true set the pin to ON for half a second then turn off, otherwise switch the pin from one state to the oth$
Toggle: False
Poll: 0
[Logging]
File: /var/log/mqttReporter.log
MaxSize: 67108864
NumFiles: 10
Syslog: NO
[Connection1]
Class: mqttConn.mqttConnection
Name: MQTT
User = user
Password = password
Host = 192.168.0.60
Port = 1883
Keepalive = 60
; Topic to listen on, when any message is received, the current state of all
; are published to their respective topics.
Topic = sensors/getUpdate
; The MQTT broker will publish the following message on the following topic
; when the client disconnects (cleanly or crashes)
LWT-Topic = status/sensor-reporters
LWT-Msg = mqttReporter is dead
; If TLS is yes the connection will be encrypted, the Certificate is expected to be in
; ./certs/ca.crt"
TLS = NO
The MQTT topic log:
Client mosqsub/2081-raspberryp received PUBLISH (d0, q0, r0, m0, 'kit/barlight', ... (2 bytes))
On
And the rpiGPIOActuator.py
import sys
import time
import RPi.GPIO as GPIO
class rpiGPIOActuator:
"""Represents an actuator connected to a GPIO pin"""
def __init__(self, connection, logger, params):
"""Sets the output and changes its state when it receives a command"""
self.logger = logger
self.pin = int(params("Pin"))
GPIO.setmode(GPIO.BCM) # uses BCM numbering, not Board numbering
GPIO.setup(self.pin, GPIO.OUT)
GPIO.output(self.pin, GPIO.HIGH)
self.destination = params("Topic")
self.connection = connection
self.toggle = bool(params("Toggle"))
self.logger.info('----------Configuring rpiGPIOActuator: pin {0} on destination {1} with toggle {2}'.form$
self.connection.register(self.destination, self.on_message)
def on_message(self, client, userdata, msg):
"""Process a message"""
self.logger.info('Received command on {0}: {1} Toggle = {2} PIN = {3}'.format(self.destination, msg.paylo$
if self.toggle == True:
self.logger.info('Toggling pin %s HIGH to LOW' % (self.pin))
GPIO.output(self.pin, GPIO.LOW)
time.sleep(4)
GPIO.output(self.pin, GPIO.HIGH)
self.logger.info('Toggling pin %s LOW to HIGH' % (self.pin))
else:
out = GPIO.LOW if msg.payload == "ON" else GPIO.HIGH
GPIO.output(self.pin, out)