First version
First version
1
Arduino/.svn/entries
Normal file
@ -0,0 +1 @@
|
||||
12
|
||||
1
Arduino/.svn/format
Normal file
@ -0,0 +1 @@
|
||||
12
|
||||
@ -0,0 +1,112 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,224 @@
|
||||
|
||||
//#define DEBUG 1 //Uit quoten om debug messages te krijgen
|
||||
|
||||
#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_kaarsen 1845
|
||||
#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_kaarsen = 0;
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,261 @@
|
||||
|
||||
//#define DEBUG 1 //Uit quoten om debug messages te krijgen
|
||||
|
||||
#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[250];
|
||||
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_kaarsen 1845
|
||||
*/
|
||||
int idx_staandelamp = 1701; //1714 //1701 //1252
|
||||
int idx_haardverlichting = 1702; //1717 //1702 //628
|
||||
int idx_tuinverlichting = 695; //1715 //695
|
||||
int idx_rooster = 148;
|
||||
int idx_hanglamp = 1695; //1716 //1695 //1326
|
||||
int idx_ir06 = 1845;
|
||||
int idx_ir07 = 0;
|
||||
int idx_ir08 = 0;
|
||||
int idx_ir09 = 0;
|
||||
int idx_ir10 = 0;
|
||||
int idx_ir11 = 0;
|
||||
int idx_ir12 = 0;
|
||||
int idx_ir13 = 0;
|
||||
int idx_ir14 = 0;
|
||||
int idx_ir15 = 0;
|
||||
int idx_ir16 = 0;
|
||||
|
||||
|
||||
#define idx_init 1984
|
||||
#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[250] = {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_kaarsen = 0;
|
||||
int main_btn_deurbelstil = 0;
|
||||
|
||||
int main_btn_ir06 = 0;
|
||||
int main_btn_ir07 = 0;
|
||||
int main_btn_ir08 = 0;
|
||||
int main_btn_ir09 = 0;
|
||||
int main_btn_ir10 = 0;
|
||||
int main_btn_ir11 = 0;
|
||||
int main_btn_ir12 = 0;
|
||||
int main_btn_ir13 = 0;
|
||||
int main_btn_ir14 = 0;
|
||||
int main_btn_ir15 = 0;
|
||||
int main_btn_ir16 = 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);
|
||||
}
|
||||
}
|
||||
|
||||
//display init
|
||||
domoticz_send_nvalue(idx_init, 1);
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,224 @@
|
||||
|
||||
//#define DEBUG 1 //Uit quoten om debug messages te krijgen
|
||||
|
||||
#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[250];
|
||||
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_kaarsen 1845
|
||||
#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[250] = {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_kaarsen = 0;
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,71 @@
|
||||
|
||||
// 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);
|
||||
|
||||
if (unit == 6) //Kaarsen
|
||||
if(main_btn_kaarsen==0)
|
||||
domoticz_send_nvalue(idx_kaarsen, 1);
|
||||
else
|
||||
domoticz_send_nvalue(idx_kaarsen, 0);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,245 @@
|
||||
//MQTT receive
|
||||
void mqtt_callback(char* topic, byte* payload, unsigned int length) {
|
||||
int svalue1, loc, StepperTarget;
|
||||
String sub, devicename;
|
||||
|
||||
StaticJsonDocument<512> 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);
|
||||
}
|
||||
|
||||
if (idx == idx_kaarsen)
|
||||
{
|
||||
if (root["nvalue"] >= 1)
|
||||
main_btn_kaarsen = 1;
|
||||
else
|
||||
main_btn_kaarsen = 0;
|
||||
|
||||
// btn_1.setValue(main_btn_kaarsen);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//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)
|
||||
{
|
||||
|
||||
#ifdef DEBUG
|
||||
Serial.print("!!!! idx 459 !!! ");
|
||||
#endif
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,345 @@
|
||||
//MQTT receive
|
||||
void mqtt_callback(char* topic, byte* payload, unsigned int length) {
|
||||
int svalue1, loc, StepperTarget;
|
||||
String sub, devicename;
|
||||
|
||||
StaticJsonDocument<512> 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
|
||||
|
||||
|
||||
//Get IDX IR config
|
||||
if (idx == -1)
|
||||
{
|
||||
idx_staandelamp = root["svalue1"];
|
||||
idx_haardverlichting = root["svalue2"];
|
||||
idx_tuinverlichting = root["svalue3"];
|
||||
idx_rooster = root["svalue4"];
|
||||
idx_hanglamp = root["svalue5"];
|
||||
idx_ir06 = root["svalue6"];
|
||||
idx_ir07 = root["svalue7"];
|
||||
idx_ir08 = root["svalue8"];
|
||||
idx_ir09 = root["svalue9"];
|
||||
idx_ir10 = root["svalue10"];
|
||||
idx_ir11 = root["svalue11"];
|
||||
idx_ir12 = root["svalue12"];
|
||||
idx_ir13 = root["svalue13"];
|
||||
idx_ir14 = root["svalue14"];
|
||||
idx_ir15 = root["svalue15"];
|
||||
idx_ir16 = root["svalue16"];
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
if (idx == idx_ir06)
|
||||
{
|
||||
if (root["nvalue"] >= 1)
|
||||
main_btn_ir06 = 1;
|
||||
else
|
||||
main_btn_ir06 = 0;
|
||||
|
||||
// btn_1.setValue(main_btn_kaarsen);
|
||||
}
|
||||
|
||||
if (idx == idx_ir07)
|
||||
{
|
||||
if (root["nvalue"] >= 1)
|
||||
main_btn_ir07 = 1;
|
||||
else
|
||||
main_btn_ir07 = 0;
|
||||
}
|
||||
|
||||
if (idx == idx_ir08)
|
||||
{
|
||||
if (root["nvalue"] >= 1)
|
||||
main_btn_ir08 = 1;
|
||||
else
|
||||
main_btn_ir08 = 0;
|
||||
}
|
||||
|
||||
if (idx == idx_ir09)
|
||||
{
|
||||
if (root["nvalue"] >= 1)
|
||||
main_btn_ir09 = 1;
|
||||
else
|
||||
main_btn_ir09 = 0;
|
||||
}
|
||||
|
||||
if (idx == idx_ir10)
|
||||
{
|
||||
if (root["nvalue"] >= 1)
|
||||
main_btn_ir10 = 1;
|
||||
else
|
||||
main_btn_ir10 = 0;
|
||||
}
|
||||
|
||||
if (idx == idx_ir11)
|
||||
{
|
||||
if (root["nvalue"] >= 1)
|
||||
main_btn_ir11 = 1;
|
||||
else
|
||||
main_btn_ir11 = 0;
|
||||
}
|
||||
|
||||
if (idx == idx_ir12)
|
||||
{
|
||||
if (root["nvalue"] >= 1)
|
||||
main_btn_ir12 = 1;
|
||||
else
|
||||
main_btn_ir12 = 0;
|
||||
}
|
||||
|
||||
if (idx == idx_ir13)
|
||||
{
|
||||
if (root["nvalue"] >= 1)
|
||||
main_btn_ir13 = 1;
|
||||
else
|
||||
main_btn_ir13 = 0;
|
||||
}
|
||||
|
||||
if (idx == idx_ir14)
|
||||
{
|
||||
if (root["nvalue"] >= 1)
|
||||
main_btn_ir14 = 1;
|
||||
else
|
||||
main_btn_ir14 = 0;
|
||||
}
|
||||
|
||||
if (idx == idx_ir15)
|
||||
{
|
||||
if (root["nvalue"] >= 1)
|
||||
main_btn_ir15 = 1;
|
||||
else
|
||||
main_btn_ir15 = 0;
|
||||
}
|
||||
|
||||
if (idx == idx_ir16)
|
||||
{
|
||||
if (root["nvalue"] >= 1)
|
||||
main_btn_ir16 = 1;
|
||||
else
|
||||
main_btn_ir16 = 0;
|
||||
}
|
||||
|
||||
//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)
|
||||
{
|
||||
|
||||
#ifdef DEBUG
|
||||
Serial.print("!!!! idx 459 !!! ");
|
||||
#endif
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,239 @@
|
||||
//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<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);
|
||||
}
|
||||
|
||||
if (idx == idx_kaarsen)
|
||||
{
|
||||
if (root["nvalue"] >= 1)
|
||||
main_btn_kaarsen = 1;
|
||||
else
|
||||
main_btn_kaarsen = 0;
|
||||
|
||||
// btn_1.setValue(main_btn_kaarsen);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,95 @@
|
||||
|
||||
// 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);
|
||||
|
||||
if (unit == 6) //Kaarsen
|
||||
if(main_btn_ir06==0)
|
||||
domoticz_send_nvalue(idx_ir06, 1);
|
||||
else
|
||||
domoticz_send_nvalue(idx_ir06, 0);
|
||||
|
||||
if (unit == 7)
|
||||
if(main_btn_ir07 == 0)
|
||||
domoticz_send_nvalue(idx_ir07, 1);
|
||||
else
|
||||
domoticz_send_nvalue(idx_ir07, 0);
|
||||
|
||||
if (unit == 8)
|
||||
if(main_btn_ir08 == 0)
|
||||
domoticz_send_nvalue(idx_ir08, 1);
|
||||
else
|
||||
domoticz_send_nvalue(idx_ir08, 0);
|
||||
|
||||
if (unit == 9)
|
||||
if(main_btn_ir09 == 0)
|
||||
domoticz_send_nvalue(idx_ir09, 1);
|
||||
else
|
||||
domoticz_send_nvalue(idx_ir09, 0);
|
||||
|
||||
if (unit == 10)
|
||||
if(main_btn_ir10 == 0)
|
||||
domoticz_send_nvalue(idx_ir10, 1);
|
||||
else
|
||||
domoticz_send_nvalue(idx_ir10, 0);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,227 @@
|
||||
//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<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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,55 @@
|
||||
|
||||
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);
|
||||
}
|
||||
@ -0,0 +1,64 @@
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,222 @@
|
||||
|
||||
//#define DEBUG 1 //Uit quoten om debug messages te krijgen
|
||||
|
||||
#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;
|
||||
}
|
||||
}
|
||||
BIN
Arduino/.svn/wc.db
Normal file
0
Arduino/.svn/wc.db-journal
Normal file
55
Arduino/display/Domoticz.ino
Normal file
@ -0,0 +1,55 @@
|
||||
|
||||
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);
|
||||
}
|
||||
115
Arduino/display/IR.ino
Normal file
@ -0,0 +1,115 @@
|
||||
|
||||
// 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
|
||||
ir_code = unit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ir_action()
|
||||
{
|
||||
|
||||
#ifdef DEBUG
|
||||
Serial.println("Ir_code == ");
|
||||
Serial.println(ir_code);
|
||||
#endif
|
||||
|
||||
|
||||
if (ir_code == 1) //Staandelamp
|
||||
if(main_btn_staandelamp==0)
|
||||
domoticz_send_nvalue(idx_staandelamp, 1);
|
||||
else
|
||||
domoticz_send_nvalue(idx_staandelamp, 0);
|
||||
|
||||
if (ir_code == 2) //Haard
|
||||
if(main_btn_haardverlichting==0)
|
||||
domoticz_send_nvalue(idx_haardverlichting, 1);
|
||||
else
|
||||
domoticz_send_nvalue(idx_haardverlichting, 0);
|
||||
|
||||
if (ir_code == 4) //Rooster
|
||||
if(main_btn_rooster==0)
|
||||
domoticz_send_nvalue(idx_rooster, 1);
|
||||
else
|
||||
domoticz_send_nvalue(idx_rooster, 0);
|
||||
|
||||
if (ir_code == 5) //Hanglamp
|
||||
if(main_btn_hanglamp==0)
|
||||
domoticz_send_nvalue(idx_hanglamp, 1);
|
||||
else
|
||||
domoticz_send_nvalue(idx_hanglamp, 0);
|
||||
|
||||
if (ir_code == 3) //Tuin
|
||||
if(main_btn_tuinverlichting==0)
|
||||
domoticz_send_nvalue(idx_tuinverlichting, 1);
|
||||
else
|
||||
domoticz_send_nvalue(idx_tuinverlichting, 0);
|
||||
|
||||
if (ir_code == 6) //Kaarsen
|
||||
if(main_btn_ir06==0)
|
||||
domoticz_send_nvalue(idx_ir06, 1);
|
||||
else
|
||||
domoticz_send_nvalue(idx_ir06, 0);
|
||||
|
||||
if (ir_code == 7)
|
||||
if(main_btn_ir07 == 0)
|
||||
domoticz_send_nvalue(idx_ir07, 1);
|
||||
else
|
||||
domoticz_send_nvalue(idx_ir07, 0);
|
||||
|
||||
if (ir_code == 8)
|
||||
if(main_btn_ir08 == 0)
|
||||
domoticz_send_nvalue(idx_ir08, 1);
|
||||
else
|
||||
domoticz_send_nvalue(idx_ir08, 0);
|
||||
|
||||
if (ir_code == 9)
|
||||
if(main_btn_ir09 == 0)
|
||||
domoticz_send_nvalue(idx_ir09, 1);
|
||||
else
|
||||
domoticz_send_nvalue(idx_ir09, 0);
|
||||
|
||||
if (ir_code == 10)
|
||||
if(main_btn_ir10 == 0)
|
||||
domoticz_send_nvalue(idx_ir10, 1);
|
||||
else
|
||||
domoticz_send_nvalue(idx_ir10, 0);
|
||||
|
||||
ir_code = 0;
|
||||
#ifdef DEBUG
|
||||
Serial.println("Ir_code set to 0 ");
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
}
|
||||
356
Arduino/display/Json.ino
Normal file
@ -0,0 +1,356 @@
|
||||
//MQTT receive
|
||||
void mqtt_callback(char* topic, byte* payload, unsigned int length) {
|
||||
int svalue1, loc, StepperTarget;
|
||||
String sub, devicename;
|
||||
|
||||
StaticJsonDocument<512> 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
|
||||
|
||||
|
||||
//Get IDX IR config
|
||||
if (idx == -1)
|
||||
{
|
||||
idx_staandelamp = root["svalue1"];
|
||||
idx_haardverlichting = root["svalue2"];
|
||||
idx_tuinverlichting = root["svalue3"];
|
||||
idx_rooster = root["svalue4"];
|
||||
idx_hanglamp = root["svalue5"];
|
||||
idx_ir06 = root["svalue6"];
|
||||
idx_ir07 = root["svalue7"];
|
||||
idx_ir08 = root["svalue8"];
|
||||
idx_ir09 = root["svalue9"];
|
||||
idx_ir10 = root["svalue10"];
|
||||
idx_ir11 = root["svalue11"];
|
||||
idx_ir12 = root["svalue12"];
|
||||
idx_ir13 = root["svalue13"];
|
||||
idx_ir14 = root["svalue14"];
|
||||
idx_ir15 = root["svalue15"];
|
||||
idx_ir16 = root["svalue16"];
|
||||
}
|
||||
|
||||
|
||||
//Dim display
|
||||
if (idx == idx_display_dim)
|
||||
{
|
||||
if(root["nvalue"] >=1)
|
||||
sendCommand("dim=10");
|
||||
else
|
||||
sendCommand("dim=100");
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
if (idx == idx_ir06)
|
||||
{
|
||||
if (root["nvalue"] >= 1)
|
||||
main_btn_ir06 = 1;
|
||||
else
|
||||
main_btn_ir06 = 0;
|
||||
|
||||
// btn_1.setValue(main_btn_kaarsen);
|
||||
}
|
||||
|
||||
if (idx == idx_ir07)
|
||||
{
|
||||
if (root["nvalue"] >= 1)
|
||||
main_btn_ir07 = 1;
|
||||
else
|
||||
main_btn_ir07 = 0;
|
||||
}
|
||||
|
||||
if (idx == idx_ir08)
|
||||
{
|
||||
if (root["nvalue"] >= 1)
|
||||
main_btn_ir08 = 1;
|
||||
else
|
||||
main_btn_ir08 = 0;
|
||||
}
|
||||
|
||||
if (idx == idx_ir09)
|
||||
{
|
||||
if (root["nvalue"] >= 1)
|
||||
main_btn_ir09 = 1;
|
||||
else
|
||||
main_btn_ir09 = 0;
|
||||
}
|
||||
|
||||
if (idx == idx_ir10)
|
||||
{
|
||||
if (root["nvalue"] >= 1)
|
||||
main_btn_ir10 = 1;
|
||||
else
|
||||
main_btn_ir10 = 0;
|
||||
}
|
||||
|
||||
if (idx == idx_ir11)
|
||||
{
|
||||
if (root["nvalue"] >= 1)
|
||||
main_btn_ir11 = 1;
|
||||
else
|
||||
main_btn_ir11 = 0;
|
||||
}
|
||||
|
||||
if (idx == idx_ir12)
|
||||
{
|
||||
if (root["nvalue"] >= 1)
|
||||
main_btn_ir12 = 1;
|
||||
else
|
||||
main_btn_ir12 = 0;
|
||||
}
|
||||
|
||||
if (idx == idx_ir13)
|
||||
{
|
||||
if (root["nvalue"] >= 1)
|
||||
main_btn_ir13 = 1;
|
||||
else
|
||||
main_btn_ir13 = 0;
|
||||
}
|
||||
|
||||
if (idx == idx_ir14)
|
||||
{
|
||||
if (root["nvalue"] >= 1)
|
||||
main_btn_ir14 = 1;
|
||||
else
|
||||
main_btn_ir14 = 0;
|
||||
}
|
||||
|
||||
if (idx == idx_ir15)
|
||||
{
|
||||
if (root["nvalue"] >= 1)
|
||||
main_btn_ir15 = 1;
|
||||
else
|
||||
main_btn_ir15 = 0;
|
||||
}
|
||||
|
||||
if (idx == idx_ir16)
|
||||
{
|
||||
if (root["nvalue"] >= 1)
|
||||
main_btn_ir16 = 1;
|
||||
else
|
||||
main_btn_ir16 = 0;
|
||||
}
|
||||
|
||||
//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)
|
||||
{
|
||||
|
||||
#ifdef DEBUG
|
||||
Serial.print("!!!! idx 459 !!! ");
|
||||
#endif
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
112
Arduino/display/Nextion.ino
Normal file
@ -0,0 +1,112 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
279
Arduino/display/display.ino
Normal file
@ -0,0 +1,279 @@
|
||||
|
||||
#define DEBUG 1 //Uit quoten om debug messages te krijgen
|
||||
|
||||
|
||||
#include <WiFi.h>
|
||||
|
||||
//#include <ESP8266WiFi.h>
|
||||
|
||||
//#include <ESP8266HTTPClient.h>
|
||||
#include <PubSubClient.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include <Nextion.h>
|
||||
|
||||
#include <X10ir.h>
|
||||
|
||||
//#define BUZZER_PIN D5
|
||||
|
||||
//#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)
|
||||
'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[250];
|
||||
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_kaarsen 1845
|
||||
*/
|
||||
int dim_val = 100;
|
||||
int idx_staandelamp = 1701; //1714 //1701 //1252
|
||||
int idx_haardverlichting = 1702; //1717 //1702 //628
|
||||
int idx_tuinverlichting = 695; //1715 //695
|
||||
int idx_rooster = 148;
|
||||
int idx_hanglamp = 1695; //1716 //1695 //1326
|
||||
int idx_ir06 = 1845;
|
||||
int idx_ir07 = 0;
|
||||
int idx_ir08 = 0;
|
||||
int idx_ir09 = 0;
|
||||
int idx_ir10 = 0;
|
||||
int idx_ir11 = 0;
|
||||
int idx_ir12 = 0;
|
||||
int idx_ir13 = 0;
|
||||
int idx_ir14 = 0;
|
||||
int idx_ir15 = 0;
|
||||
int idx_ir16 = 0;
|
||||
|
||||
int ir_code = 0;
|
||||
|
||||
|
||||
#define idx_init 1984
|
||||
#define idx_display_dim 1991
|
||||
#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[250] = {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_kaarsen = 0;
|
||||
int main_btn_deurbelstil = 0;
|
||||
|
||||
int main_btn_ir06 = 0;
|
||||
int main_btn_ir07 = 0;
|
||||
int main_btn_ir08 = 0;
|
||||
int main_btn_ir09 = 0;
|
||||
int main_btn_ir10 = 0;
|
||||
int main_btn_ir11 = 0;
|
||||
int main_btn_ir12 = 0;
|
||||
int main_btn_ir13 = 0;
|
||||
int main_btn_ir14 = 0;
|
||||
int main_btn_ir15 = 0;
|
||||
int main_btn_ir16 = 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);
|
||||
}
|
||||
}
|
||||
|
||||
//display init
|
||||
domoticz_send_nvalue(idx_init, 1);
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
//Execute IR functio
|
||||
if(ir_code != 0 )
|
||||
{
|
||||
ir_action();
|
||||
}
|
||||
|
||||
|
||||
long now = millis();
|
||||
if (now - lastMsg > 20000)
|
||||
{
|
||||
lastMsg = now;
|
||||
++value;
|
||||
}
|
||||
}
|
||||
528
Backup/display.ino
Normal file
@ -0,0 +1,528 @@
|
||||
/*
|
||||
Basic ESP8266 MQTT example
|
||||
|
||||
This sketch demonstrates the capabilities of the pubsub library in combination
|
||||
with the ESP8266 board/library.
|
||||
|
||||
It connects to an MQTT server then:
|
||||
- publishes "hello world" to the topic "outTopic" every two seconds
|
||||
- subscribes to the topic "inTopic", printing out any messages
|
||||
it receives. NB - it assumes the received payloads are strings not binary
|
||||
- If the first character of the topic "inTopic" is an 1, switch ON the ESP Led,
|
||||
else switch it off
|
||||
|
||||
It will reconnect to the server if the connection is lost using a blocking
|
||||
reconnect function. See the 'mqtt_reconnect_nonblocking' example for how to
|
||||
achieve the same result without blocking the main loop.
|
||||
|
||||
To install the ESP8266 board, (using Arduino 1.6.4+):
|
||||
- Add the following 3rd party board manager under "File -> Preferences -> Additional Boards Manager URLs":
|
||||
http://arduino.esp8266.com/stable/package_esp8266com_index.json
|
||||
- Open the "Tools -> Board -> Board Manager" and click install for the ESP8266"
|
||||
- Select your ESP8266 in "Tools -> Board"
|
||||
|
||||
*/
|
||||
//#include <EEPROM.h>
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
|
||||
//#include <ESP8266HTTPClient.h>
|
||||
#include <PubSubClient.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include <Nextion.h>
|
||||
|
||||
#include <X10ir.h>
|
||||
|
||||
#define BUZZER_PIN D2
|
||||
|
||||
// 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 * !!!!
|
||||
);
|
||||
|
||||
|
||||
// Update these with values suitable for your network.
|
||||
|
||||
const char* ssid = "FrankHilde";
|
||||
const char* password = "HildeFrank";
|
||||
const char* mqtt_server = "192.168.2.202";
|
||||
|
||||
WiFiClient espClient;
|
||||
PubSubClient client(espClient);
|
||||
long lastMsg = 0;
|
||||
char msg[100];
|
||||
int value = 0;
|
||||
|
||||
#define idx_staandelamp 1252
|
||||
#define idx_hanglamp 1326
|
||||
#define idx_haardverlichting 628
|
||||
#define idx_tuinverlichting 695
|
||||
#define idx_rooster 148
|
||||
#define idx_deurbel 906
|
||||
#define idx_deurbel_stil 917
|
||||
#define idx_rooster 922
|
||||
|
||||
//NexButton b0 = NexButton(0, 1, "b0");
|
||||
|
||||
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, 2, "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");
|
||||
|
||||
//NexText txt_temp_binnen = NexText(0, 9, "txt_temp_in");
|
||||
//NexText txt_temp_buiten = NexText(0, 10, "txt_temp_out");
|
||||
//NexText txt_regen = NexText(0, 11, "t2");
|
||||
|
||||
//page1
|
||||
//NexText txt_1_temp_binnen = NexText(1, 3, "txt_temp_in");
|
||||
//NexText txt_1_temp_buiten = NexText(1, 4, "txt_temp_out");
|
||||
|
||||
//NexText txt_1_header = NexText(1, 1, "txt_header");
|
||||
//NexText txt_1_weer = NexText(0, 15, "txt_weer");
|
||||
|
||||
|
||||
char buffer[100] = {0};
|
||||
|
||||
NexTouch *nex_listen_list[] =
|
||||
{
|
||||
&btn_1, &btn_2, &btn_3, &btn_4, &btn_5,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
void btn_1_PopCallback(void *ptr)
|
||||
{
|
||||
uint32_t dual_state;
|
||||
|
||||
btn_1.getValue(&dual_state);
|
||||
if(dual_state)
|
||||
{
|
||||
send_nvalue(idx_hanglamp,1);
|
||||
}
|
||||
else
|
||||
{
|
||||
send_nvalue(idx_hanglamp,0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void btn_2_PopCallback(void *ptr)
|
||||
{
|
||||
uint32_t dual_state;
|
||||
|
||||
btn_2.getValue(&dual_state);
|
||||
if(dual_state)
|
||||
{
|
||||
send_nvalue(idx_staandelamp,1);
|
||||
}
|
||||
else
|
||||
{
|
||||
send_nvalue(idx_staandelamp,0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
send_nvalue(idx_haardverlichting,1);
|
||||
}
|
||||
else
|
||||
{
|
||||
send_nvalue(idx_haardverlichting,0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
send_nvalue(idx_tuinverlichting,1);
|
||||
}
|
||||
else
|
||||
{
|
||||
send_nvalue(idx_tuinverlichting,0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
send_nvalue(idx_rooster,1);
|
||||
}
|
||||
else
|
||||
{
|
||||
send_nvalue(idx_rooster,0);
|
||||
}
|
||||
}
|
||||
|
||||
void setup_wifi() {
|
||||
|
||||
delay(10);
|
||||
// We start by connecting to a WiFi network
|
||||
Serial.println();
|
||||
Serial.print("Connecting to ");
|
||||
Serial.println(ssid);
|
||||
|
||||
WiFi.begin(ssid, password);
|
||||
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
}
|
||||
|
||||
randomSeed(micros());
|
||||
|
||||
Serial.println("");
|
||||
Serial.println("WiFi connected");
|
||||
Serial.println("IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
}
|
||||
|
||||
void 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");
|
||||
|
||||
Serial.print("Message arrived [");
|
||||
Serial.print(topic);
|
||||
Serial.print("] ");
|
||||
for (int i = 0; i < length; i++) {
|
||||
Serial.print((char)payload[i]);
|
||||
}
|
||||
Serial.println();
|
||||
|
||||
// Deserialize the JSON document
|
||||
DeserializationError error = deserializeJson(doc, payload);
|
||||
|
||||
|
||||
// Test if parsing succeeds.
|
||||
if (error) {
|
||||
Serial.print(F("deserializeJson() failed: "));
|
||||
Serial.println(error.c_str());
|
||||
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"];
|
||||
|
||||
Serial.println(idx);
|
||||
Serial.println(idx_name);
|
||||
Serial.println(idx_svalue1);
|
||||
Serial.println(idx_nvalue);
|
||||
|
||||
if(idx == idx_hanglamp)
|
||||
{
|
||||
btn_1.setValue(idx_nvalue);
|
||||
}
|
||||
|
||||
if(idx == idx_staandelamp)
|
||||
{
|
||||
btn_2.setValue(idx_nvalue);
|
||||
}
|
||||
|
||||
if(idx == idx_haardverlichting)
|
||||
{
|
||||
btn_3.setValue(idx_nvalue);
|
||||
}
|
||||
|
||||
if(idx == idx_tuinverlichting)
|
||||
{
|
||||
btn_4.setValue(idx_nvalue);
|
||||
}
|
||||
|
||||
if(idx == idx_rooster)
|
||||
{
|
||||
btn_5.setValue(idx_nvalue);
|
||||
}
|
||||
|
||||
//Tijd
|
||||
if(idx == 1513)
|
||||
{
|
||||
Serial.println(idx_svalue1);
|
||||
txt_header.setText(idx_svalue1);
|
||||
// txt_1_header.setText(idx_svalue1);
|
||||
}
|
||||
|
||||
//Weer
|
||||
if(idx == 1459)
|
||||
{
|
||||
nextion_send("txt_weer.txt", idx_svalue1);
|
||||
}
|
||||
|
||||
if(idx==450)
|
||||
{
|
||||
nextion_send("txt_temp_in.txt", idx_svalue1);
|
||||
nextion_send("t0.txt", idx_svalue2);
|
||||
nextion_send("t2.txt", idx_svalue4);
|
||||
|
||||
|
||||
// int length = sizeof(idx_svalue4);
|
||||
|
||||
// Serial.println("Barometer");
|
||||
// Serial.println(length);
|
||||
|
||||
// char subbuff[5];
|
||||
// memcpy( subbuff, &idx_svalue4[0], (length-2) );
|
||||
// subbuff[5] = '\0';
|
||||
// nextion_send("t2.txt", subbuff);
|
||||
|
||||
}
|
||||
|
||||
//Min temperatuur
|
||||
if(idx==1562)
|
||||
{
|
||||
nextion_send("t10.txt", idx_svalue1);
|
||||
}
|
||||
//Max Temperatuur
|
||||
if(idx==1563)
|
||||
{
|
||||
nextion_send("t11.txt", idx_svalue1);
|
||||
}
|
||||
//Rain
|
||||
if(idx==1564)
|
||||
{
|
||||
nextion_send("t3.txt", idx_svalue1);
|
||||
nextion_send("t4.txt", idx_svalue2);
|
||||
}
|
||||
|
||||
if(idx==453)
|
||||
{
|
||||
nextion_send("txt_temp_out.txt", idx_svalue1);
|
||||
nextion_send("t1.txt", idx_svalue2);
|
||||
}
|
||||
|
||||
//Set weer icoon
|
||||
if(idx==1522)
|
||||
{
|
||||
pic_weer.setPic(idx_nvalue);
|
||||
}
|
||||
|
||||
if(idx==idx_deurbel)
|
||||
{
|
||||
if(idx_nvalue==1)
|
||||
{
|
||||
Serial.println("Show doorbell");
|
||||
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_deurbel_stil)
|
||||
{
|
||||
if(idx_nvalue==1)
|
||||
sendCommand("p1.pic=56");
|
||||
else
|
||||
sendCommand("p1.pic=53");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
Serial.println(buf);
|
||||
|
||||
sendCommand(buf);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void reconnect() {
|
||||
// Loop until we're reconnected
|
||||
while (!client.connected()) {
|
||||
Serial.print("Attempting MQTT connection...");
|
||||
// Create a random client ID
|
||||
String clientId = "ESP8266Client-";
|
||||
clientId += String(random(0xffff), HEX);
|
||||
// Attempt to connect
|
||||
if (client.connect(clientId.c_str())) {
|
||||
Serial.println("connected");
|
||||
// Once connected, publish an announcement...
|
||||
client.publish("outTopic", "hello world");
|
||||
// ... and resubscribe
|
||||
client.subscribe("domoticz/out/example/display");
|
||||
} else {
|
||||
Serial.print("failed, rc=");
|
||||
Serial.print(client.state());
|
||||
Serial.println(" try again in 5 seconds");
|
||||
// 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
|
||||
Serial.begin(115200);
|
||||
setup_wifi();
|
||||
client.setServer(mqtt_server, 1883);
|
||||
client.setCallback(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();
|
||||
|
||||
long now = millis();
|
||||
if (now - lastMsg > 20000)
|
||||
{
|
||||
lastMsg = now;
|
||||
++value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void send_nvalue(int idx, int nvalue)
|
||||
{
|
||||
StaticJsonDocument<200> doc;
|
||||
|
||||
Serial.println("Sending nvalue");
|
||||
Serial.println(idx);
|
||||
Serial.println(nvalue);
|
||||
|
||||
// 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);
|
||||
Serial.println(msg);
|
||||
client.publish("domoticz/in", msg);
|
||||
}
|
||||
|
||||
|
||||
// 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");
|
||||
|
||||
Serial.println("!! IR Received !!");
|
||||
if(!isRepeat)
|
||||
{
|
||||
|
||||
Serial.println(command);
|
||||
// Handle Address Command (House + Unit)
|
||||
if(command == CMD_ADDRESS)
|
||||
{
|
||||
Serial.println("cmd == CMD_ADDRESS");
|
||||
Serial.println(house);
|
||||
Serial.println(unit);
|
||||
Serial.println(command);
|
||||
|
||||
if(unit <= 16)
|
||||
{
|
||||
Serial.println("Switch...");
|
||||
|
||||
if(unit==1) //Staandelamp
|
||||
btn_2_PopCallback(0);
|
||||
if(unit==2) //Haard
|
||||
btn_3_PopCallback(0);
|
||||
if(unit==4) //Rooster
|
||||
{
|
||||
send_nvalue(idx_rooster,1);
|
||||
}
|
||||
//btn_2_PopCallback(0);
|
||||
if(unit==4) //Hanglamp
|
||||
btn_1_PopCallback(0);
|
||||
if(unit==3) //Tuin
|
||||
btn_4_PopCallback(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
55
Domoticz.ino
Normal file
@ -0,0 +1,55 @@
|
||||
|
||||
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
Normal file
@ -0,0 +1,64 @@
|
||||
|
||||
// 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
Normal file
@ -0,0 +1,226 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
LucidaConsoleBold_64.zi
Executable file
BIN
LucidaConsoleBold_96.zi
Executable file
BIN
LucidaConsole_20.zi
Executable file
BIN
LucidaConsole_24.zi
Executable file
BIN
LucidaConsole_32.zi
Executable file
BIN
LucidaConsole_56.zi
Executable file
BIN
LucidaConsole_64.zi
Executable file
BIN
LucidaConsole_80.zi
Executable file
BIN
LucidaConsole_96.zi
Executable file
112
Nextion.ino
Normal file
@ -0,0 +1,112 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
1
Nextion/.svn/entries
Normal file
@ -0,0 +1 @@
|
||||
12
|
||||
1
Nextion/.svn/format
Normal file
@ -0,0 +1 @@
|
||||
12
|
||||
|
After Width: | Height: | Size: 92 B |
|
After Width: | Height: | Size: 104 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 1.8 KiB |
|
After Width: | Height: | Size: 46 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 19 KiB |
|
After Width: | Height: | Size: 68 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 99 KiB |
|
After Width: | Height: | Size: 23 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 100 KiB |
|
After Width: | Height: | Size: 79 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 46 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 10 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 78 KiB |
|
After Width: | Height: | Size: 10 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 10 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 58 KiB |
|
After Width: | Height: | Size: 79 KiB |
|
After Width: | Height: | Size: 77 KiB |
|
After Width: | Height: | Size: 1.2 KiB |