From bdcf70d1bfd05a2944b71c85296b658bbd9a0bff Mon Sep 17 00:00:00 2001 From: Frank Date: Mon, 10 Jan 2022 17:16:44 +0100 Subject: [PATCH] Oude files weg --- Arduino/display/display.ino | 9 +- Domoticz.ino | 55 --------- IR.ino | 64 ---------- Json.ino | 226 ------------------------------------ Nextion.ino | 112 ------------------ display.ino | 222 ----------------------------------- 6 files changed, 7 insertions(+), 681 deletions(-) delete mode 100644 Domoticz.ino delete mode 100644 IR.ino delete mode 100644 Json.ino delete mode 100644 Nextion.ino delete mode 100644 display.ino diff --git a/Arduino/display/display.ino b/Arduino/display/display.ino index a76981e..6d212dd 100644 --- a/Arduino/display/display.ino +++ b/Arduino/display/display.ino @@ -1,7 +1,6 @@ //#define DEBUG 1 //Uit quoten om debug messages te krijgen - #include //#include @@ -33,6 +32,8 @@ X10ir x10ir = X10ir( const char* ssid = "FrankHilde"; const char* password = "HildeFrank"; const char* mqtt_server = "192.168.2.200"; +const char* mqtt_user = "mqtt-display"; +const char* mqtt_pwd = "@MQTT4Display"; WiFiClient espClient; PubSubClient client(espClient); @@ -196,7 +197,11 @@ void reconnect() { String clientId = "ESP8266Client-"; clientId += String(random(0xffff), HEX); // Attempt to connect - if (client.connect(clientId.c_str())) { + + + //if (client.connect(clientId.c_str())) { + //changed mqtt authentication + if (client.connect(clientId.c_str(),mqtt_user,mqtt__pwd)) { #ifdef DEBUG Serial.println("connected"); #endif diff --git a/Domoticz.ino b/Domoticz.ino deleted file mode 100644 index 4cd4082..0000000 --- a/Domoticz.ino +++ /dev/null @@ -1,55 +0,0 @@ - -void domoticz_send_nvalue(int idx, int nvalue) -{ - StaticJsonDocument<200> doc; - -#ifdef DEBUG - Serial.println("Sending nvalue"); - Serial.println(idx); - Serial.println(nvalue); -#endif - - // Make our document be an object - JsonObject root = doc.to(); - - root["command"] = "switchlight"; - root["idx"] = idx; - if (nvalue == 1) - { - root["switchcmd"] = "On"; - } - else - { - root["switchcmd"] = "Off"; - } - serializeJson(root, msg); -#ifdef DEBUG - Serial.println(msg); -#endif - client.publish("domoticz/in", msg); -} - -//Setting page nummer into Domoticz varaiable -void domoticz_set_pagenr(int pagenr) -{ - StaticJsonDocument<200> doc; - -#ifdef DEBUG - Serial.println("Sending variable pagenr"); - Serial.println(pagenr); -#endif - - // Make our document be an object - JsonObject root = doc.to(); - - root["command"] = "setuservariable"; - root["idx"] = 4; - root["value"] = pagenr; - - serializeJson(root, msg); - -#ifdef DEBUG - Serial.println(msg); -#endif - client.publish("domoticz/in", msg); -} diff --git a/IR.ino b/IR.ino deleted file mode 100644 index 351058c..0000000 --- a/IR.ino +++ /dev/null @@ -1,64 +0,0 @@ - -// Process commands received from X10 compatible IR remote -void infraredEvent(char house, byte unit, byte command, bool isRepeat) -{ - - //Show Status IR icon - sendCommand("p0.pic=54"); - sendCommand("tm1.en=1"); - -#ifdef DEBUG - Serial.println("!! IR Received !!"); -#endif - if (!isRepeat) - { -#ifdef DEBUG - Serial.println(command); -#endif - // Handle Address Command (House + Unit) - if (command == CMD_ADDRESS) - { -#ifdef DEBUG - Serial.println("cmd == CMD_ADDRESS"); - Serial.println(house); - Serial.println(unit); - Serial.println(command); -#endif - if (unit <= 16) - { -#ifdef DEBUG - Serial.println("Switch..."); -#endif - if (unit == 1) //Staandelamp - if(main_btn_staandelamp==0) - domoticz_send_nvalue(idx_staandelamp, 1); - else - domoticz_send_nvalue(idx_staandelamp, 0); - - if (unit == 2) //Haard - if(main_btn_haardverlichting==0) - domoticz_send_nvalue(idx_haardverlichting, 1); - else - domoticz_send_nvalue(idx_haardverlichting, 0); - - if (unit == 4) //Rooster - if(main_btn_rooster==0) - domoticz_send_nvalue(idx_rooster, 1); - else - domoticz_send_nvalue(idx_rooster, 0); - - if (unit == 5) //Hanglamp - if(main_btn_hanglamp==0) - domoticz_send_nvalue(idx_hanglamp, 1); - else - domoticz_send_nvalue(idx_hanglamp, 0); - - if (unit == 3) //Tuin - if(main_btn_tuinverlichting==0) - domoticz_send_nvalue(idx_tuinverlichting, 1); - else - domoticz_send_nvalue(idx_tuinverlichting, 0); - } - } - } -} diff --git a/Json.ino b/Json.ino deleted file mode 100644 index 0b42fee..0000000 --- a/Json.ino +++ /dev/null @@ -1,226 +0,0 @@ -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; - } - } -} diff --git a/Nextion.ino b/Nextion.ino deleted file mode 100644 index 69cfcbf..0000000 --- a/Nextion.ino +++ /dev/null @@ -1,112 +0,0 @@ -void nextion_send(const char* idx, const char* val) -{ - char buf[50]; - - char* part1 = "=\""; - char* part2 = "\""; - - strcpy(buf, idx); - strcpy(buf + strlen(idx), part1); - strcpy(buf + strlen(idx) + strlen(part1), val); - strcpy(buf + strlen(idx) + strlen(part1) + strlen(val), part2); -#ifdef DEBUG - Serial.println(buf); -#endif - sendCommand(buf); -} - - -void nex_send_float(const char* idx, float val, int len, int dec) -{ - char buf[50]; - - char result[8]; // Buffer big enough for 7-character float - dtostrf(val, len, dec, result); // Leave room for too large numbers! - - char* part1 = "=\""; - char* part2 = "\""; - - strcpy(buf, idx); - strcpy(buf + strlen(idx), part1); - strcpy(buf + strlen(idx) + strlen(part1), result); - strcpy(buf + strlen(idx) + strlen(part1) + strlen(result), part2); -#ifdef DEBUG - Serial.println(buf); -#endif - sendCommand(buf); -} - - -void btn_1_PopCallback(void *ptr) -{ - uint32_t dual_state; - - btn_1.getValue(&dual_state); - if (dual_state) - main_btn_hanglamp = 1; - else - main_btn_hanglamp = 0; - - domoticz_send_nvalue(idx_hanglamp, main_btn_hanglamp); -} - - -void btn_2_PopCallback(void *ptr) -{ - uint32_t dual_state; - - btn_2.getValue(&dual_state); - if (dual_state) - main_btn_staandelamp = 1; - else - main_btn_staandelamp = 0; - - domoticz_send_nvalue(idx_staandelamp, main_btn_staandelamp); -} - - -void btn_3_PopCallback(void *ptr) -{ - uint32_t dual_state; - - /* Get the state value of dual state button component . */ - btn_3.getValue(&dual_state); - if (dual_state) - main_btn_haardverlichting = 1; - else - main_btn_haardverlichting = 0; - - domoticz_send_nvalue(idx_haardverlichting, main_btn_haardverlichting); -} - - -void btn_4_PopCallback(void *ptr) -{ - uint32_t dual_state; - - /* Get the state value of dual state button component . */ - btn_4.getValue(&dual_state); - if (dual_state) - main_btn_tuinverlichting = 1; - else - main_btn_tuinverlichting = 0; - - domoticz_send_nvalue(idx_tuinverlichting, main_btn_tuinverlichting); -} - - -void btn_5_PopCallback(void *ptr) -{ - uint32_t dual_state; - - /* Get the state value of dual state button component . */ - btn_5.getValue(&dual_state); - if (dual_state) - { - domoticz_send_nvalue(idx_rooster, 1); - } - else - { - domoticz_send_nvalue(idx_rooster, 0); - } -} diff --git a/display.ino b/display.ino deleted file mode 100644 index e9221d6..0000000 --- a/display.ino +++ /dev/null @@ -1,222 +0,0 @@ - -//#define DEBUG 1 - -#include - -//#include -#include -#include -#include - -#include - -#define BUZZER_PIN D5 - -// X10 Infrared Receiver Library -void infraredEvent(char house, byte unit, byte command, bool isRepeat); - -X10ir x10ir = X10ir( - 5, // Receive Interrupt Number (1 = Standard Arduino External Interrupt) - 5, // Receive Interrupt Pin (Pin 3 must be used with interrupt 1) - 'A', // Default House Code - // *infraredEvent // Event triggered when IR message is received - infraredEvent // Event triggered when IR message is received . //In example zonder * !!!! - ); - -const char* ssid = "FrankHilde"; -const char* password = "HildeFrank"; -const char* mqtt_server = "192.168.2.200"; - -WiFiClient espClient; -PubSubClient client(espClient); -long lastMsg = 0; -char msg[100]; -int value = 0; - -#define idx_staandelamp 1701 //1714 //1701 //1252 -#define idx_hanglamp 1695 //1716 //1695 //1326 -#define idx_haardverlichting 1702 //1717 //1702 //628 -#define idx_tuinverlichting 695 //1715 //695 -#define idx_rooster 148 -#define idx_deurbel 906 -#define idx_deurbelstil 917 -#define idx_deurbelstil4 1268 -#define idx_alarm 1565 - -#define idx_datumtijd 1513 -#define idx_netatmo_woonkamer 450 -#define idx_netatmo_buiten 453 -#define idx_netatmo_regen 1564 -#define idx_weer_icon 1522 -#define idx_temp_min 1562 -#define idx_temp_max 1563 -#define idx_weer_text 1459 - -//Define Nextion elements -#define nex_datumtijd "txt_header.txt" -#define nex_temp_in "txt_temp_in.txt" -#define nex_hum_in "t0.txt" -#define nex_temp_out "txt_temp_out.txt" -#define nex_hum_out "t1.txt" -#define nex_temp_min "t10.txt" -#define nex_temp_max "t11.txt" -#define nex_baro "t2.txt" -#define nex_rain "t3.txt" -#define nex_rain_hour "t4.txt" -#define nex_weer_text "txt_weer.txt" - -//NexText txt_header = NexText(0, 14, "txt_header"); -//NexText txt_weer = NexText(0, 12, "txt_weer"); - -NexPicture pic_weer = NexPicture(0, 13, "pic_weer"); - -NexDSButton btn_1 = NexDSButton(0, 5, "btn_1"); -NexDSButton btn_2 = NexDSButton(0, 3, "btn_2"); -NexDSButton btn_3 = NexDSButton(0, 4, "btn_3"); -NexDSButton btn_4 = NexDSButton(0, 6, "btn_4"); -NexDSButton btn_5 = NexDSButton(0, 7, "btn_5"); - -char buffer[100] = {0}; - -//global veriables -//Page main -const char* datumtijd; -const char* weer_text; -int main_btn_staandelamp = 0; -int main_btn_tuinverlichting = 0; -int main_btn_hanglamp = 0; -int main_btn_haardverlichting = 0; -int main_btn_rooster = 1; -int main_btn_deurbelstil = 0; - -int alarm_sound = 0; - -int main_pic_weer; -float main_temp_in = 0; -float main_hum_in = 0; -float main_baro = 0; - -float main_temp_out = 0; -float main_hum_out = 0; -float main_temp_min = 0; -float main_temp_max = 0; - -float main_rain = 0; -float main_rain_hour = 0; - -NexTouch *nex_listen_list[] = -{ - &btn_1, &btn_2, &btn_3, &btn_4, &btn_5, - NULL -}; - -void setup_wifi() { - - delay(10); - // We start by connecting to a WiFi network -#ifdef DEBUG - Serial.println(); - Serial.print("Connecting to "); - Serial.println(ssid); -#endif - - WiFi.begin(ssid, password); - - while (WiFi.status() != WL_CONNECTED) - { - delay(500); -#ifdef DEBUG - Serial.print("."); -#endif - } - - randomSeed(micros()); - -#ifdef DEBUG - Serial.println(""); - Serial.println("WiFi connected"); - Serial.println("IP address: "); - Serial.println(WiFi.localIP()); -#endif -} - -void reconnect() { - // Loop until we're reconnected - while (!client.connected()) { -#ifdef DEBUG - Serial.print("Attempting MQTT connection..."); -#endif - // Create a random client ID - String clientId = "ESP8266Client-"; - clientId += String(random(0xffff), HEX); - // Attempt to connect - if (client.connect(clientId.c_str())) { -#ifdef DEBUG - Serial.println("connected"); -#endif - // Once connected, publish an announcement... - client.publish("outTopic", "hello world"); - // ... and resubscribe - client.subscribe("domoticz/out/example/display"); - } else { -#ifdef DEBUG - Serial.print("failed, rc="); - Serial.print(client.state()); - Serial.println(" try again in 5 seconds"); -#endif - // Wait 5 seconds before retrying - delay(5000); - } - } -} - -void setup() { - - pinMode(BUZZER_PIN, OUTPUT); - digitalWrite(BUZZER_PIN, 0); - - pinMode(BUILTIN_LED, OUTPUT); // Initialize the BUILTIN_LED pin as an output - -#ifdef DEBUG - Serial.begin(115200); -#endif - setup_wifi(); - client.setServer(mqtt_server, 1883); - client.setCallback(mqtt_callback); - - nexInit(); - /* Register the pop event callback function of the dual state button component. */ - btn_1.attachPop(btn_1_PopCallback, &btn_1); - btn_2.attachPop(btn_2_PopCallback, &btn_2); - btn_3.attachPop(btn_3_PopCallback, &btn_3); - btn_4.attachPop(btn_4_PopCallback, &btn_4); - btn_5.attachPop(btn_5_PopCallback, &btn_5); - - //X10 IR Receiver - x10ir.begin(); -} - -void loop() { - - nexLoop(nex_listen_list); - - if (!client.connected()) - { - reconnect(); - } - - client.loop(); - - if(alarm_sound == 1) - { - tone(BUZZER_PIN, 1000, 50); - delay(1000); - } - - long now = millis(); - if (now - lastMsg > 20000) - { - lastMsg = now; - ++value; - } -}