** Now also supports ESP-32 modules **
I created this library as a software based Real Time Clock.
You don't need any additional hardware modules.
It does NOT run any special background code to keep the RTC alive.
It can generate Alarm Events at required Date/Times.
It can be calibrated from your own web based internet UTC time source using it's built in GetUTC function. (see post #7)
It also contains several functions to simplify the manipulation of date/times as seconds.
It gets it's timing by calibrating the millis() function available from Arduino.
Generated Alarm Events are managed by the B4R Scheduler class.
Notes: My testing over several days showed a loss of 1 to 2 sec per day. The RTC could be set (SetClock) every week or so from the GetUTC() function if it is required to maintain accuracy. As the Arduino Millis() function can only count continuously for about 40days the RTC should be set at least once a month.
Now updated to v1.05
See post below for details.
I created this library as a software based Real Time Clock.
You don't need any additional hardware modules.
It does NOT run any special background code to keep the RTC alive.
It can generate Alarm Events at required Date/Times.
It can be calibrated from your own web based internet UTC time source using it's built in GetUTC function. (see post #7)
It also contains several functions to simplify the manipulation of date/times as seconds.
It gets it's timing by calibrating the millis() function available from Arduino.
Generated Alarm Events are managed by the B4R Scheduler class.
B4X:
#Region Project Attributes
#AutoFlushLogs: True
#CheckArrayBounds: True
#StackBufferSize: 300
#End Region
Sub Process_Globals
Public Serial1 As Serial
Private wifi As ESP8266WiFi
Private DT(8) As Byte
Private rtc As ESP8266rtc
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
If wifi.Connect2("your ssid","your password") Then 'change to your network SSID (use Connect2 if a password is required).
Log("Connected to wireless network.")
rtc.Initialize("rtc_Alarm",True)
'I have provided my own "url.php" as an example only.
'you must create your own as per the details in the post for v1-04
err = rtc.GetUTC(DT,"www.starchild.com.au","/utc.php"))
If err <> 0 Then
Log("GetUTC failed: ",err)
End If
rtc.SetClock(DT,8,0) 'offset for Western Australia. UTC +08:00
Log(rtc.ReadClock(DT))
Log("RTC: ",DT(0),",",DT(1),",",DT(2),",",DT(3),",",DT(4),",",DT(5),",",DT(6),",",DT(7))
rtc.SetAlarm(1,rtc.Sec2DT(rtc.DT2Sec(DT)+10))
rtc.SetAlarm(2,rtc.Sec2DT(rtc.DT2Sec(DT)+5))
rtc.SetAlarm(3,rtc.Sec2DT(rtc.DT2Sec(DT)+15))
rtc.SetAlarm(9,rtc.Sec2DT(rtc.DT2Sec(DT+rtc.SECONDS_1MINUTE))
rtc.SetAlarm(5,rtc.ThisTime(6,30,0)) 'set alarm for 6:30am (within the next 24hrs)
Else
Log("Failed to connect.")
End If
End Sub
private Sub rtc_Alarm(index As Byte)
If index=0 Then
'tick every second
rtc.ReadClock(DT)
Log("RTC: ",rtc.ShortDOW(DT),", ",rtc.ShortDate(DT),", ",rtc.Time24(DT))
Return
End If
Log("AlarmEvent: ",index)
End Sub
Notes: My testing over several days showed a loss of 1 to 2 sec per day. The RTC could be set (SetClock) every week or so from the GetUTC() function if it is required to maintain accuracy. As the Arduino Millis() function can only count continuously for about 40days the RTC should be set at least once a month.
Now updated to v1.05
See post below for details.
Attachments
Last edited: