Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Time sync Node-RED server. #625

Closed
RobMBSos opened this issue Aug 20, 2020 · 20 comments
Closed

Time sync Node-RED server. #625

RobMBSos opened this issue Aug 20, 2020 · 20 comments

Comments

@RobMBSos
Copy link

I am trying to sync time via NODE-RED timesync server but with M5core and Lopy4 I can't get it work.
I have configured NODE-RED as example described in readme and configured MQTT to point to AppID/devices/DeviceID/up
I send a downlink to Port 2 with 87 as message and module receives it:
][senddata.cpp:113] sendData(): Counter cleared [D][lorawan.cpp:472] myEventCallback(): TXSTART [I][lorawan.cpp:266] lora_send(): 4 byte(s) sent to LORA [D][lorawan.cpp:472] myEventCallback(): RXSTART [I][lorawan.cpp:510] myRxCallback(): Received 1 byte(s) of payload on port 2 [I][rcommand.cpp:332] set_time(): Timesync requested by timeserver [D][lorawan.cpp:472] myEventCallback(): TXCOMPLETE
but nothing is happening. I have tried with:
#define TIME_SYNC_LORAWAN 0 // set to 1 to use LORA network as time source, 0 means off [default = 1] #define TIME_SYNC_LORASERVER 1 /
and with:
#define TIME_SYNC_LORAWAN 1 // set to 1 to use LORA network as time source, 0 means off [default = 1] #define TIME_SYNC_LORASERVER 0 /

What I am doing wrong? Is there any bugs with NODE-RED time server?
Thanks in advance.

@FlorianLudwig
Copy link
Collaborator

FlorianLudwig commented Aug 20, 2020

Hi @TheHysiK ,

do you see any messages on node-red? You can add debug nodes there to get messages printed inside a console.

Maybe you can add a screenshot from the ttn console, which downlink/uplink messages where seen by the network?

@RobMBSos
Copy link
Author

Hi @FlorianLudwig thanks for your comment.
I have attached 3 images:
https://imgur.com/a/VA8FNi6
No debug message is shown at NODE-RED, if I add one at uplink I see message received by TTN with WIFI and BLE counters but no response of downlink message.

@FlorianLudwig
Copy link
Collaborator

Hey @TheHysiK
I just noticed you used
TIME_SYNC_LORAWAN
Which uses the lorawan mac commands to get the time. This does not interact with the node-red server at all.

TIME_SYNC_LORASERVER is for the node-red server. The only reason to use this is if you need higher (sub second) precision.

@RobMBSos
Copy link
Author

@FlorianLudwig I have tested with both of them; in the images I was using TIME_SYNC_LORASERVER 1 so I guess that could not be the problem at all.

@cyberman54
Copy link
Owner

@TheHysiK Please check, that TTN downlinks are working with your setup. Working downlink is required for time sync protocol via node red.

While you're sure that your downlinks are working, but your node does not sync time, probably no timesync packet was sent by the node red timeserver. Mostly this happenes, if the node's timesync request is received via a TTN gateway that does not provide time.

Check in your TTN console in your application, if there is a field "time" (not: "timestamp") with a valid and precise time. Precise means, that there must be a microsecond fraction, marked by "Z".

If the gateway, which delivers the payload from/to your node, does not provide a time, or does provide a time but without microseconds, the node red time server will not work. Move to another gateway then, or try another brand of gateway. The TTN TTIG does provide microseconds.

If you find that your gateway is the reason, please close this issue, since it's not a failure related to this software. Thanks.

@RobMBSos
Copy link
Author

RobMBSos commented Aug 21, 2020

Hi @cyberman54 !
I am testing right now, I have checked with 2 gateways and tested with one Indoor TTN gateway.
Here are the images: https://imgur.com/a/TLIjzJ6
With TTN gateway I sent to port 2 87 and it receives but it does not start the process of time sync in Node-red.

EDIT: Fixed URL.

@cyberman54
Copy link
Owner

