sumnerboy12 / mqtt-gpio-monitor

Python script for sending/receiving commands to/from GPIO pins via MQTT messages
46 stars 23 forks source link

Incoming message for pin # #28

Closed AJStubbsy closed 6 years ago

AJStubbsy commented 6 years ago

This isn't an issue, the code is ace! as I'm sure you're aware, but I'm stuck and couldn't think of another way to ask.

No matter what I change, I always get a payload sent to the control GPIOs when my RPi Zero connects to the MQTT broker. I'm monitoring/controlling it from a RPi3 using Home Assistant. My MQTT switches in Hass have Retain set to False and Qos 0. The reason this is a problem for me is that I'm using your program to set the control GPIO to LOW, then on_message turn the GPIO HIGH, wait for 1 second then back to LOW. The GPIO pin is opening a transistor that is shorting out the Advance button on my central heating programmer, so it's simulating the button being pressed. Each time the button is pressed/shorted-out the heating either comes on or goes off. For this reason I have IN payload 0 and 1 doing the same thing (HIGH, wait 1 sec, LOW). When I reboot, I think the LWT function is sending a payload, which effectively toggles the state of my heating. I've tried a few things like: -

Set MQTT_LWT payload to '3' - and then have that just keep the GPIO pin LOW Set MQTT_LWT Retain to False Set MQTT_LWT blank - which just stops the program running

I know there's a few instances of LWT and so I've adjusted each of them. I don't suppose you have a suggestions? You can probably guess from my terminology that I'm not exactly a pro when it comes to this but anything you can suggest to point me in the right direction would be greatly appreciated.

Thanks for making this monitor available by the way. If I could only guarantee my RPi Zero wouldn't reboot I'd be laughing, cause it works a treat once it's running!

sumnerboy12 commented 6 years ago

Very hard to say sorry. Publishes to LWT should have no effect on your control topics, unless you have them set to the same topic in your INI file. Sorry I can't be of more help.

AJStubbsy commented 6 years ago

I imagined you'd probably had enough of people asking questions after they've fucked about with your code to be honest, so I'm grateful you answered at all!

When you say "unless you have them set to the same topic in your INI file" are you referring to MQTT_LWT? I haven't changed that, it's still 'clients/mqtt-gpio-monitor' and my MQTT_TOPIC is 'heating'. So if I'm understanding correctly, the LWT won't send a payload on_connect? Which would mean my problem is coming from hass when a device connects to the broker?

I know you can't be sure of my setup but does that sound like a sensible diagnosis?

sumnerboy12 commented 6 years ago

When the client connects to your broker, it will publish a message on the LWT topic, to indicate the client is alive. It won't publish anything on your control topic, unless you have retain set (which you say you haven't). If you have clean_session=False then if there were messages sent to that topic while your client was offline, then those might be published upon connection. See the docs on what clean_session actually does. Good luck!