Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- for (int i = 0; i < length; i++) {
- Serial.print((char)message[i]);
- messageTemp += (char)message[i];
- }
- Serial.println();
- // Feel free to add more if statements to control more GPIOs with MQTT
- // If a message is received on the topic home/office/sonoff01X, you check if the message is either 1 or 0. Turns the ESP GPIO according to the message
- if(topic=="home/office/sonoff01X"){
- Serial.print("Changing sonoff01X to ");
- if(messageTemp == "on"){
- digitalWrite(gpio13Led, LOW);
- digitalWrite(gpio12Relay, HIGH);
- Serial.print("On");
- client.publish("home/office/sonoff01X/state","on");
- }
- else if(messageTemp == "off"){
- digitalWrite(gpio13Led, HIGH);
- digitalWrite(gpio12Relay, LOW);
- Serial.print("Off");
- client.publish("home/office/sonoff01X/state","off");
- }
- }
- Serial.println();
- }
Advertisement
Add Comment
Please, Sign In to add comment