pleasedontcode

# WiFi Relays rev_03

Mar 9th, 2026
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 16.73 KB | None | 0 0
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: # WiFi Relays
  13.     - Version: 003
  14.     - Source Code NOT compiled for: ESP32 DevKit V1
  15.     - Source Code created on: 2026-03-09 05:17:30
  16.  
  17. ********* Pleasedontcode.com **********/
  18.  
  19. /****** SYSTEM REQUIREMENTS *****/
  20. /****** SYSTEM REQUIREMENT 1 *****/
  21.     /* Control 8 relay outputs independently via GPIO */
  22.     /* pins. Each relay can be turned ON or OFF */
  23.     /* individually. */
  24. /****** SYSTEM REQUIREMENT 2 *****/
  25.     /* Initialize all 8 relay pins at startup and set */
  26.     /* them to LOW (OFF) state. */
  27. /****** SYSTEM REQUIREMENT 3 *****/
  28.     /* Provide relay control functions to toggle each */
  29.     /* relay between ON and OFF states. */
  30. /****** SYSTEM REQUIREMENT 4 *****/
  31.     /* Enable WiFi connectivity on ESP32 to connect to */
  32.     /* home network. Support WiFi credential */
  33.     /* configuration. */
  34. /****** SYSTEM REQUIREMENT 5 *****/
  35.     /* Connect to MQTT broker and subscribe to relay */
  36.     /* control topics to receive ON/OFF commands */
  37.     /* remotely. */
  38. /****** SYSTEM REQUIREMENT 6 *****/
  39.     /* Publish relay state changes to MQTT broker so */
  40.     /* other IoT devices can monitor relay status in */
  41.     /* real-time. */
  42. /****** SYSTEM REQUIREMENT 7 *****/
  43.     /* Implement MQTT reconnection logic to automatically */
  44.     /* reconnect if broker connection is lost. */
  45. /****** END SYSTEM REQUIREMENTS *****/
  46.  
  47.  
  48. /* START CODE */
  49.  
  50. /****** DEFINITION OF LIBRARIES *****/
  51. #include <MQUnifiedsensor.h>
  52. #include <WiFi.h>
  53. #include <PubSubClient.h>
  54.  
  55. /****** WIFI AND MQTT CONFIGURATION CONSTANTS *****/
  56. // WiFi network credentials
  57. const char* WIFI_SSID = "YOUR_SSID";
  58. const char* WIFI_PASSWORD = "YOUR_PASSWORD";
  59.  
  60. // MQTT broker configuration
  61. const char* MQTT_BROKER = "broker.hivemq.com";
  62. const int MQTT_PORT = 1883;
  63. const char* MQTT_CLIENT_ID = "ESP32_Relay_Controller";
  64. const char* MQTT_USERNAME = "";
  65. const char* MQTT_PASSWORD = "";
  66.  
  67. // MQTT topic base path
  68. const char* MQTT_BASE_TOPIC = "home/relays";
  69. const char* MQTT_RELAY_CONTROL_TOPIC_BASE = "home/relays/relay";
  70. const char* MQTT_RELAY_STATE_TOPIC_BASE = "home/relays/state/relay";
  71.  
  72. // Reconnection timing constants
  73. const unsigned long WIFI_RECONNECT_INTERVAL = 5000;
  74. const unsigned long MQTT_RECONNECT_INTERVAL = 5000;
  75. const unsigned long MQTT_KEEPALIVE_INTERVAL = 60000;
  76.  
  77. /****** FUNCTION PROTOTYPES *****/
  78. void setup(void);
  79. void loop(void);
  80. void initializeRelayPins(void);
  81. void relayON(uint8_t relayNumber);
  82. void relayOFF(uint8_t relayNumber);
  83. void relayToggle(uint8_t relayNumber);
  84. void initializeWiFi(void);
  85. void checkWiFiConnection(void);
  86. void initializeMQTT(void);
  87. void checkMQTTConnection(void);
  88. void mqttCallback(char* topic, byte* payload, unsigned int length);
  89. void publishRelayState(uint8_t relayNumber);
  90. void publishAllRelayStates(void);
  91. void handleMQTTMessage(char* topic, byte* payload, unsigned int length);
  92. void subscribeToAllRelayTopics(void);
  93.  
  94. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  95. const uint8_t RelayModule8Ch_MQ309A_DOUT_PIN_D4 = 4;
  96.  
  97. /***** DEFINITION OF ANALOG INPUT PINS *****/
  98. const uint8_t RelayModule8Ch_MQ309A_AOUT_PIN_D32 = 32;
  99.  
  100. /***** DEFINITION OF RELAY CONTROL PINS *****/
  101. // SYSTEM REQUIREMENT 1: Control 8 relay outputs independently via GPIO pins
  102. // Relay pins for ESP32 DevKit V1
  103. const uint8_t RELAY_PIN_1 = 12;
  104. const uint8_t RELAY_PIN_2 = 13;
  105. const uint8_t RELAY_PIN_3 = 14;
  106. const uint8_t RELAY_PIN_4 = 15;
  107. const uint8_t RELAY_PIN_5 = 16;
  108. const uint8_t RELAY_PIN_6 = 17;
  109. const uint8_t RELAY_PIN_7 = 18;
  110. const uint8_t RELAY_PIN_8 = 19;
  111.  
  112. // Array to store relay pins for easier management
  113. const uint8_t relayPins[8] = {
  114.   RELAY_PIN_1, RELAY_PIN_2, RELAY_PIN_3, RELAY_PIN_4,
  115.   RELAY_PIN_5, RELAY_PIN_6, RELAY_PIN_7, RELAY_PIN_8
  116. };
  117.  
  118. // Array to store relay states
  119. uint8_t relayStates[8] = {LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW};
  120.  
  121. /****** WIFI AND MQTT CLIENT INSTANCES *****/
  122. WiFiClient espClient;
  123. PubSubClient mqttClient(espClient);
  124.  
  125. /****** TIMING VARIABLES FOR RECONNECTION LOGIC *****/
  126. unsigned long lastWiFiCheckTime = 0;
  127. unsigned long lastMQTTCheckTime = 0;
  128. unsigned long lastMQTTKeepAliveTime = 0;
  129.  
  130. /****** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
  131.  
  132. void setup(void)
  133. {
  134.     // Serial communication initialization for debugging
  135.     Serial.begin(115200);
  136.     delay(100);
  137.  
  138.     Serial.println("\n\nStarting Relay Controller with IoT Functionality...");
  139.    
  140.     // Initialize MQ309A sensor pins
  141.     pinMode(RelayModule8Ch_MQ309A_DOUT_PIN_D4, INPUT_PULLUP);
  142.     pinMode(RelayModule8Ch_MQ309A_AOUT_PIN_D32, INPUT);
  143.    
  144.     // SYSTEM REQUIREMENT 2: Initialize all 8 relay pins at startup
  145.     // and set them to LOW (OFF) state
  146.     initializeRelayPins();
  147.    
  148.     // Initialize WiFi connectivity
  149.     // SYSTEM REQUIREMENT 4: Enable WiFi connectivity on ESP32
  150.     initializeWiFi();
  151.    
  152.     // Initialize MQTT client and configuration
  153.     // SYSTEM REQUIREMENT 5: Connect to MQTT broker
  154.     initializeMQTT();
  155.    
  156.     Serial.println("System initialized successfully");
  157.     Serial.println("All 8 relays are set to OFF state");
  158.     Serial.println("WiFi and MQTT initialization in progress...");
  159. }
  160.  
  161. void loop(void)
  162. {
  163.     // Check WiFi connection status and reconnect if needed
  164.     // SYSTEM REQUIREMENT 7: Implement MQTT reconnection logic
  165.     checkWiFiConnection();
  166.    
  167.     // Check MQTT connection status and reconnect if needed
  168.     checkMQTTConnection();
  169.    
  170.     // Maintain MQTT connection
  171.     if (mqttClient.connected())
  172.     {
  173.         mqttClient.loop();
  174.     }
  175.    
  176.     // Small delay to prevent overwhelming the MCU
  177.     delay(10);
  178. }
  179.  
  180. /****** RELAY CONTROL FUNCTIONS *****/
  181.  
  182. // SYSTEM REQUIREMENT 2: Initialize all 8 relay pins at startup
  183. // and set them to LOW (OFF) state
  184. void initializeRelayPins(void)
  185. {
  186.     // Configure all 8 relay pins as OUTPUT and set to LOW (OFF)
  187.     for (uint8_t i = 0; i < 8; i++)
  188.     {
  189.         pinMode(relayPins[i], OUTPUT);
  190.         digitalWrite(relayPins[i], LOW);
  191.         relayStates[i] = LOW;
  192.     }
  193.    
  194.     Serial.println("All relay pins initialized to LOW (OFF) state:");
  195.     for (uint8_t i = 0; i < 8; i++)
  196.     {
  197.         Serial.print("Relay ");
  198.         Serial.print(i + 1);
  199.         Serial.print(" (GPIO ");
  200.         Serial.print(relayPins[i]);
  201.         Serial.println(") = OFF");
  202.     }
  203. }
  204.  
  205. // SYSTEM REQUIREMENT 3: Provide relay control functions to toggle
  206. // each relay between ON and OFF states
  207. // Function to turn ON a specific relay (1-8)
  208. void relayON(uint8_t relayNumber)
  209. {
  210.     // Validate relay number (1-8)
  211.     if (relayNumber < 1 || relayNumber > 8)
  212.     {
  213.         Serial.print("Error: Invalid relay number ");
  214.         Serial.println(relayNumber);
  215.         return;
  216.     }
  217.    
  218.     // Convert relay number (1-8) to array index (0-7)
  219.     uint8_t index = relayNumber - 1;
  220.    
  221.     // Set relay to HIGH (ON)
  222.     digitalWrite(relayPins[index], HIGH);
  223.     relayStates[index] = HIGH;
  224.    
  225.     Serial.print("Relay ");
  226.     Serial.print(relayNumber);
  227.     Serial.print(" (GPIO ");
  228.     Serial.print(relayPins[index]);
  229.     Serial.println(") turned ON");
  230.    
  231.     // SYSTEM REQUIREMENT 6: Publish relay state changes to MQTT broker
  232.     publishRelayState(relayNumber);
  233. }
  234.  
  235. // SYSTEM REQUIREMENT 3: Provide relay control functions to toggle
  236. // each relay between ON and OFF states
  237. // Function to turn OFF a specific relay (1-8)
  238. void relayOFF(uint8_t relayNumber)
  239. {
  240.     // Validate relay number (1-8)
  241.     if (relayNumber < 1 || relayNumber > 8)
  242.     {
  243.         Serial.print("Error: Invalid relay number ");
  244.         Serial.println(relayNumber);
  245.         return;
  246.     }
  247.    
  248.     // Convert relay number (1-8) to array index (0-7)
  249.     uint8_t index = relayNumber - 1;
  250.    
  251.     // Set relay to LOW (OFF)
  252.     digitalWrite(relayPins[index], LOW);
  253.     relayStates[index] = LOW;
  254.    
  255.     Serial.print("Relay ");
  256.     Serial.print(relayNumber);
  257.     Serial.print(" (GPIO ");
  258.     Serial.print(relayPins[index]);
  259.     Serial.println(") turned OFF");
  260.    
  261.     // SYSTEM REQUIREMENT 6: Publish relay state changes to MQTT broker
  262.     publishRelayState(relayNumber);
  263. }
  264.  
  265. // SYSTEM REQUIREMENT 3: Provide relay control functions to toggle
  266. // each relay between ON and OFF states
  267. // Function to toggle a specific relay (1-8)
  268. void relayToggle(uint8_t relayNumber)
  269. {
  270.     // Validate relay number (1-8)
  271.     if (relayNumber < 1 || relayNumber > 8)
  272.     {
  273.         Serial.print("Error: Invalid relay number ");
  274.         Serial.println(relayNumber);
  275.         return;
  276.     }
  277.    
  278.     // Convert relay number (1-8) to array index (0-7)
  279.     uint8_t index = relayNumber - 1;
  280.    
  281.     // Toggle relay state
  282.     if (relayStates[index] == LOW)
  283.     {
  284.         digitalWrite(relayPins[index], HIGH);
  285.         relayStates[index] = HIGH;
  286.         Serial.print("Relay ");
  287.         Serial.print(relayNumber);
  288.         Serial.print(" (GPIO ");
  289.         Serial.print(relayPins[index]);
  290.         Serial.println(") toggled to ON");
  291.     }
  292.     else
  293.     {
  294.         digitalWrite(relayPins[index], LOW);
  295.         relayStates[index] = LOW;
  296.         Serial.print("Relay ");
  297.         Serial.print(relayNumber);
  298.         Serial.print(" (GPIO ");
  299.         Serial.print(relayPins[index]);
  300.         Serial.println(") toggled to OFF");
  301.     }
  302.    
  303.     // SYSTEM REQUIREMENT 6: Publish relay state changes to MQTT broker
  304.     publishRelayState(relayNumber);
  305. }
  306.  
  307. /****** WIFI CONNECTIVITY FUNCTIONS *****/
  308.  
  309. // SYSTEM REQUIREMENT 4: Enable WiFi connectivity on ESP32 to connect to home network
  310. // Initialize WiFi connection with network credentials
  311. void initializeWiFi(void)
  312. {
  313.     Serial.println("\n--- WiFi Initialization ---");
  314.     Serial.print("Connecting to WiFi SSID: ");
  315.     Serial.println(WIFI_SSID);
  316.    
  317.     // Set WiFi mode to station mode
  318.     WiFi.mode(WIFI_STA);
  319.    
  320.     // Start WiFi connection with credentials
  321.     WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  322.    
  323.     // Wait for connection with timeout
  324.     int connectionAttempts = 0;
  325.     const int maxAttempts = 20;
  326.    
  327.     while (WiFi.status() != WL_CONNECTED && connectionAttempts < maxAttempts)
  328.     {
  329.         delay(500);
  330.         Serial.print(".");
  331.         connectionAttempts++;
  332.     }
  333.    
  334.     if (WiFi.status() == WL_CONNECTED)
  335.     {
  336.         Serial.println("\nWiFi connected successfully!");
  337.         Serial.print("IP Address: ");
  338.         Serial.println(WiFi.localIP());
  339.         Serial.print("Signal Strength: ");
  340.         Serial.print(WiFi.RSSI());
  341.         Serial.println(" dBm");
  342.     }
  343.     else
  344.     {
  345.         Serial.println("\nWiFi connection failed!");
  346.         Serial.println("Will attempt to reconnect automatically...");
  347.     }
  348. }
  349.  
  350. // Check WiFi connection and attempt reconnection if disconnected
  351. void checkWiFiConnection(void)
  352. {
  353.     unsigned long currentTime = millis();
  354.    
  355.     // Check WiFi status at regular intervals
  356.     if (currentTime - lastWiFiCheckTime >= WIFI_RECONNECT_INTERVAL)
  357.     {
  358.         lastWiFiCheckTime = currentTime;
  359.        
  360.         if (WiFi.status() != WL_CONNECTED)
  361.         {
  362.             Serial.println("WiFi connection lost. Attempting to reconnect...");
  363.             WiFi.reconnect();
  364.         }
  365.     }
  366. }
  367.  
  368. /****** MQTT FUNCTIONS *****/
  369.  
  370. // SYSTEM REQUIREMENT 5: Connect to MQTT broker and subscribe to relay control topics
  371. // Initialize MQTT client and set broker connection parameters
  372. void initializeMQTT(void)
  373. {
  374.     Serial.println("\n--- MQTT Initialization ---");
  375.    
  376.     // Set MQTT broker server and port
  377.     mqttClient.setServer(MQTT_BROKER, MQTT_PORT);
  378.    
  379.     // Set callback function for incoming MQTT messages
  380.     mqttClient.setCallback(mqttCallback);
  381.    
  382.     // Configure buffer sizes for topic and payload handling
  383.     mqttClient.setBufferSize(512);
  384.    
  385.     Serial.print("MQTT Broker: ");
  386.     Serial.print(MQTT_BROKER);
  387.     Serial.print(":");
  388.     Serial.println(MQTT_PORT);
  389.     Serial.println("MQTT initialization complete. Will connect when WiFi is available.");
  390. }
  391.  
  392. // Check MQTT connection and attempt reconnection if disconnected
  393. void checkMQTTConnection(void)
  394. {
  395.     unsigned long currentTime = millis();
  396.    
  397.     // Check MQTT connection status
  398.     if (!mqttClient.connected())
  399.     {
  400.         // Try to reconnect at regular intervals
  401.         if (currentTime - lastMQTTCheckTime >= MQTT_RECONNECT_INTERVAL)
  402.         {
  403.             lastMQTTCheckTime = currentTime;
  404.            
  405.             // Only attempt MQTT connection if WiFi is connected
  406.             if (WiFi.status() == WL_CONNECTED)
  407.             {
  408.                 Serial.println("Attempting MQTT connection...");
  409.                
  410.                 // Create MQTT client ID with unique identifier
  411.                 String clientId = String(MQTT_CLIENT_ID) + "_" + String(ESP.getChipId(), HEX);
  412.                
  413.                 // Attempt to connect to MQTT broker with credentials if provided
  414.                 boolean connected = false;
  415.                 if (strlen(MQTT_USERNAME) > 0)
  416.                 {
  417.                     connected = mqttClient.connect(
  418.                         clientId.c_str(),
  419.                         MQTT_USERNAME,
  420.                         MQTT_PASSWORD
  421.                     );
  422.                 }
  423.                 else
  424.                 {
  425.                     connected = mqttClient.connect(clientId.c_str());
  426.                 }
  427.                
  428.                 if (connected)
  429.                 {
  430.                     Serial.println("MQTT connected successfully!");
  431.                     Serial.print("Client ID: ");
  432.                     Serial.println(clientId);
  433.                    
  434.                     // Subscribe to all relay control topics
  435.                     // SYSTEM REQUIREMENT 5: Subscribe to relay control topics
  436.                     subscribeToAllRelayTopics();
  437.                    
  438.                     // Publish all relay states on connection
  439.                     // SYSTEM REQUIREMENT 6: Publish relay state changes
  440.                     publishAllRelayStates();
  441.                 }
  442.                 else
  443.                 {
  444.                     Serial.print("MQTT connection failed, rc=");
  445.                     Serial.println(mqttClient.state());
  446.                 }
  447.             }
  448.             else
  449.             {
  450.                 Serial.println("WiFi not connected. Skipping MQTT connection attempt.");
  451.             }
  452.         }
  453.     }
  454.     else
  455.     {
  456.         // Keep MQTT connection alive by sending keepalive message periodically
  457.         if (currentTime - lastMQTTKeepAliveTime >= MQTT_KEEPALIVE_INTERVAL)
  458.         {
  459.             lastMQTTKeepAliveTime = currentTime;
  460.             // The PubSubClient library handles PINGREQ automatically, no manual action needed
  461.         }
  462.     }
  463. }
  464.  
  465. // Callback function for incoming MQTT messages
  466. // SYSTEM REQUIREMENT 5: Connect to MQTT broker and subscribe to relay control topics
  467. // to receive ON/OFF commands remotely
  468. void mqttCallback(char* topic, byte* payload, unsigned int length)
  469. {
  470.     Serial.print("MQTT Message received on topic: ");
  471.     Serial.println(topic);
  472.    
  473.     // Handle received MQTT message
  474.     handleMQTTMessage(topic, payload, length);
  475. }
  476.  
  477. // Process incoming MQTT message and control relays accordingly
  478. void handleMQTTMessage(char* topic, byte* payload, unsigned int length)
  479. {
  480.     // Convert payload to string
  481.     String payloadStr = "";
  482.     for (unsigned int i = 0; i < length; i++)
  483.     {
  484.         payloadStr += (char)payload[i];
  485.     }
  486.    
  487.     Serial.print("Payload: ");
  488.     Serial.println(payloadStr);
  489.    
  490.     // Parse topic and extract relay number
  491.     String topicStr = String(topic);
  492.    
  493.     // Check if topic is a relay control topic
  494.     if (topicStr.startsWith("home/relays/relay") && topicStr.endsWith("/control"))
  495.     {
  496.         // Extract relay number from topic
  497.         // Topic format: home/relays/relay<N>/control
  498.         int startIndex = String("home/relays/relay").length();
  499.         int endIndex = topicStr.indexOf("/control");
  500.        
  501.         if (startIndex < endIndex)
  502.         {
  503.             String relayNumStr = topicStr.substring(startIndex, endIndex);
  504.             uint8_t relayNumber = relayNumStr.toInt();
  505.            
  506.             // Validate relay number
  507.             if (relayNumber >= 1 && relayNumber <= 8)
  508.             {
  509.                 // Process command
  510.                 if (payloadStr == "ON" || payloadStr == "on" || payloadStr == "1")
  511.                 {
  512.                     Serial.print("Turning ON relay ");
  513.                     Serial.println(relayNumber);
  514.                     relayON(relayNumber);
  515.                 }
  516.                 else if (payloadStr == "OFF" || payloadStr == "off" || payloadStr == "0")
  517.                 {
  518.                     Serial.print("Turning OFF relay ");
  519.                     Serial.println(relayNumber);
  520.                     relayOFF(relayNumber);
  521.                 }
  522.                 else if (payloadStr == "TOGGLE" || payloadStr == "toggle")
  523.                 {
  524.                     Serial.print("Toggling relay ");
  525.                     Serial.println(relayNumber);
  526.                     relayToggle(relayNumber);
  527.                 }
  528.             }
  529.         }
  530.     }
  531. }
  532.  
  533. // Subscribe to all relay control topics
  534. void subscribeToAllRelayTopics(void)
  535. {
  536.     // Subscribe to individual relay control topics (relay1 to relay8)
  537.     for (uint8_t i = 1; i <= 8; i++)
  538.     {
  539.         String topic = String("home/relays/relay") + String(i) + String("/control");
  540.         if (mqttClient.subscribe(topic.c_str()))
  541.         {
  542.             Serial.print("Subscribed to: ");
  543.             Serial.println(topic);
  544.         }
  545.         else
  546.         {
  547.             Serial.print("Failed to subscribe to: ");
  548.             Serial.println(topic);
  549.         }
  550.     }
  551.    
  552.     // Subscribe to broadcast control topic for all relays
  553.     if (mqttClient.subscribe("home/relays/all/control"))
  554.     {
  555.         Serial.println("Subscribed to: home/relays/all/control");
  556.     }
  557. }
  558.  
  559. // Publish the current state of a specific relay
  560. // SYSTEM REQUIREMENT 6: Publish relay state changes to MQTT broker
  561. // so other IoT devices can monitor relay status in real-time
  562. void publishRelayState(uint8_t relayNumber)
  563. {
  564.     // Validate relay number
  565.     if (relayNumber < 1 || relayNumber > 8)
  566.     {
  567.         return;
  568.     }
  569.    
  570.     // Only publish if MQTT is connected
  571.     if (!mqttClient.connected())
  572.     {
  573.         Serial.println("MQTT not connected. State not published.");
  574.         return;
  575.     }
  576.    
  577.     // Build topic
  578.     String topic = String("home/relays/state/relay") + String(relayNumber);
  579.    
  580.     // Get relay state
  581.     uint8_t index = relayNumber - 1;
  582.     String state = (relayStates[index] == HIGH) ? "ON" : "OFF";
  583.    
  584.     // Publish state
  585.     if (mqttClient.publish(topic.c_str(), state.c_str(), true))
  586.     {
  587.         Serial.print("Published relay ");
  588.         Serial.print(relayNumber);
  589.         Serial.print(" state: ");
  590.         Serial.print(state);
  591.         Serial.print(" to topic: ");
  592.         Serial.println(topic);
  593.     }
  594.     else
  595.     {
  596.         Serial.print("Failed to publish relay state for relay ");
  597.         Serial.println(relayNumber);
  598.     }
  599. }
  600.  
  601. // Publish the current state of all relays
  602. void publishAllRelayStates(void)
  603. {
  604.     Serial.println("Publishing all relay states...");
  605.    
  606.     for (uint8_t i = 1; i <= 8; i++)
  607.     {
  608.         publishRelayState(i);
  609.         delay(100);
  610.     }
  611.    
  612.     Serial.println("All relay states published.");
  613. }
  614.  
  615. /* END CODE */
  616.  
Advertisement
Add Comment
Please, Sign In to add comment