├── .gitattributes └── 16_Appliances_Home_Automation └── 16_Appliances_Home_Automation.ino /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /16_Appliances_Home_Automation/16_Appliances_Home_Automation.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | /**************************************** 7 | Define Constants 8 | ****************************************/ 9 | 10 | #define WIFISSID "SSID" // Put your WifiSSID here 11 | #define PASSWORD "PASSWORD" // Put your wifi password here 12 | #define TOKEN "Token" // Put your Ubidots' TOKEN 13 | 14 | #define VARIABLE_LABEL_SUB_1 "relay1" // Assing the variable label to subscribe 15 | #define VARIABLE_LABEL_SUB_2 "relay2" // Assing the variable label to subscribe 16 | #define VARIABLE_LABEL_SUB_3 "relay3" // Assing the variable label to subscribe 17 | #define VARIABLE_LABEL_SUB_4 "relay4" // Assing the variable label to subscribe 18 | #define VARIABLE_LABEL_SUB_5 "relay5" // Assing the variable label to subscribe 19 | #define VARIABLE_LABEL_SUB_6 "relay6" // Assing the variable label to subscribe 20 | #define VARIABLE_LABEL_SUB_7 "relay7" // Assing the variable label to subscribe 21 | #define VARIABLE_LABEL_SUB_8 "relay8" // Assing the variable label to subscribe 22 | #define VARIABLE_LABEL_SUB_9 "relay9" // Assing the variable label to subscribe 23 | #define VARIABLE_LABEL_SUB_10 "relay10" // Assing the variable label to subscribe 24 | #define VARIABLE_LABEL_SUB_11 "relay11" // Assing the variable label to subscribe 25 | #define VARIABLE_LABEL_SUB_12 "relay12" // Assing the variable label to subscribe 26 | #define VARIABLE_LABEL_SUB_13 "relay13" // Assing the variable label to subscribe 27 | #define VARIABLE_LABEL_SUB_14 "relay14" // Assing the variable label to subscribe 28 | #define VARIABLE_LABEL_SUB_15 "relay15" // Assing the variable label to subscribe 29 | #define VARIABLE_LABEL_SUB_16 "relay16" // Assing the variable label to subscribe 30 | 31 | #define DEVICE_LABEL "esp32" // Assig the device label to subscribe 32 | #define MQTT_CLIENT_NAME "testing" // MQTT client Name, put a Random ASCII 33 | //#define SENSOR1 12; 34 | //#define SENSOR2 13; 35 | #define R1 15 36 | #define R2 2 37 | #define R3 4 38 | #define R4 18 39 | #define R5 19 40 | #define R6 21 41 | #define R7 22 42 | #define R8 23 43 | #define R9 32 44 | #define R10 33 45 | #define R11 25 46 | #define R12 26 47 | #define R13 27 48 | #define R14 14 49 | #define R15 12 50 | #define R16 13 51 | 52 | #define Buzzer 5 53 | 54 | char mqttBroker[] = "industrial.api.ubidots.com"; 55 | 56 | const int ERROR_VALUE = 65535; // Set here an error value 57 | 58 | const uint8_t NUMBER_OF_VARIABLES = 16; // Number of variable to subscribe to 59 | char * variable_labels[NUMBER_OF_VARIABLES] = {"relay1", "relay2", "relay3", "relay4", "relay5", "relay6", "relay7", "relay8", "relay9", "relay10", "relay11", "relay12", "relay13", "relay14", "relay15", "relay16"}; // labels of the variable to subscribe to 60 | 61 | float CONTROL1; // Name of the variable to be used within the code. 62 | float CONTROL2; // Name of the variable to be used within the code. 63 | float CONTROL3; // Name of the variable to be used within the code. 64 | float CONTROL4; // Name of the variable to be used within the code. 65 | float CONTROL5; // Name of the variable to be used within the code. 66 | float CONTROL6; // Name of the variable to be used within the code. 67 | float CONTROL7; // Name of the variable to be used within the code. 68 | float CONTROL8; // Name of the variable to be used within the code. 69 | float CONTROL9; // Name of the variable to be used within the code. 70 | float CONTROL10; // Name of the variable to be used within the code. 71 | float CONTROL11; // Name of the variable to be used within the code. 72 | float CONTROL12; // Name of the variable to be used within the code. 73 | float CONTROL13; // Name of the variable to be used within the code. 74 | float CONTROL14; // Name of the variable to be used within the code. 75 | float CONTROL15; // Name of the variable to be used within the code. 76 | float CONTROL16; // Name of the variable to be used within the code. 77 | 78 | float value; // To store incoming value. 79 | uint8_t variable; // To keep track of the state machine and be able to use the switch case. 80 | 81 | //char str_sensor1[10]; // Space to store values to send 82 | //char str_sensor2[10]; // Space to store values to send 83 | 84 | /**************************************** 85 | Initializate constructors for objects 86 | ****************************************/ 87 | 88 | WiFiClient ubidots; 89 | PubSubClient client(ubidots); 90 | 91 | 92 | /**************************************** 93 | Auxiliar Functions 94 | ****************************************/ 95 | 96 | void callback(char* topic, byte* payload, unsigned int length) { 97 | char* variable_label = (char *) malloc(sizeof(char) * 30);; 98 | get_variable_label_topic(topic, variable_label); 99 | value = btof(payload, length); 100 | set_state(variable_label); 101 | execute_cases(); 102 | free(variable_label); 103 | } 104 | 105 | // Parse topic to extract the variable label which changed value 106 | void get_variable_label_topic(char * topic, char * variable_label) { 107 | Serial.print("topic:"); 108 | Serial.println(topic); 109 | sprintf(variable_label, ""); 110 | for (int i = 0; i < NUMBER_OF_VARIABLES; i++) { 111 | char * result_lv = strstr(topic, variable_labels[i]); 112 | if (result_lv != NULL) { 113 | uint8_t len = strlen(result_lv); 114 | char result[100]; 115 | uint8_t i = 0; 116 | for (i = 0; i < len - 3; i++) { 117 | result[i] = result_lv[i]; 118 | } 119 | result[i] = '\0'; 120 | Serial.print("Label is: "); 121 | Serial.println(result); 122 | sprintf(variable_label, "%s", result); 123 | break; 124 | } 125 | } 126 | } 127 | 128 | // cast from an array of chars to float value. 129 | float btof(byte * payload, unsigned int length) { 130 | char * demo_ = (char *) malloc(sizeof(char) * 10); 131 | for (int i = 0; i < length; i++) { 132 | demo_[i] = payload[i]; 133 | } 134 | return atof(demo_); 135 | } 136 | 137 | // State machine to use switch case 138 | void set_state(char* variable_label) { 139 | variable = 0; 140 | for (uint8_t i = 0; i < NUMBER_OF_VARIABLES; i++) { 141 | if (strcmp(variable_label, variable_labels[i]) == 0) { 142 | break; 143 | } 144 | variable++; 145 | } 146 | if (variable >= NUMBER_OF_VARIABLES) variable = ERROR_VALUE; // Not valid 147 | } 148 | 149 | // Function with switch case to determine which variable changed and assigned the value accordingly to the code variable 150 | void execute_cases() { 151 | switch (variable) { 152 | case 0: 153 | CONTROL1 = value; 154 | digitalWrite(R1,value); 155 | Serial.print("CONTROL1: "); 156 | Serial.println(CONTROL1); 157 | Serial.println(); 158 | break; 159 | case 1: 160 | CONTROL2 = value; 161 | digitalWrite(R2,value); 162 | Serial.print("CONTROL2: "); 163 | Serial.println(CONTROL2); 164 | Serial.println(); 165 | break; 166 | case 2: 167 | CONTROL3 = value; 168 | digitalWrite(R3,value); 169 | Serial.print("CONTROL3: "); 170 | Serial.println(CONTROL3); 171 | Serial.println(); 172 | break; 173 | case 3: 174 | CONTROL3 = value; 175 | digitalWrite(R4,value); 176 | Serial.print("CONTROL3: "); 177 | Serial.println(CONTROL3); 178 | Serial.println(); 179 | break; 180 | case 4: 181 | CONTROL5 = value; 182 | digitalWrite(R5,value); 183 | Serial.print("CONTROL5: "); 184 | Serial.println(CONTROL5); 185 | Serial.println(); 186 | break; 187 | case 5: 188 | CONTROL6 = value; 189 | digitalWrite(R6,value); 190 | Serial.print("CONTROL6: "); 191 | Serial.println(CONTROL6); 192 | Serial.println(); 193 | break; 194 | case 6: 195 | CONTROL7 = value; 196 | digitalWrite(R7,value); 197 | Serial.print("CONTROL7: "); 198 | Serial.println(CONTROL7); 199 | 200 | Serial.println(); 201 | break; 202 | case 7: 203 | CONTROL8 = value; 204 | digitalWrite(R8,value); 205 | Serial.print("CONTROL8: "); 206 | Serial.println(CONTROL8); 207 | Serial.println(); 208 | break; 209 | case 8: 210 | CONTROL9 = value; 211 | digitalWrite(R9,value); 212 | Serial.print("CONTROL9: "); 213 | Serial.println(CONTROL9); 214 | Serial.println(); 215 | break; 216 | case 9: 217 | CONTROL10 = value; 218 | digitalWrite(R10,value); 219 | Serial.print("CONTROL10: "); 220 | Serial.println(CONTROL10); 221 | 222 | Serial.println(); 223 | break; 224 | case 10: 225 | CONTROL11 = value; 226 | digitalWrite(R11,value); 227 | Serial.print("CONTROL11: "); 228 | Serial.println(CONTROL11); 229 | Serial.println(); 230 | break; 231 | case 11: 232 | CONTROL12 = value; 233 | digitalWrite(R12,value); 234 | Serial.print("CONTROL12: "); 235 | Serial.println(CONTROL12); 236 | Serial.println(); 237 | break; 238 | case 12: 239 | CONTROL13 = value; 240 | digitalWrite(R13,value); 241 | Serial.print("CONTROL13: "); 242 | Serial.println(CONTROL13); 243 | Serial.println(); 244 | break; 245 | case 13: 246 | CONTROL14 = value; 247 | digitalWrite(R14,value); 248 | Serial.print("CONTROL14: "); 249 | Serial.println(CONTROL14); 250 | Serial.println(); 251 | break; 252 | case 14: 253 | CONTROL15 = value; 254 | digitalWrite(R15,value); 255 | Serial.print("CONTROL15: "); 256 | Serial.println(CONTROL15); 257 | Serial.println(); 258 | break; 259 | case 15: 260 | CONTROL16 = value; 261 | digitalWrite(R16,value); 262 | Serial.print("CONTROL16: "); 263 | Serial.println(CONTROL16); 264 | Serial.println(); 265 | break; 266 | case ERROR_VALUE: 267 | Serial.println("error"); 268 | Serial.println(); 269 | break; 270 | default: 271 | Serial.println("default"); 272 | Serial.println(); 273 | } 274 | 275 | } 276 | 277 | void reconnect() { 278 | // Loop until we're reconnected 279 | while (!client.connected()) { 280 | 281 | digitalWrite(Buzzer, HIGH); 282 | delay(200); 283 | digitalWrite(Buzzer, LOW); 284 | delay(200); 285 | Serial.println("Attempting MQTT connection..."); 286 | 287 | // Attempt to connect 288 | if (client.connect(MQTT_CLIENT_NAME, TOKEN, "")) { 289 | Serial.println("connected"); 290 | digitalWrite(Buzzer, HIGH); 291 | delay(1000); 292 | digitalWrite(Buzzer, LOW); 293 | } else { 294 | Serial.print("failed, rc="); 295 | Serial.print(client.state()); 296 | Serial.println(" try again in 2 seconds"); 297 | // Wait 2 seconds before retrying 298 | delay(2000); 299 | digitalWrite(Buzzer, HIGH); 300 | delay(200); 301 | digitalWrite(Buzzer, LOW); 302 | delay(50); 303 | digitalWrite(Buzzer, HIGH); 304 | delay(200); 305 | digitalWrite(Buzzer, LOW); 306 | delay(50); 307 | } 308 | } 309 | } 310 | 311 | 312 | /**************************************** 313 | Main Functions 314 | ****************************************/ 315 | 316 | void setup() { 317 | Serial.begin(115200); 318 | //pinMode(A0, INPUT); 319 | pinMode(R1, OUTPUT); 320 | pinMode(R2, OUTPUT); 321 | pinMode(R3, OUTPUT); 322 | pinMode(R4, OUTPUT); 323 | pinMode(R5, OUTPUT); 324 | pinMode(R6, OUTPUT); 325 | pinMode(R7, OUTPUT); 326 | pinMode(R8, OUTPUT); 327 | pinMode(R9, OUTPUT); 328 | pinMode(R10, OUTPUT); 329 | pinMode(R11, OUTPUT); 330 | pinMode(R12, OUTPUT); 331 | pinMode(R13, OUTPUT); 332 | pinMode(R14, OUTPUT); 333 | pinMode(R15, OUTPUT); 334 | pinMode(R16, OUTPUT); 335 | 336 | pinMode(Buzzer, OUTPUT); 337 | 338 | WiFi.begin(WIFISSID, PASSWORD); 339 | Serial.println(); 340 | Serial.println(); 341 | Serial.print("Wait for WiFi... "); 342 | 343 | while (WiFi.status() != WL_CONNECTED) { 344 | Serial.print("."); 345 | delay(500); 346 | } 347 | 348 | Serial.println(""); 349 | Serial.println("WiFi connected"); 350 | Serial.println("IP address: "); 351 | Serial.println(WiFi.localIP()); 352 | client.setServer(mqttBroker, 1883); 353 | client.setCallback(callback); 354 | } 355 | 356 | void loop() { 357 | 358 | if (!client.connected()) { 359 | reconnect(); 360 | 361 | // Subscribes for getting the value of the control variable in the temperature-box device 362 | char topicToSubscribe_variable_1[200]; 363 | sprintf(topicToSubscribe_variable_1, "%s", ""); // Cleans the content of the char 364 | sprintf(topicToSubscribe_variable_1, "%s%s", "/v1.6/devices/", DEVICE_LABEL); 365 | sprintf(topicToSubscribe_variable_1, "%s/%s/lv", topicToSubscribe_variable_1, VARIABLE_LABEL_SUB_1); 366 | Serial.println("subscribing to topic:"); 367 | Serial.println(topicToSubscribe_variable_1); 368 | client.subscribe(topicToSubscribe_variable_1); 369 | 370 | char topicToSubscribe_variable_2[200]; 371 | sprintf(topicToSubscribe_variable_2, "%s", ""); // Cleans the content of the char 372 | sprintf(topicToSubscribe_variable_2, "%s%s", "/v1.6/devices/", DEVICE_LABEL); 373 | sprintf(topicToSubscribe_variable_2, "%s/%s/lv", topicToSubscribe_variable_2, VARIABLE_LABEL_SUB_2); 374 | Serial.println("subscribing to topic:"); 375 | Serial.println(topicToSubscribe_variable_2); 376 | client.subscribe(topicToSubscribe_variable_2); 377 | 378 | char topicToSubscribe_variable_3[200]; 379 | sprintf(topicToSubscribe_variable_3, "%s", ""); // Cleans the content of the char 380 | sprintf(topicToSubscribe_variable_3, "%s%s", "/v1.6/devices/", DEVICE_LABEL); 381 | sprintf(topicToSubscribe_variable_3, "%s/%s/lv", topicToSubscribe_variable_3, VARIABLE_LABEL_SUB_3); 382 | Serial.println("subscribing to topic:"); 383 | Serial.println(topicToSubscribe_variable_3); 384 | client.subscribe(topicToSubscribe_variable_3); 385 | 386 | char topicToSubscribe_variable_4[200]; 387 | sprintf(topicToSubscribe_variable_4, "%s", ""); // Cleans the content of the char 388 | sprintf(topicToSubscribe_variable_4, "%s%s", "/v1.6/devices/", DEVICE_LABEL); 389 | sprintf(topicToSubscribe_variable_4, "%s/%s/lv", topicToSubscribe_variable_4, VARIABLE_LABEL_SUB_4); 390 | Serial.println("subscribing to topic:"); 391 | Serial.println(topicToSubscribe_variable_4); 392 | client.subscribe(topicToSubscribe_variable_4); 393 | 394 | char topicToSubscribe_variable_5[200]; 395 | sprintf(topicToSubscribe_variable_5, "%s", ""); // Cleans the content of the char 396 | sprintf(topicToSubscribe_variable_5, "%s%s", "/v1.6/devices/", DEVICE_LABEL); 397 | sprintf(topicToSubscribe_variable_5, "%s/%s/lv", topicToSubscribe_variable_5, VARIABLE_LABEL_SUB_5); 398 | Serial.println("subscribing to topic:"); 399 | Serial.println(topicToSubscribe_variable_5); 400 | client.subscribe(topicToSubscribe_variable_5); 401 | 402 | char topicToSubscribe_variable_6[200]; 403 | sprintf(topicToSubscribe_variable_6, "%s", ""); // Cleans the content of the char 404 | sprintf(topicToSubscribe_variable_6, "%s%s", "/v1.6/devices/", DEVICE_LABEL); 405 | sprintf(topicToSubscribe_variable_6, "%s/%s/lv", topicToSubscribe_variable_6, VARIABLE_LABEL_SUB_6); 406 | Serial.println("subscribing to topic:"); 407 | Serial.println(topicToSubscribe_variable_6); 408 | client.subscribe(topicToSubscribe_variable_6); 409 | 410 | char topicToSubscribe_variable_7[200]; 411 | sprintf(topicToSubscribe_variable_7, "%s", ""); // Cleans the content of the char 412 | sprintf(topicToSubscribe_variable_7, "%s%s", "/v1.6/devices/", DEVICE_LABEL); 413 | sprintf(topicToSubscribe_variable_7, "%s/%s/lv", topicToSubscribe_variable_7, VARIABLE_LABEL_SUB_7); 414 | Serial.println("subscribing to topic:"); 415 | Serial.println(topicToSubscribe_variable_7); 416 | client.subscribe(topicToSubscribe_variable_7); 417 | 418 | char topicToSubscribe_variable_8[200]; 419 | sprintf(topicToSubscribe_variable_8, "%s", ""); // Cleans the content of the char 420 | sprintf(topicToSubscribe_variable_8, "%s%s", "/v1.6/devices/", DEVICE_LABEL); 421 | sprintf(topicToSubscribe_variable_8, "%s/%s/lv", topicToSubscribe_variable_8, VARIABLE_LABEL_SUB_8); 422 | Serial.println("subscribing to topic:"); 423 | Serial.println(topicToSubscribe_variable_8); 424 | client.subscribe(topicToSubscribe_variable_8); 425 | 426 | char topicToSubscribe_variable_9[200]; 427 | sprintf(topicToSubscribe_variable_9, "%s", ""); // Cleans the content of the char 428 | sprintf(topicToSubscribe_variable_9, "%s%s", "/v1.6/devices/", DEVICE_LABEL); 429 | sprintf(topicToSubscribe_variable_9, "%s/%s/lv", topicToSubscribe_variable_9, VARIABLE_LABEL_SUB_9); 430 | Serial.println("subscribing to topic:"); 431 | Serial.println(topicToSubscribe_variable_9); 432 | client.subscribe(topicToSubscribe_variable_9); 433 | 434 | char topicToSubscribe_variable_10[200]; 435 | sprintf(topicToSubscribe_variable_10, "%s", ""); // Cleans the content of the char 436 | sprintf(topicToSubscribe_variable_10, "%s%s", "/v1.6/devices/", DEVICE_LABEL); 437 | sprintf(topicToSubscribe_variable_10, "%s/%s/lv", topicToSubscribe_variable_10, VARIABLE_LABEL_SUB_10); 438 | Serial.println("subscribing to topic:"); 439 | Serial.println(topicToSubscribe_variable_10); 440 | client.subscribe(topicToSubscribe_variable_10); 441 | 442 | char topicToSubscribe_variable_11[200]; 443 | sprintf(topicToSubscribe_variable_11, "%s", ""); // Cleans the content of the char 444 | sprintf(topicToSubscribe_variable_11, "%s%s", "/v1.6/devices/", DEVICE_LABEL); 445 | sprintf(topicToSubscribe_variable_11, "%s/%s/lv", topicToSubscribe_variable_11, VARIABLE_LABEL_SUB_11); 446 | Serial.println("subscribing to topic:"); 447 | Serial.println(topicToSubscribe_variable_11); 448 | client.subscribe(topicToSubscribe_variable_11); 449 | 450 | char topicToSubscribe_variable_12[200]; 451 | sprintf(topicToSubscribe_variable_12, "%s", ""); // Cleans the content of the char 452 | sprintf(topicToSubscribe_variable_12, "%s%s", "/v1.6/devices/", DEVICE_LABEL); 453 | sprintf(topicToSubscribe_variable_12, "%s/%s/lv", topicToSubscribe_variable_12, VARIABLE_LABEL_SUB_12); 454 | Serial.println("subscribing to topic:"); 455 | Serial.println(topicToSubscribe_variable_12); 456 | client.subscribe(topicToSubscribe_variable_12); 457 | 458 | char topicToSubscribe_variable_13[200]; 459 | sprintf(topicToSubscribe_variable_13, "%s", ""); // Cleans the content of the char 460 | sprintf(topicToSubscribe_variable_13, "%s%s", "/v1.6/devices/", DEVICE_LABEL); 461 | sprintf(topicToSubscribe_variable_13, "%s/%s/lv", topicToSubscribe_variable_13, VARIABLE_LABEL_SUB_13); 462 | Serial.println("subscribing to topic:"); 463 | Serial.println(topicToSubscribe_variable_13); 464 | client.subscribe(topicToSubscribe_variable_13); 465 | 466 | char topicToSubscribe_variable_14[200]; 467 | sprintf(topicToSubscribe_variable_14, "%s", ""); // Cleans the content of the char 468 | sprintf(topicToSubscribe_variable_14, "%s%s", "/v1.6/devices/", DEVICE_LABEL); 469 | sprintf(topicToSubscribe_variable_14, "%s/%s/lv", topicToSubscribe_variable_14, VARIABLE_LABEL_SUB_14); 470 | Serial.println("subscribing to topic:"); 471 | Serial.println(topicToSubscribe_variable_14); 472 | client.subscribe(topicToSubscribe_variable_14); 473 | 474 | char topicToSubscribe_variable_15[200]; 475 | sprintf(topicToSubscribe_variable_15, "%s", ""); // Cleans the content of the char 476 | sprintf(topicToSubscribe_variable_15, "%s%s", "/v1.6/devices/", DEVICE_LABEL); 477 | sprintf(topicToSubscribe_variable_15, "%s/%s/lv", topicToSubscribe_variable_15, VARIABLE_LABEL_SUB_15); 478 | Serial.println("subscribing to topic:"); 479 | Serial.println(topicToSubscribe_variable_15); 480 | client.subscribe(topicToSubscribe_variable_15); 481 | 482 | char topicToSubscribe_variable_16[200]; 483 | sprintf(topicToSubscribe_variable_16, "%s", ""); // Cleans the content of the char 484 | sprintf(topicToSubscribe_variable_16, "%s%s", "/v1.6/devices/", DEVICE_LABEL); 485 | sprintf(topicToSubscribe_variable_16, "%s/%s/lv", topicToSubscribe_variable_16, VARIABLE_LABEL_SUB_16); 486 | Serial.println("subscribing to topic:"); 487 | Serial.println(topicToSubscribe_variable_16); 488 | client.subscribe(topicToSubscribe_variable_16); 489 | } 490 | /* 491 | char payload_publish[100]; 492 | char topicToPublish[200]; 493 | 494 | float sensor_1 = 15; // Fix value. Modify it with the sensor reading 495 | float sensor_2 = 25; // Fix value. Modify it with the sensor reading 496 | 497 | // 4 is mininum width, 2 is precision; float value is copied onto str_sensor 498 | dtostrf(sensor_1, 4, 2, str_sensor1); 499 | dtostrf(sensor_2, 4, 2, str_sensor2); 500 | 501 | sprintf(topicToPublish, "%s", ""); // Cleans the content of the char 502 | sprintf(topicToPublish, "%s%s", "/v1.6/devices/", DEVICE_LABEL); 503 | sprintf(payload_publish, "{\"%s\":%s", VARIABLE_LABEL_PUB_1, str_sensor1); // Adds the variable label 504 | sprintf(payload_publish, "%s,\"%s\":%s}", payload_publish, VARIABLE_LABEL_PUB_2, str_sensor2); // Adds the variable label 505 | Serial.println("publishing to topic:"); 506 | Serial.println(topicToPublish); 507 | Serial.println("Payload published:"); 508 | Serial.println(payload_publish); 509 | client.publish(topicToPublish, payload_publish); 510 | */ 511 | client.loop(); 512 | delay(1); 513 | } 514 | --------------------------------------------------------------------------------