Maintain date and time in the absence of wifi

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
callkalpa
New user
Posts: 2
Joined: 07 Jul 2018, 06:30

Maintain date and time in the absence of wifi

#1 Post by callkalpa » 07 Jul 2018, 06:42

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.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Maintain date and time in the absence of wifi

#2 Post by TD-er » 09 Jul 2018, 23:54

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.

callkalpa
New user
Posts: 2
Joined: 07 Jul 2018, 06:30

Re: Maintain date and time in the absence of wifi

#3 Post by callkalpa » 10 Jul 2018, 04:05

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.

User avatar
enesbcs
Normal user
Posts: 587
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: Maintain date and time in the absence of wifi

#4 Post by enesbcs » 10 Jul 2018, 07:22

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.

User avatar
budman1758
Normal user
Posts: 301
Joined: 15 Apr 2017, 05:13
Location: Riverside CA USA

Re: Maintain date and time in the absence of wifi

#5 Post by budman1758 » 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. :mrgreen: :mrgreen:
"The glass is twice as big as it needs to be".

User avatar
enesbcs
Normal user
Posts: 587
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: Maintain date and time in the absence of wifi

#6 Post by enesbcs » 09 Sep 2018, 18:42

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. :mrgreen: :mrgreen:
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.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Maintain date and time in the absence of wifi

#7 Post by TD-er » 09 Sep 2018, 22:20

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.

User avatar
enesbcs
Normal user
Posts: 587
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: Maintain date and time in the absence of wifi

#8 Post by enesbcs » 10 Sep 2018, 19:52

TD-er wrote: 09 Sep 2018, 22:20 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.
Thank you. I just tested it with ESPEasy32, it works.
The only check i used if the year > 2017. :) Build time comparison is a nice idea.
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.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Maintain date and time in the absence of wifi

#9 Post by TD-er » 10 Sep 2018, 21:15

enesbcs wrote: 10 Sep 2018, 19:52 [...]
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.
Yep, major I2C issues on ESP32 .
That's the main reason that platform hasn't gotten the attention it deserved.

User avatar
enesbcs
Normal user
Posts: 587
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: Maintain date and time in the absence of wifi

#10 Post by enesbcs » 13 Sep 2018, 18:43

TD-er wrote: 10 Sep 2018, 21:15 Yep, major I2C issues on ESP32 .
That's the main reason that platform hasn't gotten the attention it deserved.
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. :) Testing in progress.
(DS3231 ensures that time remains after reboot and without network connection)
Attachments
esp32_ds3231.jpg
esp32_ds3231.jpg (110.86 KiB) Viewed 29731 times

dony71
Normal user
Posts: 16
Joined: 25 Apr 2018, 20:01

Re: Maintain date and time in the absence of wifi

#11 Post by dony71 » 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

User avatar
enesbcs
Normal user
Posts: 587
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: Maintain date and time in the absence of wifi

#12 Post by enesbcs » 21 Sep 2018, 09:40

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
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.

User avatar
enesbcs
Normal user
Posts: 587
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: Maintain date and time in the absence of wifi

#13 Post by enesbcs » 06 Oct 2018, 19:06

dony71 wrote: 21 Sep 2018, 01:04 any possibility to make plugin for ds1307 ?
hardware can be purchased cheap at aliexpress
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. :(

User avatar
budman1758
Normal user
Posts: 301
Joined: 15 Apr 2017, 05:13
Location: Riverside CA USA

Re: Maintain date and time in the absence of wifi

#14 Post by budman1758 » 07 Oct 2018, 04:53

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.
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.
"The glass is twice as big as it needs to be".

User avatar
enesbcs
Normal user
Posts: 587
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: Maintain date and time in the absence of wifi

#15 Post by enesbcs » 07 Oct 2018, 08:39

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.
Yes of course i can compile a 4M version, but are there any other plugin that you need?
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 576 times

User avatar
budman1758
Normal user
Posts: 301
Joined: 15 Apr 2017, 05:13
Location: Riverside CA USA

Re: Maintain date and time in the absence of wifi

#16 Post by budman1758 » 08 Oct 2018, 07:00

enesbcs wrote: 07 Oct 2018, 08:39 Yes of course i can compile a 4M version, but are there any other plugin that you need?
I am using only a subset of the available plugins, my version is attached.
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".

User avatar
budman1758
Normal user
Posts: 301
Joined: 15 Apr 2017, 05:13
Location: Riverside CA USA

Re: Maintain date and time in the absence of wifi

#17 Post by budman1758 » 15 Oct 2018, 23:27

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 glass is twice as big as it needs to be".

User avatar
enesbcs
Normal user
Posts: 587
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: Maintain date and time in the absence of wifi

#18 Post by enesbcs » 15 Oct 2018, 23:37

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.
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...

User avatar
budman1758
Normal user
Posts: 301
Joined: 15 Apr 2017, 05:13
Location: Riverside CA USA

Re: Maintain date and time in the absence of wifi

#19 Post by budman1758 » 16 Oct 2018, 01:42

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
"The glass is twice as big as it needs to be".

AndrewJ
Normal user
Posts: 229
Joined: 14 Feb 2017, 12:38

Re: Maintain date and time in the absence of wifi

#20 Post by AndrewJ » 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. :)

User avatar
budman1758
Normal user
Posts: 301
Joined: 15 Apr 2017, 05:13
Location: Riverside CA USA

Re: Maintain date and time in the absence of wifi

#21 Post by budman1758 » 16 Oct 2018, 19:20

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 was looking at something along those lines also. I have some 555 chips. When I get some time I will do some experimenting.
I'm not sure if they will run at 3.3 volts tho.....
"The glass is twice as big as it needs to be".

User avatar
enesbcs
Normal user
Posts: 587
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: Maintain date and time in the absence of wifi

#22 Post by enesbcs » 25 Oct 2018, 21:12

dony71 wrote: 21 Sep 2018, 01:04 any possibility to make plugin for ds1307 ?
hardware can be purchased cheap at aliexpress
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.

User avatar
enesbcs
Normal user
Posts: 587
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: Maintain date and time in the absence of wifi

#23 Post by enesbcs » 03 Nov 2018, 11:26

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.
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)

