0

Synching Gauge and Switch using mqtt_client.py?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Synching Gauge and Switch using mqtt_client.py?

by fghorow on Sat Jun 16, 2018 10:59 pm

Hi All,

Noob question here regarding callbacks, timings, and initialization.

I'm using a modified version of mqtt_client.py to write an on/off pump controller on a RPi. I read/write the relevant GPIO pin status using the wiringpi library from another site, and have hooked up the callbacks in the example mqtt_client.py such that when I click on a toggle switch on my dashboard, it correctly toggles the GPIO pin. I also publish the status of that GPIO pin to a gauge on my dashboard.

I'm mostly interested in running the pump on a schedule via crontab entries, but occasionally need to override the state using the toggle switch. I'd really like to keep the gauge as a (remote) status monitor, and the switch to override the crontab settings. My problem is that there's an annoyance on startup: the GPIO pin state is un-synched with the status of the toggle switch.

I'm not an EE, but I'm sure that similar problems have been done "the right way (TM)" for decades. Any suggestions on how (and where in the mqtt_client.py style code) to synch the initial status of the dashboard toggle switch with the current value of the GPIO pin?

TIA for any help you might be able to provide!!!

fghorow
 
Posts: 2
Joined: Sat Jun 16, 2018 10:38 pm

Re: Synching Gauge and Switch using mqtt_client.py?

by fghorow on Mon Jun 18, 2018 1:42 pm

Never mind. I figured out that if I simply send the status to both the toggle switch and the gauge, it works.

Clunky, but working...

Hope this helps somebody else...

fghorow
 
Posts: 2
Joined: Sat Jun 16, 2018 10:38 pm

Please be positive and constructive with your questions and comments.