Compare commits

...

5 Commits

Author SHA1 Message Date
fbd139996e Update display.ino
IR weer werkend voor Wemos D1 Mini
2022-03-12 20:25:23 +01:00
8a051e1fd3 Update Json.ino 2022-03-07 09:34:57 +01:00
6bd01e7396 Update display.ino
Ook de tone was al uitgezet ivm ESP32 migratie
2022-03-06 14:39:09 +01:00
14ecb076bd Update display.ino
Nextion baudrate en portsettings SoftwareSerial terug gezet want die waren al aangepast voor de ESP32 !!
En MQTT server IP adres is aangepast
2022-03-06 11:43:29 +01:00
bdcf70d1bf Oude files weg 2022-01-10 17:16:44 +01:00
7 changed files with 32 additions and 690 deletions

View File

@ -315,7 +315,7 @@ void mqtt_callback(char* topic, byte* payload, unsigned int length) {
//delay(200);
for (int i = 0; i < 10; i++)
{
// tone(BUZZER_PIN, 1000, 200);
tone(BUZZER_PIN, 1000, 200);
delay(500);
}
sendCommand("vis pic_doorbell,0");

View File

@ -1,38 +1,55 @@
/*
Display Domoticz
Device : LOLIN (WEMOS) D1 mini (clone)
Nextion display is connected to D5 en D6
in NexHardware.cpp moet de volgende regels staan :
#include "SoftwareSerial.h" //FvEs deze uit als ESP32 gebruikt wordt
//Wemos
SoftwareSerial nexSerial(D5, D6); // RX, TX
*/
//#define DEBUG 1 //Uit quoten om debug messages te krijgen
//#include <WiFi.h>
#include <WiFi.h>
//#include <ESP8266WiFi.h>
#include <ESP8266WiFi.h>
//#include <ESP8266HTTPClient.h>
#include <PubSubClient.h>
#include <ArduinoJson.h>
#include <Nextion.h>
//SoftwareSerial HMISerial(D5,D6);
#include <X10ir.h>
//#define BUZZER_PIN D5
//#define BUZZER_PIN D7
#define BUZZER_PIN 5
#define BUZZER_PIN D7
//#define BUZZER_PIN 5
// X10 Infrared Receiver Library
void infraredEvent(char house, byte unit, byte command, bool isRepeat);
X10ir x10ir = X10ir(
4, // Receive Interrupt Number (1 = Standard Arduino External Interrupt)
4, // Receive Interrupt Pin (Pin 3 must be used with interrupt 1)
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 * !!!!
);
//WIFI config
const char* ssid = "FrankHilde";
const char* password = "HildeFrank";
const char* mqtt_server = "192.168.2.200";
//MQTT config
const char* mqtt_server = "192.168.2.153";
const char* mqtt_user = "domoticz";
const char* mqtt_pwd = "MQTT&Domoticz";
WiFiClient espClient;
PubSubClient client(espClient);
@ -196,7 +213,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
@ -259,7 +280,7 @@ void loop() {
if(alarm_sound == 1)
{
// tone(BUZZER_PIN, 1000, 50);
tone(BUZZER_PIN, 1000, 50);
delay(1000);
}

View File

@ -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<JsonObject>();
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<JsonObject>();
root["command"] = "setuservariable";
root["idx"] = 4;
root["value"] = pagenr;
serializeJson(root, msg);
#ifdef DEBUG
Serial.println(msg);
#endif
client.publish("domoticz/in", msg);
}

64
IR.ino
View File

@ -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);
}
}
}
}

226
Json.ino
View File

@ -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<JsonObject>();
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;
}
}
}

View File

@ -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);
}
}

View File

@ -1,222 +0,0 @@
//#define DEBUG 1
#include <ESP8266WiFi.h>
//#include <ESP8266HTTPClient.h>
#include <PubSubClient.h>
#include <ArduinoJson.h>
#include <Nextion.h>
#include <X10ir.h>
#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;
}
}