tango156157
Normal user
Posts: 11
Joined: 27 Feb 2018, 15:30

Re: Maintain date and time in the absence of wifi

#24 Post by tango156157 » 09 Jan 2019, 15:51

enesbcs wrote: 25 Oct 2018, 21:12
dony71 wrote: 21 Sep 2018, 01:04 any possibility to make plugin for ds1307 ?
hardware can be purchased cheap at aliexpress
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.
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

User avatar
enesbcs
Normal user
Posts: 587
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: Maintain date and time in the absence of wifi

#25 Post by enesbcs » 09 Jan 2019, 17:33

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
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:

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)
So i doubt that it is an ESP32 binary...

tango156157
Normal user
Posts: 11
Joined: 27 Feb 2018, 15:30

Re: Maintain date and time in the absence of wifi

#26 Post by tango156157 » 09 Jan 2019, 18:03

enesbcs wrote: 09 Jan 2019, 17:33
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
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:

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)
So i doubt that it is an ESP32 binary...
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?

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

User avatar
enesbcs
Normal user
Posts: 587
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: Maintain date and time in the absence of wifi

#27 Post by enesbcs » 09 Jan 2019, 18:33

tango156157 wrote: 09 Jan 2019, 18:03

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)
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?

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
I am using nodemcuPyflasher for first uploading:
Did you try to use DOUT mode for example a lower speed at 57600? If nothing helps check Erase flash: wipes all data
Image
(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.

tango156157
Normal user
Posts: 11
Joined: 27 Feb 2018, 15:30

Re: Maintain date and time in the absence of wifi

#28 Post by tango156157 » 10 Jan 2019, 14:56

enesbcs wrote: 09 Jan 2019, 18:33
tango156157 wrote: 09 Jan 2019, 18:03

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)
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?

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
I am using nodemcuPyflasher for first uploading:
Did you try to use DOUT mode for example a lower speed at 57600? If nothing helps check Erase flash: wipes all data
Image
(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.
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.

Eugraf
New user
Posts: 6
Joined: 19 Feb 2021, 08:50

Re: Maintain date and time in the absence of wifi

#29 Post by Eugraf » 19 Feb 2021, 08:55

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

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Maintain date and time in the absence of wifi

#30 Post by Ath » 19 Feb 2021, 09:08

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)

Eugraf
New user
Posts: 6
Joined: 19 Feb 2021, 08:50

Re: Maintain date and time in the absence of wifi

#31 Post by Eugraf » 19 Feb 2021, 09:25

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

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Maintain date and time in the absence of wifi

#32 Post by Ath » 19 Feb 2021, 10:50

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)

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Maintain date and time in the absence of wifi

#33 Post by TD-er » 19 Feb 2021, 11:11

Ath wrote: 19 Feb 2021, 10:50 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.
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%

Eugraf
New user
Posts: 6
Joined: 19 Feb 2021, 08:50

Re: Maintain date and time in the absence of wifi

#34 Post by Eugraf » 19 Feb 2021, 17:37

TD-er wrote: 19 Feb 2021, 11:11
Ath wrote: 19 Feb 2021, 10:50 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.
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%
Hi,
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 believe this command wasn't available at the time when this build was made
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!

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Maintain date and time in the absence of wifi

#35 Post by TD-er » 19 Feb 2021, 20:25

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)

Eugraf
New user
Posts: 6
Joined: 19 Feb 2021, 08:50

Re: Maintain date and time in the absence of wifi

#36 Post by Eugraf » 19 Feb 2021, 20:45

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

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Maintain date and time in the absence of wifi

#37 Post by TD-er » 20 Feb 2021, 02:19

You can store it in a dummy task perhaps?
See TaskValueSet

Eugraf
New user
Posts: 6
Joined: 19 Feb 2021, 08:50

Re: Maintain date and time in the absence of wifi

#38 Post by Eugraf » 20 Feb 2021, 11:16

All done and working now, here is my code in case anyone has use of it

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
Couldn't find a better compromise to reset to 0 without a big delay on adjusting time
Thank you!

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Maintain date and time in the absence of wifi

#39 Post by TD-er » 20 Feb 2021, 11:23

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?

Eugraf
New user
Posts: 6
Joined: 19 Feb 2021, 08:50

Re: Maintain date and time in the absence of wifi

#40 Post by Eugraf » 20 Feb 2021, 12:21

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.

User avatar
enesbcs
Normal user
Posts: 587
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: Maintain date and time in the absence of wifi

#41 Post by enesbcs » 20 Feb 2021, 16:54

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!
DS3231 support added to mPyEasy. Although it will only support ESP32 as ESP8266 has no remarkable memory to run micropython.
Image

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 24 guests