cyberman54 commented Aug 21, 2020

@TheHysiK Your link doesn't work.

Anyway, check your Node red server:

  • Nodes "listen" and "send" must show "connected"
  • Below of node "Timeserver Gw" you should see EIU of last time serving gateway. If not, there ist no gateway in range which does provide precise time, thus time sync cannot work.

@RobMBSos
Copy link
Author

RobMBSos commented Aug 23, 2020

@TheHysiK Your link doesn't work.

Anyway, check your Node red server:

  • Nodes "listen" and "send" must show "connected"
  • Below of node "Timeserver Gw" you should see EIU of last time serving gateway. If not, there ist no gateway in range which does provide precise time, thus time sync cannot work.

@cyberman54
Nodes are connected.
Timeserver GW debug message does not show any message. But as I already showed Gateway have time with microsecond.
I fixed url, please check when you are able.

@cyberman54
Copy link
Owner

@TheHsyik your screenshot show 3 different gateways, but only 1 of 3, the TTIG, provides absolute time. For syncing time you need to make sure, that the time sync request of the node is delivered by the TTIG, not by the other gateways.

@RobMBSos
Copy link
Author

@TheHsyik your screenshot show 3 different gateways, but only 1 of 3, the TTIG, provides absolute time. For syncing time you need to make sure, that the time sync request of the node is delivered by the TTIG, not by the other gateways.

Hi @cyberman54 I understand that, I did all the test with that gateway and no other in range of the node, nothing happened.
Regards.

@cyberman54
Copy link
Owner

please write serial log with debug level 4 and post it here.

@RobMBSos
Copy link
Author

please write serial log with debug level 4 and post it here.

I checked it and it already was with Debug level 4, this is the code when Timesync is received:
][senddata.cpp:113] sendData(): Counter cleared [D][lorawan.cpp:472] myEventCallback(): TXSTART [I][lorawan.cpp:266] lora_send(): 4 byte(s) sent to LORA [D][lorawan.cpp:472] myEventCallback(): RXSTART [I][lorawan.cpp:510] myRxCallback(): Received 1 byte(s) of payload on port 2 [I][rcommand.cpp:332] set_time(): Timesync requested by timeserver [D][lorawan.cpp:472] myEventCallback(): TXCOMPLETE

@cyberman54
Copy link
Owner

Please check payload on all ports in TTN app console. Does the node send a timesync packet on port 9?

@RobMBSos
Copy link
Author

Please check payload on all ports in TTN app console. Does the node send a timesync packet on port 9?

No, just a normal PAX counter message.

@cyberman54
Copy link
Owner

Please check payload on all ports in TTN app console. Does the node send a timesync packet on port 9?

No, just a normal PAX counter message.

Did you wait some time? The action is triggered asynchronally, can take up to 30 seconds (depending on settings in paxcounter.conf)

@RobMBSos
Copy link
Author

RobMBSos commented Aug 25, 2020

Please check payload on all ports in TTN app console. Does the node send a timesync packet on port 9?

No, just a normal PAX counter message.

Did you wait some time? The action is triggered asynchronally, can take up to 30 seconds (depending on settings in paxcounter.conf)

@cyberman54 yes I waited like 5-10 minutes while doing different test.
I am starting another test to check but main problem that I detected is that it will not trigger any timesync packet (I checked at node-red and terminal) that's why I started this "issue".
I am doing some more test:

  • If I send to port 2 value 86, it receives a get time command and it sends the message.
    image
    image

  • If I send then port 2 87 value, it receives a time sync command but it doesnt send nothing at port 9 so no Node-red is triggered.
    image

I am checking the timeserver logic and messages received by device, it seems Gateway is compatible with microseconds and timestamp but no message is generated from the function block...

cyberman54 pushed a commit that referenced this issue Sep 2, 2020
cyberman54 pushed a commit that referenced this issue Sep 2, 2020
@cyberman54
Copy link
Owner

