B4R Library TimeTools Library with NTP Time

Hello,

here is my first attempt to write a lib for B4R ;)

The Lib based on the following Libraries (you have to install this bevor you can use this lib):

https://github.com/aharshac/EasyNTPClient
https://github.com/PaulStoffregen/Time

for me it works fine in combination with the Software Real Time Clock https://www.b4x.com/android/forum/threads/software-real-time-clock.77158/#post-530071

i have Testet with the ESP8266 board

regards

Andy



B4X:
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 300
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public Serial1 As Serial
    Public timelib As ESPTimetools
    Public wifi As ESP8266WiFi
    Public timestamp As ULong
End Sub

' based on the following Libraries:
' https://github.com/aharshac/EasyNTPClient
' https://github.com/PaulStoffregen/Time

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    wifi.Connect2("insert your wifi id","insert your wifi password")
    timelib.initialize("pool.ntp.org",3600) 'UTC(1) = MEZ
    timestamp=timelib.timestamp
    If timestamp <> 0 Then
        Log ("Timestamp is:", timestamp)
        If (timelib.issummertime_eu(timelib.getyear(timestamp),timelib.getmonth(timestamp),timelib.getday(timestamp),timelib.gethour(timestamp),1))=True Then
            timestamp=timestamp+3600 'UTC(1) = MEZ +3600sec (1hour) = MESZ
            Log ("it is summertime")
        Else
            Log ("it is wintertime")
        End If
        Log("Seconds ",timelib.getseconds(timestamp))
        Log("minute ",timelib.getminute(timestamp))
        Log("hour ",timelib.gethour(timestamp))
        Log("weekday ",timelib.getweekday(timestamp))
        Log("day ",timelib.getday(timestamp))
        Log("month ",timelib.getmonth(timestamp))
        Log("year ",timelib.getyear(timestamp))
        Log("hour12 ",timelib.gethour12(timestamp))
        Log("Is AM ",timelib.isam(timestamp))
        Log("Is PM ",timelib.ispm(timestamp))
    
        ' date & time formatet
        Log("Date: ",NumberFormat(timelib.getday(timestamp),2,0),".",NumberFormat(timelib.getmonth(timestamp),2,0),".",timelib.getyear(timestamp))
        Log("Time: ",NumberFormat(timelib.gethour(timestamp),2,0),":",NumberFormat(timelib.getminute(timestamp),2,0),":",NumberFormat(timelib.getseconds(timestamp),2,0))
    Else
        Log ("error: can't get time data from server")
    End If   
End Sub
 

Attachments

  • rESP8266TimeTools.zip
    2.7 KB · Views: 634

Robert Valentino

Well-Known Member
Licensed User
Longtime User
I needed the # Days in the month so I could calculate holidays like Memorial Day, Thanksgiving, etc

This value was in Time.c but never saved in the the time structure.

I modified the Time-Master and rESP8266TimeTools to support this.

B4X:
                  Log("Days In Month:", mTimelib.getdaysinmonth(mTimestamp))
 

Attachments

  • TimeChanges.zip
    33 KB · Views: 473

jwgf

Member
Sorry, but I do not understand, if I run out of Wi-Fi for a few minutes the clock keeps ticking and you can check the time, how?
 
Top