Maintain date and time in the absence of wifi
Moderators: grovkillen, Stuntteam, TD-er
Maintain date and time in the absence of wifi
Hi,
I have installed ESPEasy to a SONOFF Basic. My use case is that every day at a specific time (let's say 9am) I want to switch on the relay, let it be on for 30 minutes and then switch it off. SONOFF is connected to the router and I am using NTP.
Assume there was wifi (and internet) connection when the SONOFF is powered on so that it received the date and time. Now while the SONOFF is still powered on, if the wifi (internet) connection is lost, does ESP Easy still maintain the date and time ? If so how how long (like is it until the next reboot of SONOFF).
My system is installed remotely so I cannot experiment at the moment, hence the question.
Thank you.
I have installed ESPEasy to a SONOFF Basic. My use case is that every day at a specific time (let's say 9am) I want to switch on the relay, let it be on for 30 minutes and then switch it off. SONOFF is connected to the router and I am using NTP.
Assume there was wifi (and internet) connection when the SONOFF is powered on so that it received the date and time. Now while the SONOFF is still powered on, if the wifi (internet) connection is lost, does ESP Easy still maintain the date and time ? If so how how long (like is it until the next reboot of SONOFF).
My system is installed remotely so I cannot experiment at the moment, hence the question.
Thank you.
Re: Maintain date and time in the absence of wifi
If a NTP query fails, it will not reset the time settings.
So you would still use the time based on the internal timer.
The time may drift a little, but that's about a few seconds per day max and depending on several factors like temperature.
As soon as the node reboots, there is no way to know the time in the absence of wifi.
So you should take into account the rules may start at the wrong moment of the day if the connection was lost and the node has rebooted.
So you would still use the time based on the internal timer.
The time may drift a little, but that's about a few seconds per day max and depending on several factors like temperature.
As soon as the node reboots, there is no way to know the time in the absence of wifi.
So you should take into account the rules may start at the wrong moment of the day if the connection was lost and the node has rebooted.
Re: Maintain date and time in the absence of wifi
Thanks for the reply.
What is the frequency that ESPEasy query for NTP? I am trying to figure out if wifi is absent at node reboot and after sometime wifi is back, will the node make a NTP query and correct the date time.
What is the frequency that ESPEasy query for NTP? I am trying to figure out if wifi is absent at node reboot and after sometime wifi is back, will the node make a NTP query and correct the date time.
Re: Maintain date and time in the absence of wifi
Although espeasy does not support it directly, but an RTC chip can also be used with esp8266 to maintain time when restarting with no wifi/internet. Needs some coding. 
https://techtutorialsx.com/2016/05/22/e ... s3231-rtc/
I am using a local openwrt NTP server instead on my wifi router, which is on UPS, so it is always available to my ESP modules for time sync.

https://techtutorialsx.com/2016/05/22/e ... s3231-rtc/
I am using a local openwrt NTP server instead on my wifi router, which is on UPS, so it is always available to my ESP modules for time sync.
- budman1758
- Normal user
- Posts: 303
- Joined: 15 Apr 2017, 05:13
- Location: Riverside CA USA
Re: Maintain date and time in the absence of wifi
I have requested a plugin for an RTC a couple times. The DS3231 would be perfect. It has configurable timers and could be used in battery powered sensors to get around the 71 min ESP limit. I'm sure folks would come up with multiple use cases for it.



"The glass is twice as big as it needs to be".
Re: Maintain date and time in the absence of wifi
I'm just finished a test version of my DS3231 plugin. It keeps time when power down, even without NTP server, and shows temperature information, the latter is new to me. I struggled a little with timezones when updating from ntp to rtc, but now i think it is working.budman1758 wrote: ↑10 Jul 2018, 19:29 I have requested a plugin for an RTC a couple times. The DS3231 would be perfect. It has configurable timers and could be used in battery powered sensors to get around the 71 min ESP limit. I'm sure folks would come up with multiple use cases for it.![]()
![]()
Alarm mode works in theory, but it is low level active, so pullup needed on the other side, i am curious how can you use it for deep sleep.
https://github.com/enesbcs/ESPEasyPlugi ... DS3231.ino
It disables NTP through "Settings.UseNTP" so any functions that depends on it - such as "Local Time" on main page, and several Clock plugins WILL NOT WORK! And i did not see any solution without modifing the current ESPEasy core functions... Rules / Clock#Time will work, and system values like %syshour% may work.
Re: Maintain date and time in the absence of wifi
OK, so we should have an extra check to see if it is a plausible time (anything past build time for example) and use that as check for rules.
I will have a look at your PR on the playground.
I will have a look at your PR on the playground.
Re: Maintain date and time in the absence of wifi
Thank you. I just tested it with ESPEasy32, it works.
The only check i used if the year > 2017.

Rodan's DS3231 library works well with ESP8266 and ESP32 also.
Another problem i found that the unixtime inside this library is not providing the same output (almost 14.7 year the difference) as the ESPEasy maketime() function, so i use the latter.
update: after reboot the ESP32 did not find anything on I2C bus, and of course, rtc chip can not be accessed. if i power cycle it, than it works again. maybe there are some problems in the ESP32 I2C library? with esp8266 there are no such problems.
Re: Maintain date and time in the absence of wifi
Yep, major I2C issues on ESP32 .
That's the main reason that platform hasn't gotten the attention it deserved.
Re: Maintain date and time in the absence of wifi
Thank you for the tip.
I tried, and now i think it works on ESP32. Not sure how stable it is, sometimes the temperature returns -0.25celsius at startup, but the next read it returns normally. The time can be read and write to the DS3231, and it also works after reboot.
https://github.com/enesbcs/ESPEasyPlugi ... DS3231.ino
I borrowed the idea from the DS18B20 plugin "portENTER_CRITICAL" seems to solve timing problems, not sure how it affects other devices...
My timer based ESP32 controlled relay project got another boost.

(DS3231 ensures that time remains after reboot and without network connection)
- Attachments
-
- esp32_ds3231.jpg (110.86 KiB) Viewed 55033 times
Re: Maintain date and time in the absence of wifi
any possibility to make plugin for ds1307 ?
hardware can be purchased cheap at aliexpress
https://www.aliexpress.com/item/Integra ... autifyAB=0
hardware can be purchased cheap at aliexpress
https://www.aliexpress.com/item/Integra ... autifyAB=0
Re: Maintain date and time in the absence of wifi
I ordered one ds1307 for trying, and i will tell. In fact, the ds3231 code _should_ work basicly for the 1307. Except, that 1307 does not support either ALARM, nor TEMPERATURE function.dony71 wrote: ↑21 Sep 2018, 01:04 any possibility to make plugin for ds1307 ?
hardware can be purchased cheap at aliexpress
https://www.aliexpress.com/item/Integra ... autifyAB=0
Re: Maintain date and time in the absence of wifi
I've got a faulty ds1307 - at least when i plugged in a 3V cr1220 battery, i only measured 0,4V.. and of course after power cycling the unit, time is lost. So i ordered another one.

- budman1758
- Normal user
- Posts: 303
- Joined: 15 Apr 2017, 05:13
- Location: Riverside CA USA
Re: Maintain date and time in the absence of wifi
Would it be possible for you to make a bin file with this plugin in it? I have not mastered the self compile thing as of yet. Preferably a 4 meg version. If you don't have somewhere to put it for download I can set up an FTP account for you. Thanks in advance.enesbcs wrote: ↑09 Sep 2018, 18:42 I'm just finished a test version of my DS3231 plugin. It keeps time when power down, even without NTP server, and shows temperature information, the latter is new to me. I struggled a little with timezones when updating from ntp to rtc, but now i think it is working.
Alarm mode works in theory, but it is low level active, so pullup needed on the other side, i am curious how can you use it for deep sleep.
https://github.com/enesbcs/ESPEasyPlugi ... DS3231.ino
It disables NTP through "Settings.UseNTP" so any functions that depends on it - such as "Local Time" on main page, and several Clock plugins WILL NOT WORK! And i did not see any solution without modifing the current ESPEasy core functions... Rules / Clock#Time will work, and system values like %syshour% may work.
"The glass is twice as big as it needs to be".
Re: Maintain date and time in the absence of wifi
Yes of course i can compile a 4M version, but are there any other plugin that you need?budman1758 wrote: ↑07 Oct 2018, 04:53 Would it be possible for you to make a bin file with this plugin in it? I have not mastered the self compile thing as of yet. Preferably a 4 meg version. If you don't have somewhere to put it for download I can set up an FTP account for you. Thanks in advance.
I am using only a subset of the available plugins, my version is attached.
- Attachments
-
- ESPEasy_ds3231_4M_241.zip
- ESPEasy with DS3231-4M-core 2.4.1
- (496.9 KiB) Downloaded 1191 times
- budman1758
- Normal user
- Posts: 303
- Joined: 15 Apr 2017, 05:13
- Location: Riverside CA USA
Re: Maintain date and time in the absence of wifi
Thanks. At the moment I don't see anything missing that I would need.
My project idea is some battery powered, solar recharged remote soil moisture sensors.
The idea is if they only wake up say every 3 to 4 hours they could probably run indefinitely. (Maybe?)


"The glass is twice as big as it needs to be".
- budman1758
- Normal user
- Posts: 303
- Joined: 15 Apr 2017, 05:13
- Location: Riverside CA USA
Re: Maintain date and time in the absence of wifi
Finally got around to testing my setup with this plugin. I have a couple things that are a bit fuzzy though.
The RTC module seems to be working as it should. The alarm function is one of the things I was most interested in and its working but not as I expected it to.
I was under the impression that the alarm trigger was an active low momentary pulse.
What I seem to be getting is a very low voltage that stays there until the ESP "tells" it to go off.
The RTC module seems to have a pullup resistor keeping the INT/SQW at 3.3 volts.
When the alarm time occurs the INT/SQW pin goes to about .035 volts and stays there until I assume its reset by the ESP.
The idea is the alarm pin pulses the RST pin on the ESP to wake it. Because the pin does not go low and back to high the ESP does not reset and wake up.
I have to momentarily ground the ESP RST pin to wake it. Only then does the INT/SQW pin on the RTC reset to 3.3 volts.
Looking at the DS3231 datasheet I get the impression there are 2 output modes for the INT/SQW pin.
I "think" it is outputting the square wave version instead of an interrupt version.
Wondering if I am all wet here and need some special circuitry here or what.
Thanks for any info.
Not sure if this is the best place for this or to start a new topic.
The RTC module seems to be working as it should. The alarm function is one of the things I was most interested in and its working but not as I expected it to.
I was under the impression that the alarm trigger was an active low momentary pulse.
What I seem to be getting is a very low voltage that stays there until the ESP "tells" it to go off.
The RTC module seems to have a pullup resistor keeping the INT/SQW at 3.3 volts.
When the alarm time occurs the INT/SQW pin goes to about .035 volts and stays there until I assume its reset by the ESP.
The idea is the alarm pin pulses the RST pin on the ESP to wake it. Because the pin does not go low and back to high the ESP does not reset and wake up.
I have to momentarily ground the ESP RST pin to wake it. Only then does the INT/SQW pin on the RTC reset to 3.3 volts.
Looking at the DS3231 datasheet I get the impression there are 2 output modes for the INT/SQW pin.
I "think" it is outputting the square wave version instead of an interrupt version.
Wondering if I am all wet here and need some special circuitry here or what.
Thanks for any info.
Not sure if this is the best place for this or to start a new topic.
"The glass is twice as big as it needs to be".
Re: Maintain date and time in the absence of wifi
I think you can see the problem now. In alarm mode, there are no wave output. I am also curious for the solution because i have very little knowledge in electronics. There are a RST pin on the DS3231 also that can be pulled to low, after the INT pin went LOW.. maybe with placing a capacitor between them? Just guessing, and assuming that the resetting of the DS3231 clears alarm state...budman1758 wrote: ↑15 Oct 2018, 23:27 The idea is the alarm pin pulses the RST pin on the ESP to wake it. Because the pin does not go low and back to high the ESP does not reset and wake up.
I have to momentarily ground the ESP RST pin to wake it. Only then does the INT/SQW pin on the RTC reset to 3.3 volts.
Looking at the DS3231 datasheet I get the impression there are 2 output modes for the INT/SQW pin.
I "think" it is outputting the square wave version instead of an interrupt version.
- budman1758
- Normal user
- Posts: 303
- Joined: 15 Apr 2017, 05:13
- Location: Riverside CA USA
Re: Maintain date and time in the absence of wifi
I am fairly sure whats going on now after searching the web. There are definitely 2 output types for the alarm function.
Type 1 is an active low and the other is a square wave signal.
I think the current working with this plugin is a square wave output because instead of a zero volt reading on my meter I am getting about .34 volts which is not much but is definitely NOT zero.
It also stays there until the ESP resets it when it reboots. (which I have to do manually).
The other problem here is even if the output is zero voltage it would stay that way until the ESP resets the alarm flag in the RTC chip.
Problem with that is the ESP needs a short pulse on the RST pin to restart from sleep. If the RTC keeps the output low then the ESP cannot reset.
So what's needed is some circuit to create a short ground pulse when the RTC alarm fires.
Anybody have an idea for such a circuit?
Got a good bit of info from this link on the alarm functions...
https://gist.github.com/JChristensen/03 ... 0db5419213
Type 1 is an active low and the other is a square wave signal.
I think the current working with this plugin is a square wave output because instead of a zero volt reading on my meter I am getting about .34 volts which is not much but is definitely NOT zero.
It also stays there until the ESP resets it when it reboots. (which I have to do manually).
The other problem here is even if the output is zero voltage it would stay that way until the ESP resets the alarm flag in the RTC chip.
Problem with that is the ESP needs a short pulse on the RST pin to restart from sleep. If the RTC keeps the output low then the ESP cannot reset.
So what's needed is some circuit to create a short ground pulse when the RTC alarm fires.
Anybody have an idea for such a circuit?
Got a good bit of info from this link on the alarm functions...
https://gist.github.com/JChristensen/03 ... 0db5419213
"The glass is twice as big as it needs to be".
Re: Maintain date and time in the absence of wifi
Hi Guys,
This is right on the edge of my knowledge, but I wonder if something like this could give a suitable pulse to the esp?
http://www.electronics-base.com/general ... l/24-ne555
They are pretty cheap. Would need to think about and minimise the power draw though. Perhaps the esp could switch it off when it's done it's job??
HTH.
This is right on the edge of my knowledge, but I wonder if something like this could give a suitable pulse to the esp?
http://www.electronics-base.com/general ... l/24-ne555
They are pretty cheap. Would need to think about and minimise the power draw though. Perhaps the esp could switch it off when it's done it's job??
HTH.

- budman1758
- Normal user
- Posts: 303
- Joined: 15 Apr 2017, 05:13
- Location: Riverside CA USA
Re: Maintain date and time in the absence of wifi
I was looking at something along those lines also. I have some 555 chips. When I get some time I will do some experimenting.AndrewJ wrote: ↑16 Oct 2018, 09:01 Hi Guys,
This is right on the edge of my knowledge, but I wonder if something like this could give a suitable pulse to the esp?
http://www.electronics-base.com/general ... l/24-ne555
They are pretty cheap. Would need to think about and minimise the power draw though. Perhaps the esp could switch it off when it's done it's job??
HTH.![]()
I'm not sure if they will run at 3.3 volts tho.....
"The glass is twice as big as it needs to be".
Re: Maintain date and time in the absence of wifi
I just got a working DS1307 and succesfully tested with this plugin:
_P156_DS1307.ino
Precompiled binary (contains DS3231+DS1307 plugins also)
I am too lazy to merge with my DS3231 plugin... they are similar but not as similar, that i think first.
Re: Maintain date and time in the absence of wifi
I do not have new idea about deepsleep, but i think if you wish Forced Light-Sleep can be triggered by simple High or Low edge of a pin. It is now supported by WifiMan plugin. Of course this consumes a little more than deep sleep. (ModemSleep=15mA, LightSleep=0.4mA, DeepSleep=20uA)budman1758 wrote: ↑15 Oct 2018, 23:27 The idea is the alarm pin pulses the RST pin on the ESP to wake it. Because the pin does not go low and back to high the ESP does not reset and wake up.
I have to momentarily ground the ESP RST pin to wake it. Only then does the INT/SQW pin on the RTC reset to 3.3 volts.
-
- Normal user
- Posts: 11
- Joined: 27 Feb 2018, 15:30
Re: Maintain date and time in the absence of wifi
Hello there, I tried to download your Firmware file but looks like it is compiled for ESP 32. Would you be able to share the Firmware/Bin file for ESP8266 4M version?enesbcs wrote: ↑25 Oct 2018, 21:12I just got a working DS1307 and succesfully tested with this plugin:
_P156_DS1307.ino
Precompiled binary (contains DS3231+DS1307 plugins also)
I am too lazy to merge with my DS3231 plugin... they are similar but not as similar, that i think first.
I am been trying to pull my hairs off in compiling a version of EspEasy Mega with the RTC plugin for DS3231...Many Thanks
Re: Maintain date and time in the absence of wifi
This zip file contains a file named "ESPEasy_ds3231_4M_241.bin" I've uploaded it to a NodeMCU ESP8266 at my desk and the sysinfo says:tango156157 wrote: ↑09 Jan 2019, 15:51 Precompiled binary (contains DS3231+DS1307 plugins also)
Hello there, I tried to download your Firmware file but looks like it is compiled for ESP 32. Would you be able to share the Firmware/Bin file for ESP8266 4M version?
I am been trying to pull my hairs off in compiling a version of EspEasy Mega with the RTC plugin for DS3231...Many Thanks
Code: Select all
Build 20102 - Mega
Libraries ESP82xx Core 2_4_1, NONOS SDK 2.2.1(cfd48f3), LWIP: 2.0.3
GIT version (custom)
Plugins 52 [Normal] [Testing]
Build Md5 4d44355f4d44355f4d44355f4d44355f
Md5 check never mind.
Build time Oct 2 2018 21:07:00
ESP Chip ID 1153420 (0x11998C)
ESP Chip Freq: 80 MHz
ESP Board Name: ESP8266_GENERIC
Flash Chip ID Vendor: 0x20 Device: 0x4016
Flash Chip Real Size: 4096 kB
Flash IDE Size: 4096 kB
Flash IDE speed: 40 MHz
Flash IDE mode: DOUT
Flash Writes 1 daily / 1 boot
Sketch Size 757 kB (2312 kB free)
SPIFFS Size 934 kB (860 kB free)
-
- Normal user
- Posts: 11
- Joined: 27 Feb 2018, 15:30
Re: Maintain date and time in the absence of wifi
Great, thanks for your response Sir....I tried flashing my Wemos D1 Mini with the .BIN file and get below error in my console. Please can you advise what might be the problem?enesbcs wrote: ↑09 Jan 2019, 17:33This zip file contains a file named "ESPEasy_ds3231_4M_241.bin" I've uploaded it to a NodeMCU ESP8266 at my desk and the sysinfo says:tango156157 wrote: ↑09 Jan 2019, 15:51 Precompiled binary (contains DS3231+DS1307 plugins also)
Hello there, I tried to download your Firmware file but looks like it is compiled for ESP 32. Would you be able to share the Firmware/Bin file for ESP8266 4M version?
I am been trying to pull my hairs off in compiling a version of EspEasy Mega with the RTC plugin for DS3231...Many Thanks
So i doubt that it is an ESP32 binary...Code: Select all
Build 20102 - Mega Libraries ESP82xx Core 2_4_1, NONOS SDK 2.2.1(cfd48f3), LWIP: 2.0.3 GIT version (custom) Plugins 52 [Normal] [Testing] Build Md5 4d44355f4d44355f4d44355f4d44355f Md5 check never mind. Build time Oct 2 2018 21:07:00 ESP Chip ID 1153420 (0x11998C) ESP Chip Freq: 80 MHz ESP Board Name: ESP8266_GENERIC Flash Chip ID Vendor: 0x20 Device: 0x4016 Flash Chip Real Size: 4096 kB Flash IDE Size: 4096 kB Flash IDE speed: 40 MHz Flash IDE mode: DOUT Flash Writes 1 daily / 1 boot Sketch Size 757 kB (2312 kB free) SPIFFS Size 934 kB (860 kB free)
Code: Select all
INIT : Booting version: (custom) (ESP82xx Core 2_4_1, NONOS SDK 2.2.1(cfd48f3), LWIP: 2.0.3)
88 : INIT : Warm boot #6 - Restart Reason: External System
90 : FS : Mounting...
115 : FS : Mount successful, used 75802 bytes of 957314
121 : CRC : No program memory checksum found. Check output of crc2.py
Re: Maintain date and time in the absence of wifi
I am using nodemcuPyflasher for first uploading:tango156157 wrote: ↑09 Jan 2019, 18:03Great, thanks for your response Sir....I tried flashing my Wemos D1 Mini with the .BIN file and get below error in my console. Please can you advise what might be the problem?Code: Select all
Build time Oct 2 2018 21:07:00 ESP Chip ID 1153420 (0x11998C) ESP Chip Freq: 80 MHz ESP Board Name: ESP8266_GENERIC Flash Chip ID Vendor: 0x20 Device: 0x4016 Flash Chip Real Size: 4096 kB Flash IDE Size: 4096 kB Flash IDE speed: 40 MHz Flash IDE mode: DOUT Flash Writes 1 daily / 1 boot Sketch Size 757 kB (2312 kB free) SPIFFS Size 934 kB (860 kB free)
Code: Select all
INIT : Booting version: (custom) (ESP82xx Core 2_4_1, NONOS SDK 2.2.1(cfd48f3), LWIP: 2.0.3) 88 : INIT : Warm boot #6 - Restart Reason: External System 90 : FS : Mounting... 115 : FS : Mount successful, used 75802 bytes of 957314 121 : CRC : No program memory checksum found. Check output of crc2.py
Did you try to use DOUT mode for example a lower speed at 57600? If nothing helps check Erase flash: wipes all data

(erasing flash helps usually)
If not works, try to upload ANY ESPEasy 4MB image you wish, than if it starts you can change the firmware by OTA.
-
- Normal user
- Posts: 11
- Joined: 27 Feb 2018, 15:30
Re: Maintain date and time in the absence of wifi
Success! Thanks...i resorted to uploading a working 4M copy of the firmware and from there uploaded your BIN file. Thanks for all your help and suggestions.enesbcs wrote: ↑09 Jan 2019, 18:33I am using nodemcuPyflasher for first uploading:tango156157 wrote: ↑09 Jan 2019, 18:03Great, thanks for your response Sir....I tried flashing my Wemos D1 Mini with the .BIN file and get below error in my console. Please can you advise what might be the problem?Code: Select all
Build time Oct 2 2018 21:07:00 ESP Chip ID 1153420 (0x11998C) ESP Chip Freq: 80 MHz ESP Board Name: ESP8266_GENERIC Flash Chip ID Vendor: 0x20 Device: 0x4016 Flash Chip Real Size: 4096 kB Flash IDE Size: 4096 kB Flash IDE speed: 40 MHz Flash IDE mode: DOUT Flash Writes 1 daily / 1 boot Sketch Size 757 kB (2312 kB free) SPIFFS Size 934 kB (860 kB free)
Code: Select all
INIT : Booting version: (custom) (ESP82xx Core 2_4_1, NONOS SDK 2.2.1(cfd48f3), LWIP: 2.0.3) 88 : INIT : Warm boot #6 - Restart Reason: External System 90 : FS : Mounting... 115 : FS : Mount successful, used 75802 bytes of 957314 121 : CRC : No program memory checksum found. Check output of crc2.py
Did you try to use DOUT mode for example a lower speed at 57600? If nothing helps check Erase flash: wipes all data
(erasing flash helps usually)
If not works, try to upload ANY ESPEasy 4MB image you wish, than if it starts you can change the firmware by OTA.
Re: Maintain date and time in the absence of wifi
Hello,
I was never able to include ds3231 and wifiman into a build so thanks for the.bin
I need to adjust the clock with a button and I've created a rule but it doesn't work....can anybody help me please?
On button#1 do
setdate,%sysyear%,%sysmonth%,%sysday%,%syshour%+1,%sysmin%,%syssec%
endon
I've tried many ways and got stuck
I was never able to include ds3231 and wifiman into a build so thanks for the.bin
I need to adjust the clock with a button and I've created a rule but it doesn't work....can anybody help me please?
On button#1 do
setdate,%sysyear%,%sysmonth%,%sysday%,%syshour%+1,%sysmin%,%syssec%
endon
I've tried many ways and got stuck
Re: Maintain date and time in the absence of wifi
You have your event syntax confused, this should work (assuming you didn't change the Variables part on the button):
Code: Select all
on button#state=1 do
setdate,%sysyear%,%sysmonth%,%sysday%,%syshour%+1,%sysmin%,%syssec%
endon
/Ton (PayPal.me)
Re: Maintain date and time in the absence of wifi
Apologies for typo, event was ok. So my rule looks like your suggestion but output on the console is like a string eg:17+1 rather than 18
Re: Maintain date and time in the absence of wifi
Well, I've not used that kind of arithmetic, but possibly it should be like %syshour+1h%, like the %sunset-1h% and %sunrise+10m% examples on the System variables page.
/Ton (PayPal.me)
Re: Maintain date and time in the absence of wifi
Nope, those computations are for sunrise/sunset only.
%syshour% is returning an integer value, but I think you should do the computation first and assign the result to a variable first using "let" command
Then use that variable in your event.
Code: Select all
let,1,%syshour%+1
setdate,%sysyear%,%sysmonth%,%sysday%,%v1%,%sysmin%,%syssec%
Re: Maintain date and time in the absence of wifi
Hi,TD-er wrote: ↑19 Feb 2021, 11:11Nope, those computations are for sunrise/sunset only.
%syshour% is returning an integer value, but I think you should do the computation first and assign the result to a variable first using "let" command
Then use that variable in your event.
Code: Select all
let,1,%syshour%+1 setdate,%sysyear%,%sysmonth%,%sysday%,%v1%,%sysmin%,%syssec%
thank you so much for this advice. I'm sure this is the best way to go forward but I encounter another issue:
Code: Select all
4782281: EVENT: Time#Set
4782443: Command: let
4782444: Command unknown: 'let'
4782457: EVENT: Clock#Time=Thu,17:41
[code]
[code]
Build 20102 - Mega
Libraries ESP82xx Core 2_4_1, NONOS SDK 2.2.1(cfd48f3), LWIP: 2.0.3
GIT version (custom)
Plugins 52 [Normal] [Testing]
Build Md5 4d44355f4d44355f4d44355f4d44355f
Md5 check never mind.
Build time Oct 2 2018 21:07:00
Binary filename ThisIsTheDummyPlaceHolderForTheBinaryFilename64ByteLongFilenames
I have tried to compile myself using gitpod but I get all sorts of errors that are beyond my skills to fix. I couldn't find a tutorial on how to use it. So unless one of you amazing people will compile one for me a newer build with _P156_DS1307.ino,_P157_DS3231.ino,_P166_WiFiMan.ino, plugin 5, plugin 73,I will be stuck forever and my dad will be disappointed because his son failed a simple project.
Thank you so much again!
Re: Maintain date and time in the absence of wifi
Hmm this is a rather old build (over 2 years old)
I don't think setdate was already present then.
In other news... a more recent build also keeps the time stored in RTC memory, so as long as the unit remains powered, it will keep its time after a reboot or crash.
On average it will loose a bit over 1 second in accuracy between each reboot.
Another way to keep track of a correct time without ever seeing WiFi is to use a simple GPS module.
The GPS plugin does also set your system time. (when it got a valid time from the GPS module)
I don't think setdate was already present then.
In other news... a more recent build also keeps the time stored in RTC memory, so as long as the unit remains powered, it will keep its time after a reboot or crash.
On average it will loose a bit over 1 second in accuracy between each reboot.
Another way to keep track of a correct time without ever seeing WiFi is to use a simple GPS module.
The GPS plugin does also set your system time. (when it got a valid time from the GPS module)
Re: Maintain date and time in the absence of wifi
That build has plugin for DS1307 and DS3231, very cheap RTC. these plugins has the option to setdate and my only issue is to be able to store %syshour% and add 1.
let command was very promising but it wasn't implemented yet. i was trying to create a "device" that has formula tab inside and do a %value%+%syshour%+1.
if i do a setdate,2020,2,19,19,44,30 will work just fine or setdate,%sysyear%,%sysmonth%,%sysday%,%syshour%,5,%syssec% etc. only problem is the math side
let command was very promising but it wasn't implemented yet. i was trying to create a "device" that has formula tab inside and do a %value%+%syshour%+1.
if i do a setdate,2020,2,19,19,44,30 will work just fine or setdate,%sysyear%,%sysmonth%,%sysday%,%syshour%,5,%syssec% etc. only problem is the math side
Re: Maintain date and time in the absence of wifi
You can store it in a dummy task perhaps?
See TaskValueSet
See TaskValueSet
Re: Maintain date and time in the absence of wifi
All done and working now, here is my code in case anyone has use of it
Couldn't find a better compromise to reset to 0 without a big delay on adjusting time
Thank you!
Code: Select all
//Rule: "When System Boot"
on System#Boot do
TaskValueSet,11,1,%syshour% //dummy for hour
TaskValueSet,11,2,%sysmin% //dummy for min
endon
on Clock#Time do
timerSet,8,10
endon
on Rules#Timer=8 do
if [clock#hour]>=23
TaskValueSet,11,1,0 //dummy for hour reset to 0 if >=23
else
TaskValueSet,11,1,%syshour% //dummy for hour
endif
if [clock#minute]>=59
TaskValueSet,11,2,0 //dummy for min reset to 0 if >=59
else
TaskValueSet,11,2,%sysmin% //dummy for min
endif
endon
//Rules to change date and time with buttons
// set Hour with +1
on hour#state=1 do
TaskValueSet,11,1,[clock#hour]+1
setdate,%sysyear%,%sysmonth%,%sysday%,[clock#hour],%sysmin%,%syssec%
// let,1,%syshour%+1 //not working on this buid but working on newer ones
// setdate,%sysyear%,%sysmonth%,%sysday%,%v1%,%sysmin%,%syssec% //not working on this buid but working on newer ones
endon
// set Minute with +1
on minute#state=1 do
TaskValueSet,11,2,[clock#minute]+1
setdate,%sysyear%,%sysmonth%,%sysday%,%syshour%,[clock#minute],%syssec%
// let,2,%sysmin%+1 //not working on this buid but working on newer ones
// setdate,%sysyear%,%sysmonth%,%sysday%,%syshour%,%v2%,%syssec% //not working on this buid but working on newer ones
endon
Thank you!
Re: Maintain date and time in the absence of wifi
And the nice part is, as long as your unit remains powered, the dummy variable values will be preserved after a reboot/crash.
But I'm curious, to why you need to add an hour to the systime?
Why not use the time zone for this?
But I'm curious, to why you need to add an hour to the systime?
Why not use the time zone for this?
Re: Maintain date and time in the absence of wifi
because the unit does not have access to wifi unless it's a hassle and when I do, I couldn't figure out the daytime saving to work properly and time gets set 1h + or -
also power loss can be very frequent(that's why I set dummys at the boot) and only way to remember was DS3231 as gps modules are big+antena.
also power loss can be very frequent(that's why I set dummys at the boot) and only way to remember was DS3231 as gps modules are big+antena.
Re: Maintain date and time in the absence of wifi
DS3231 support added to mPyEasy. Although it will only support ESP32 as ESP8266 has no remarkable memory to run micropython.Eugraf wrote: ↑19 Feb 2021, 17:37 I have tried to compile myself using gitpod but I get all sorts of errors that are beyond my skills to fix. I couldn't find a tutorial on how to use it. So unless one of you amazing people will compile one for me a newer build with _P156_DS1307.ino,_P157_DS3231.ino,_P166_WiFiMan.ino, plugin 5, plugin 73,I will be stuck forever and my dad will be disappointed because his son failed a simple project.
Thank you so much again!

Who is online
Users browsing this forum: Bing [Bot] and 13 guests