merkelck

switching

Apr 26th, 2024
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1.  
  2. for (int i = 0; i < length; i++) {
  3. Serial.print((char)message[i]);
  4. messageTemp += (char)message[i];
  5. }
  6. Serial.println();
  7.  
  8. // Feel free to add more if statements to control more GPIOs with MQTT
  9.  
  10. // 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
  11. if(topic=="home/office/sonoff01X"){
  12. Serial.print("Changing sonoff01X to ");
  13. if(messageTemp == "on"){
  14. digitalWrite(gpio13Led, LOW);
  15. digitalWrite(gpio12Relay, HIGH);
  16. Serial.print("On");
  17. client.publish("home/office/sonoff01X/state","on");
  18. }
  19. else if(messageTemp == "off"){
  20. digitalWrite(gpio13Led, HIGH);
  21. digitalWrite(gpio12Relay, LOW);
  22. Serial.print("Off");
  23. client.publish("home/office/sonoff01X/state","off");
  24. }
  25. }
  26. Serial.println();
  27. }
  28.  
  29.  
Advertisement
Add Comment
Please, Sign In to add comment