//MQTT receive void mqtt_callback(char* topic, byte* payload, unsigned int length) { int svalue1, loc, StepperTarget; String sub, devicename; StaticJsonDocument<256> doc; sendCommand("p0.pic=55"); sendCommand("tm1.en=1"); #ifdef DEBUG Serial.print("Message arrived ["); Serial.print(topic); Serial.print("] "); for (int i = 0; i < length; i++) { Serial.print((char)payload[i]); } Serial.println(); #endif // Deserialize the JSON document DeserializationError error = deserializeJson(doc, payload); // Test if parsing succeeds. if (error) { #ifdef DEBUG Serial.print(F("deserializeJson() failed: ")); Serial.println(error.c_str()); #endif return; } //Show Status WIFI icon sendCommand("p0.pic=55"); // Get the root object in the document JsonObject root = doc.as(); int idx = root["idx"]; const char* idx_name = root["name"]; const char* idx_svalue1 = root["svalue1"]; const char* idx_svalue2 = root["svalue2"]; const char* idx_svalue4 = root["svalue4"]; int idx_nvalue = root["nvalue"]; #ifdef DEBUG Serial.println(idx); Serial.println(idx_name); Serial.println(idx_svalue1); Serial.println(idx_nvalue); #endif if (idx == idx_staandelamp) { if (root["nvalue"] >= 1) main_btn_staandelamp = 1; else main_btn_staandelamp = 0; btn_2.setValue(main_btn_staandelamp); } if (idx == idx_tuinverlichting) { if (root["nvalue"] >= 1) main_btn_tuinverlichting = 1; else main_btn_tuinverlichting = 0; btn_4.setValue(main_btn_tuinverlichting); } if (idx == idx_hanglamp) { if (root["nvalue"] >= 1) main_btn_hanglamp = 1; else main_btn_hanglamp = 0; btn_1.setValue(main_btn_hanglamp); } if (idx == idx_haardverlichting) { if (root["nvalue"] >= 1) main_btn_haardverlichting = 1; else main_btn_haardverlichting = 0; btn_3.setValue(main_btn_haardverlichting); } if (idx == idx_rooster) { if (root["nvalue"] == 1) main_btn_rooster = 1; else main_btn_rooster = 0; // btn_x.setValue(main_btn_rooster); } //Tijd if (idx == idx_datumtijd) { #ifdef DEBUG // Serial.println(root["svalue1"]); #endif // memcpy(datumtijd,root["svalue1"]) datumtijd = root["svalue1"]; //datumtijd[10] = '\0'; // txt_header.setText(datumtijd); nextion_send(nex_datumtijd, datumtijd); // txt_1_header.setText(idx_svalue1); } //Weer if (idx == idx_weer_text) { weer_text = root["svalue1"]; nextion_send(nex_weer_text, weer_text); } if (idx == idx_netatmo_woonkamer) { main_temp_in = atof(root["svalue1"]); main_hum_in = atof(root["svalue2"]); main_baro = atof(root["svalue4"]); nex_send_float(nex_temp_in, main_temp_in, 4, 1); nex_send_float(nex_hum_in, main_hum_in, 2, 0); nex_send_float(nex_baro, main_baro, 4, 0); } //Min temperatuur if (idx == idx_temp_min) { main_temp_min = atof(root["svalue1"]); nex_send_float(nex_temp_min, main_temp_min, 4, 1); } //Max Temperatuur if (idx == idx_temp_max) { main_temp_max = atof(root["svalue1"]); nex_send_float(nex_temp_max, main_temp_max, 4, 1); } //Rain if (idx == idx_netatmo_regen) { main_rain = atof(root["svalue1"]); main_rain_hour = atof(root["svalue2"]); nex_send_float(nex_rain, main_rain, 3, 1); nex_send_float(nex_rain_hour, main_rain_hour, 3, 1); } if (idx == idx_netatmo_buiten) { main_temp_out = atof(root["svalue1"]); main_hum_out = atof(root["svalue2"]); nex_send_float(nex_temp_out, main_temp_out, 4, 1); nex_send_float(nex_hum_out, main_hum_out, 2, 0); } //Set weer icoon if (idx == idx_weer_icon) { main_pic_weer = root["nvalue"]; pic_weer.setPic(main_pic_weer); } if (idx == idx_deurbel) { if (idx_nvalue == 1) { #ifdef DEBUG Serial.println("Show doorbell"); #endif sendCommand("pic_doorbell.pic=52"); sendCommand("vis pic_doorbell,1"); //delay(200); for (int i = 0; i < 10; i++) { tone(BUZZER_PIN, 1000, 200); delay(500); } sendCommand("vis pic_doorbell,0"); } } //Show Deurbel stil icon if (idx == idx_deurbelstil) { if (idx_nvalue == 1) sendCommand("p1.pic=56"); else sendCommand("p1.pic=53"); } //Show Alarm if(idx == idx_alarm) { if (idx_nvalue == 1) { #ifdef DEBUG Serial.println("Show Alarm"); #endif sendCommand("pic_doorbell.pic=58"); sendCommand("vis pic_doorbell,1"); alarm_sound = 1; } else { #ifdef DEBUG Serial.println("Hide Alarm"); #endif sendCommand("vis pic_doorbell,0"); sendCommand("pic_doorbell.pic=52"); alarm_sound = 0; } } }