B4R Question Read NIST server time

Erel

B4X founder
Staff member
Licensed User
Longtime User
Works fine here. Tested with ESP32:
B4X:
AppStart
Connected: 1
Connecting to NIST server...
Failed to connect to NIST server
Connecting to NIST server...
Failed to connect to NIST server
Connecting to NIST server...
Date: 25-05-18
Time (UTC): 05:15:41
Date: 25-05-18
Time (UTC): 05:15:42
Date: 25-05-18
Time (UTC): 05:15:43
Date: 25-05-18
Time (UTC): 05:15:44
Date: 25-05-18
Time (UTC): 05:15:45
Date: 25-05-18
Time (UTC): 05:15:46
Date: 25-05-18
Time (UTC): 05:15:47
Date: 25-05-18
Time (UTC): 05:15:48
Date: 25-05-18
Time (UTC): 05:15:49
Date: 25-05-18
Time (UTC): 05:15:50
Date: 25-05-18
Time (UTC): 05:15:51
Date: 25-05-18
Time (UTC): 05:15:52
Date: 25-05-18
Time (UTC): 05:15:53
Date: 25-05-18
Time (UTC): 05:15:54
Date: 25-05-18
Time (UTC): 05:15:55
Date: 25-05-18
Time (UTC): 05:15:56
Date: 25-05-18
Time (UTC): 05:15:57
Date: 25-05-18
Time (UTC): 05:15:58
Date: 25-05-18
Time (UTC): 05:15:59

Which error do you get?
 
Upvote 0

Gerardo Tenreiro

Active Member
Licensed User
Good morning
If you check the ERROR routine, you'll see that it's triggered every NIST read cycle.

Nist.Initialize(socket.Stream, "NIST_NewData", "NIST_Error")
Nist_NewData is triggered with the NIST values, but NIST_ERROR is also triggered.

Checking my application, when I get a NIST error, I re-issue the request and overload the application.
I took measures in my application to not request NIST again before a minute has passed, but I still get the error response in "Nist_Error".

Thank you, and if you can fix this minor issue, I'd appreciate it.

Congratulations on your great work.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Are you referring to this sub:
B4X:
Private Sub AStream_Error
    'Log("Disconnected")
End Sub
It is expected to be raised when the connection is closed. TimeNIST will try to reconnect after 1 second if it failed to connect:
B4X:
Private Sub Connect(u As Byte)
    Log("Connecting to NIST server...")
    If socket.ConnectHost("time.nist.gov", 13) Then
        astream.Initialize(socket.Stream, "astream_NewData", "astream_Error")
    Else
        Log("Failed to connect to NIST server")
        CallSubPlus("Connect", 1000, 0)
    End If
End Sub

You don't need to change anything...
 
Upvote 0

Gerardo Tenreiro

Active Member
Licensed User
If I'm referring to that "Private Sub AStream_Error" module, it always runs whether or not you connect to NIST.

This application uses Wi-Fi and Bluetooth, but not simultaneously, of course.
Every so often, the application turns on Wi-Fi, connects to the NIST server, takes the date and time, and sends information to a data server using PUT and GET.
After a while, the application activates Bluetooth and waits for the connection. If they connect via Bluetooth, it remains connected, and when the time has passed, it reconnects to Bluetooth and repeats the process.
This is the module that performs this operation.


The application is currently running on more than 500 devices, and everything is correct. My client continues to request modules, and at some point, I will have to make some changes, so it's very important to be able to make changes and keep everything working.

The problem is that my hard drive stopped working, so I reinstalled Windows 10, along with all the programs.
I have backups of all the applications, several from different times.

This application was created in 2021 with ESP32 3.0.7, and now the only thing I changed was to ESP32 3.2.0, and the application doesn't work properly.

I've checked everything; if I load version 3.0.7, the application works correctly.

Any suggestions?

Thank you very much.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…