For some reason there was a ")" missing in the timserver routine. Not sure if this caused this issue.
I commited a bugfix.
Please try again with current version.

I tested with my NODE RED timeserver, it worked.

@RobMBSos
Copy link
Author

RobMBSos commented Sep 3, 2020

For some reason there was a ")" missing in the timserver routine. Not sure if this caused this issue.
I commited a bugfix.
Please try again with current version.

I tested with my NODE RED timeserver, it worked.

@cyberman54 that was the problem, it is solved now. Thanks for your help.

@RobMBSos RobMBSos closed this as completed Sep 3, 2020
@cyberman54
Copy link
Owner

@theHysik sorry that had trouble with this bug. As your sync is working now, what precision do you achieve?

@RobMBSos
Copy link
Author

RobMBSos commented Sep 7, 2020

@cyberman54 I was checking today to give you a response and this is happening now:
][senddata.cpp:113] sendData(): Counter cleared [D][lorawan.cpp:472] myEventCallback(): TXSTART [I][lorawan.cpp:266] lora_send(): 4 byte(s) sent to LORA [D][lorawan.cpp:472] myEventCallback(): RXSTART [I][lorawan.cpp:510] myRxCallback(): Received 1 byte(s) of payload on port 2 [I][rcommand.cpp:332] set_time(): Timesync requested by timeserver [D][timesync.cpp:166] timesync_store(): [2163.286] seq#57[0]: t1=2163286 [W][timesync.cpp:215] timesync_serverAnswer(): [2163.293] Timeserver error: spurious data received [D][lorawan.cpp:472] myEventCallback(): TXCOMPLETE 1 [D][timesync.cpp:166] timesync_store(): [2163.306] seq#57[0]: t0=2163306 [I][lorawan.cpp:266] lora_send(): 1 byte(s) sent to LORA [D][lorawan.cpp:472] myEventCallback(): TXSTART [D][lorawan.cpp:472] myEventCallback(): RXSTART [I][lorawan.cpp:510] myRxCallback(): Received 6 byte(s) of payload on port 9 [D][timesync.cpp:166] timesync_store(): [2168.422] seq#57[0]: t1=2168422 [D][timesync.cpp:166] timesync_store(): [2168.424] seq#57[0]: t2=1599490788 [D][timesync.cpp:166] timesync_store(): [2168.430] seq#57[0]: t3=296 [W][timesync.cpp:104] timesync_processReq(): [2168.436] Timesync aborted: handshake out of sync [D][lorawan.cpp:472] myEventCallback(): TXCOMPLETE [D][cyclic.cpp:39] doHousekeeping(): IRQhandler 2292 bytes left | Taskstate = 0 [D][cyclic.cpp:42] doHousekeeping(): LMiCtask 2076 bytes left | Taskstate = 2 [D][cyclic.cpp:45] doHousekeeping(): Lorasendtask 1256 bytes left | Taskstate = 2 [D][cyclic.cpp:68] doHousekeeping(): LEDloop 480 bytes left | Taskstate = 1 [D][cyclic.cpp:39] doHousekeeping(): IRQhandler 2292 bytes left | Taskstate = 0 [D][cyclic.cpp:42] doHousekeeping(): LMiCtask 2076 bytes left | Taskstate = 2 [D][cyclic.cpp:45] doHousekeeping(): Lorasendtask 1256 bytes left | Taskstate = 2 [D][cyclic.cpp:68] doHousekeeping(): LEDloop 480 bytes left | Taskstate = 2 [D][cyclic.cpp:39] doHousekeeping(): IRQhandler 2292 bytes left | Taskstate = 0 [D][cyclic.cpp:42] doHousekeeping(): LMiCtask 2076 bytes left | Taskstate = 2 [D][cyclic.cpp:45] doHousekeeping(): Lorasendtask 1256 bytes left | Taskstate = 2 [D][cyclic.cpp:68] doHousekeeping(): LEDloop 480 bytes left | Taskstate = 2
Thanks in advance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants