But now I want to publish the topic include the deviceID and the pin of light /turn/light/{deviceID}/{pin}/{action}
Example: /turn/light/esp123456/5/1
That only effect with the deviceID: esp123456 and the light connected on pin 5th is ON
Below is Arduino code
void callback(char* topic, byte* payload, unsigned int length) {
String topicStr = topic;
//turn the light on if the payload is '1' and publish to the MQTT server a confirmation message
if (payload[0] == '1') {
digitalWrite(5, HIGH);
client.publish("/state/light", "Light On");
}
//turn the light off if the payload is '0' and publish to the MQTT server a confirmation message
else if (payload[0] == '0') {
digitalWrite(5, LOW);
client.publish("/state/light", "Light Off");
}
}
Hello @bluerhinos My code is working by turn the light on/off URLAPI calling: http://domainname.com/api/turnTheLight/5/1 routes: /api/{pin}/{action}
But now I want to publish the topic include the deviceID and the pin of light
/turn/light/{deviceID}/{pin}/{action}
Example:/turn/light/esp123456/5/1
That only effect with the deviceID: esp123456 and the light connected on pin 5th is ONBelow is Arduino code
Please help me.