I am using umqtt library for Python to interface with Cayenne MQTT server. I have the following issue: I want to control two buttons B1 and B2 (controlling two different pins on my ESP32) on my Cayenne dashboard. In my ESP32 I subscribe two the command topics for both of the channels associated with the buttons. I also create the necessary callback function to handle the received messages. My question is: how is it possible to know which button (B1 or B2 sent the command) so I parse the command in the proper way?
You probably already know that, your MQTT action consists of a TOPIC, and a PAYLOAD (the actual message). I’ve never used that particular library, but it shouldn’t matter. Specifically in Cayenne, (for an actuator) things might look something like…
TOPIC = v1/MQTT_USERNAME/things/CLIENT_ID/cmd/ChannelNumber
PAYLOAD = Sequence_ID, value
So, in order to find out which button you are sending commands from, inside your Callback function, you should check the last TOPIC’s character, in this case “5” (Actuator on channel 5). Then you should check the PAYLOAD’s last character to get the value (1 in this case, ON). For example…