Domoticz data timeout
-
@kimot , I have to confess that I'm still a bit lost when I have to understand which language I'm using in each environment, but this is because I keep jumping from something to something else. Your explanation was very clear and allowed me to solve the "timing problem" if a few minutes.
At the same time... you gave me enough reason to test ESPeasy... and to say it all I have already installed another NodeMCU on the breadboard and starting right now to play :)
Thanks again -
@kimot , I have to confess that I'm still a bit lost when I have to understand which language I'm using in each environment, but this is because I keep jumping from something to something else. Your explanation was very clear and allowed me to solve the "timing problem" if a few minutes.
At the same time... you gave me enough reason to test ESPeasy... and to say it all I have already installed another NodeMCU on the breadboard and starting right now to play :)
Thanks again -
My tests with ESPeasy stopped before beginning because I realized that I need a USB to TTL converter that I don't have a t moment... Delayed...
This gave me time to implement the change in NodeMCU sketch which addresses and solves the original problem of this topic.
I'm attaching here the second part of the modified sketch omitting the WiFi part.
In short, I defined a fake "switch" sensor in NodeMCU and I'm sending its modified status to Domoticz every 45 seconds (data timeout in Domoticz is 1 minute).
Important to underline that the new "fake sensor" can remain in the list of "not used" devices in Domoticz.
Here is the code:// Start of the sensor specific code #include <SPI.h> #include <MySensors.h> #include <pins_arduino.h> #include <Bounce2.h> #define CHILD_ID0 0 #define CHILD_ID1 1 #define CHILD_ID2 2 Bounce debouncer1 = Bounce(); Bounce debouncer2 = Bounce(); int oldValue1=-1; int oldValue2=-1; int tempo=millis(); int ultimo=0; MyMessage msg1(CHILD_ID0, V_TRIPPED); MyMessage msg2(CHILD_ID1, V_TRIPPED); MyMessage msg3(CHILD_ID2, V_TRIPPED); void setup() { // Setup magnetic contact on D0 with pull-up pinMode(D0,INPUT_PULLUP); // After setting up reed switch, setup debouncer debouncer1.attach(D0); debouncer1.interval(5); // Setup magnetic contact on D1 with pull-up pinMode(D1,INPUT_PULLUP); // After setting up reed switch, setup debouncer debouncer2.attach(D1); debouncer2.interval(5); } void presentation() { // Present locally attached sensors here present(CHILD_ID0, S_DOOR); present(CHILD_ID1, S_DOOR); present(CHILD_ID2, S_DOOR); } // Check if digital input has changed and send in new value void loop() { debouncer1.update(); debouncer2.update(); // Get the update value int value1 = debouncer1.read(); int value2 = debouncer2.read(); if (millis() > tempo + 45000) { Serial.print (millis()); Serial.print (ultimo); tempo = millis(); send(msg3.set(ultimo)); ultimo = ultimo + 1; if (ultimo > 1) { ultimo = 0; } } if (value1 != oldValue1) { // Send in the new value send(msg1.set(value1==HIGH ? 1 : 0)); oldValue1 = value1; } if (value2 != oldValue2) { // Send in the new value send(msg2.set(value2==HIGH ? 1 : 0)); oldValue2 = value2; } }``` -
Domoticz log changed from this:
2018-01-05 14:19:04.819 MySensors: Gateway Ready...
2018-01-05 14:19:05.820 MySensors: Gateway Version: 2.1.1
2018-01-05 14:19:05.820 MySensors: Gateway Version: 2.1.1
2018-01-05 14:20:00.270 dzVents: Debug: Dumping domoticz data to /home/pi/domoticz/scripts/dzVents//domoticzData.lua
2018-01-05 14:20:00.293 dzVents: Debug: Event trigger type: time
2018-01-05 14:20:30.855 Error: MySensors1 hardware (7) nothing received for more than 1 Minute!....
2018-01-05 14:20:31.856 Error: Restarting: MySensors1
2018-01-05 14:20:32.829 MySensors: TCP/IP Worker stopped...
2018-01-05 14:20:33.831 MySensors: trying to connect to: 192.168.1.7:5003
2018-01-05 14:20:34.831 MySensors: connected to: 192.168.1.7:5003
2018-01-05 14:20:34.831 MySensors: Gateway Ready...
2018-01-05 14:20:35.832 MySensors: Gateway Version: 2.1.1
2018-01-05 14:20:35.832 MySensors: Gateway Version: 2.1.1
2018-01-05 14:21:00.379 dzVents: Debug: Dumping domoticz data to /home/pi/domoticz/scripts/dzVents//domoticzData.lua
2018-01-05 14:21:00.402 dzVents: Debug: Event trigger type: time
2018-01-05 14:22:00.486 dzVents: Debug: Dumping domoticz data to /home/pi/domoticz/scripts/dzVents//domoticzData.lua
2018-01-05 14:22:00.510 dzVents: Debug: Event trigger type: time
2018-01-05 14:22:00.846 Error: MySensors1 hardware (7) nothing received for more than 1 Minute!....
2018-01-05 14:22:01.847 Error: Restarting: MySensors1
2018-01-05 14:22:02.841 MySensors: TCP/IP Worker stopped...
2018-01-05 14:22:03.842 MySensors: trying to connect to: 192.168.1.7:5003
2018-01-05 14:22:04.843 MySensors: connected to: 192.168.1.7:5003To this:
2018-01-05 14:55:00.413 dzVents: Debug: Dumping domoticz data to /home/pi/domoticz/scripts/dzVents//domoticzData.lua
2018-01-05 14:55:00.436 dzVents: Debug: Event trigger type: time
2018-01-05 14:55:35.108 (MySensors1) Light/Switch (Security Sensor)
2018-01-05 14:56:00.520 dzVents: Debug: Dumping domoticz data to /home/pi/domoticz/scripts/dzVents//domoticzData.lua
2018-01-05 14:56:00.543 dzVents: Debug: Event trigger type: time
2018-01-05 14:56:20.113 (MySensors1) Light/Switch (Security Sensor)
2018-01-05 14:57:00.127 dzVents: Debug: Dumping domoticz data to /home/pi/domoticz/scripts/dzVents//domoticzData.lua
2018-01-05 14:57:00.151 dzVents: Debug: Event trigger type: time
2018-01-05 14:57:05.120 (MySensors1) Light/Switch (Security Sensor)
2018-01-05 14:57:50.124 (MySensors1) Light/Switch (Security Sensor)
2018-01-05 14:58:00.235 dzVents: Debug: Dumping domoticz data to /home/pi/domoticz/scripts/dzVents//domoticzData.lua
2018-01-05 14:58:00.259 dzVents: Debug: Event trigger type: time
2018-01-05 14:58:35.129 (MySensors1) Light/Switch (Security Sensor)
2018-01-05 14:59:00.344 dzVents: Debug: Dumping domoticz data to /home/pi/domoticz/scripts/dzVents//domoticzData.lua
2018-01-05 14:59:00.367 dzVents: Debug: Event trigger type: time
2018-01-05 14:59:20.134 (MySensors1) Light/Switch (Security Sensor) -
My tests with ESPeasy stopped before beginning because I realized that I need a USB to TTL converter that I don't have a t moment... Delayed...
This gave me time to implement the change in NodeMCU sketch which addresses and solves the original problem of this topic.
I'm attaching here the second part of the modified sketch omitting the WiFi part.
In short, I defined a fake "switch" sensor in NodeMCU and I'm sending its modified status to Domoticz every 45 seconds (data timeout in Domoticz is 1 minute).
Important to underline that the new "fake sensor" can remain in the list of "not used" devices in Domoticz.
Here is the code:// Start of the sensor specific code #include <SPI.h> #include <MySensors.h> #include <pins_arduino.h> #include <Bounce2.h> #define CHILD_ID0 0 #define CHILD_ID1 1 #define CHILD_ID2 2 Bounce debouncer1 = Bounce(); Bounce debouncer2 = Bounce(); int oldValue1=-1; int oldValue2=-1; int tempo=millis(); int ultimo=0; MyMessage msg1(CHILD_ID0, V_TRIPPED); MyMessage msg2(CHILD_ID1, V_TRIPPED); MyMessage msg3(CHILD_ID2, V_TRIPPED); void setup() { // Setup magnetic contact on D0 with pull-up pinMode(D0,INPUT_PULLUP); // After setting up reed switch, setup debouncer debouncer1.attach(D0); debouncer1.interval(5); // Setup magnetic contact on D1 with pull-up pinMode(D1,INPUT_PULLUP); // After setting up reed switch, setup debouncer debouncer2.attach(D1); debouncer2.interval(5); } void presentation() { // Present locally attached sensors here present(CHILD_ID0, S_DOOR); present(CHILD_ID1, S_DOOR); present(CHILD_ID2, S_DOOR); } // Check if digital input has changed and send in new value void loop() { debouncer1.update(); debouncer2.update(); // Get the update value int value1 = debouncer1.read(); int value2 = debouncer2.read(); if (millis() > tempo + 45000) { Serial.print (millis()); Serial.print (ultimo); tempo = millis(); send(msg3.set(ultimo)); ultimo = ultimo + 1; if (ultimo > 1) { ultimo = 0; } } if (value1 != oldValue1) { // Send in the new value send(msg1.set(value1==HIGH ? 1 : 0)); oldValue1 = value1; } if (value2 != oldValue2) { // Send in the new value send(msg2.set(value2==HIGH ? 1 : 0)); oldValue2 = value2; } }```@gbuico
"and to say it all I have already installed another NodeMCU on the breadboard and starting right now to play""My tests with ESPeasy stopped before beginning because I realized that I need a USB to TTL converter that I don't have a t moment... Delayed..."
NodeMCU is with USB to TTL converter onboard.
Or how you programme it now? -
I think with domoticz its might be enough to call sendHeartbeat() from your gateway every 30 seconds.
It should update the m_LastHeartbeatReceive of the HW and thats what mainworker uses when it defines if the HW should be "rebooted".Here is a example(NOT TESTED):
#define HEARTBEAT_SEND_FREQUENCY 30000 unsigned long lastHeartBeatSend; .... void setup() { lastHeartBeatSend = 0; } ... void loop() { unsigned long now = millis(); if(now - lastHeartBeatSend > HEARTBEAT_SEND_FREQUENCY) { sendHeartbeat(); lastHeartBeatSend = now; } }See:
https://github.com/domoticz/domoticz/blob/8bb0420c3ba4a10bbacd6f2e2f9b40b06ff0c7ac/main/mainworker.cpp#L12864
https://github.com/domoticz/domoticz/blob/8bb0420c3ba4a10bbacd6f2e2f9b40b06ff0c7ac/hardware/MySensorsBase.cpp#L487
https://www.mysensors.org/download/sensor_api_20 -
@kimot , right now I'm using the Arduino IDE application which allows me to upload to NodeMCU just using the USB cable.
Reading the ESPeasy documentation I understand that this type of connection is not an option and you must have a USB to TTL interface.
I'd be very happy to hear that I don't need it... otherwise I'm going to get one on monday... -
I think with domoticz its might be enough to call sendHeartbeat() from your gateway every 30 seconds.
It should update the m_LastHeartbeatReceive of the HW and thats what mainworker uses when it defines if the HW should be "rebooted".Here is a example(NOT TESTED):
#define HEARTBEAT_SEND_FREQUENCY 30000 unsigned long lastHeartBeatSend; .... void setup() { lastHeartBeatSend = 0; } ... void loop() { unsigned long now = millis(); if(now - lastHeartBeatSend > HEARTBEAT_SEND_FREQUENCY) { sendHeartbeat(); lastHeartBeatSend = now; } }See:
https://github.com/domoticz/domoticz/blob/8bb0420c3ba4a10bbacd6f2e2f9b40b06ff0c7ac/main/mainworker.cpp#L12864
https://github.com/domoticz/domoticz/blob/8bb0420c3ba4a10bbacd6f2e2f9b40b06ff0c7ac/hardware/MySensorsBase.cpp#L487
https://www.mysensors.org/download/sensor_api_20@pjr , what you are suggesting is exactly what I wanted at the beginning..... but... my understanding from the first answer I got and for this https://www.domoticz.com/forum/viewtopic.php?f=42&t=9775&sid=1fea4af7b12f84f656ca4aa825eb6115
is that the sendHeartbeat() function is basically accepted but disregarded in Domoticz, meaning, would not create problems but not fixing the issues.
Of course this is my understanding and would be glad to have additional opinions/tests -
@pjr, thanks for your update. I went to check the solution proposed in the link you attached... and let me confess... got the concept, but it's complexity is currently not something at my reach.
Meaning.. as my solution is very small and working, for the time been I'll stick to it and spend my time for further function implementation.
My only worry... your example was just a few lines... understandable... how did they end up with 1700 lines of code or this?
Whatever.. I'l go back to it when I have some more time as I prefer an official implementation to a patch like mine... -
@kimot , right now I'm using the Arduino IDE application which allows me to upload to NodeMCU just using the USB cable.
Reading the ESPeasy documentation I understand that this type of connection is not an option and you must have a USB to TTL interface.
I'd be very happy to hear that I don't need it... otherwise I'm going to get one on monday...@gbuico
USB to TTL serial is on board on NodeMCU and Wemos.Download
ESPEasy mega dev.13Upload to your NodeMCU using "FlashESP8266.exe" from .zip
Upload to NodeMCUUse "....._normal_4096.bin" file
Power off - on !!! your NodeMCU ( reconnect USB cable )
Make basic setup:
With smart phone or notebook connect to your NodeMCU, which works like wifi acces point now ( name like "ESP_Easy_0" )
If password required - "configesp"
Type in browser address 192.168.4.1
wifi setup
Set your home wifi access info in config page.
You will see actual IP your NodeMCU in your wifi network.
Connect to this IP and make basic setup.
( you can set Fixed IP, IP of your Domoticz, etc )
ESPEasy setup