cyberman54 / ESP32-Paxcounter

Wifi & BLE driven passenger flow metering with cheap ESP32 boards
https://cyberman54.github.io/ESP32-Paxcounter/
Other
1.76k stars 409 forks source link

Time sync Node-RED server. #625

Closed RobMBSos closed 4 years ago

RobMBSos commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

@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 commented 4 years ago

@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 commented 4 years ago

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 commented 4 years ago

@TheHysiK Your link doesn't work.

Anyway, check your Node red server:

RobMBSos commented 4 years ago

@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 commented 4 years ago

@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 commented 4 years ago

@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 commented 4 years ago

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

RobMBSos commented 4 years ago

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 commented 4 years ago

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

RobMBSos commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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:

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 commented 4 years ago

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 commented 4 years ago

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.

cyberman54 commented 4 years ago

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

RobMBSos commented 4 years ago

@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

[W][timesync.cpp:215] timesync_serverAnswer(): [2163.293] Timeserver error: spurious data received [D][lorawan.cpp:472] myEventCallback(): TXCOMPLETE 1

[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

[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