p2p automatic time synchronization

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
BuddhaZen
Normal user
Posts: 13
Joined: 07 Apr 2018, 14:23

p2p automatic time synchronization

#1 Post by BuddhaZen » 05 Sep 2022, 08:12

There are several esp 1-3 modules on the network. p2p mode enabled. Number 1 has an RTC DS3231. The modules have been reloaded. Internet is missing. The time on the modules will be set to 00:00 hours. How to automatically synchronize modules 2 and 3 from RTC module number 1 in the absence of the Internet?

User avatar
Ath
Normal user
Posts: 3494
Joined: 10 Jun 2018, 12:06
Location: NL

Re: p2p automatic time synchronization

#2 Post by Ath » 05 Sep 2022, 08:42

I think that is covered in the ESPEasy-now feature that is still in PR (#3301). You could download the latest build from there (you will need to be logged in to Github to be able to download), and test that. Not sure how complete the documentation on that feature is, so it might be a bit experimental.
I know, from a reliable source (TD-er ;)), it is actually working, though there still are a few technical issues to be solved, but for time-sync it should be usable, as that seems to be one of the requirements of Espressif's ESP-now, where this feature is building on.
/Ton (PayPal.me)

TD-er
Core team member
Posts: 8739
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: p2p automatic time synchronization

#3 Post by TD-er » 05 Sep 2022, 09:11

Using that PR, you need to define this:

Code: Select all

#define USES_ESPEASY_NOW
Also on the Tools->Advanced page you have to enable using ESPEasy-NOW

This will give you the option to indeed sync time via all node within range.
Also if you have a MQTT controller configured, you should enable to forward ESPEasy-NOW messages in that controller.

Conceptually, you have one (or more) gateway node and mesh nodes.
A gateway node is a node connected to a network (either ethernet or WiFi) and has a connection to the MQTT broker (and forwarding enabled)
Nodes will try to find each other automatically and you can also have a "chain" of nodes in the mesh.
However automatic finding may not work very well if the Channel is not fixed (see force mesh channel option on tools->advanced page) and also mixing ESP8266 and ESP32 may not always work that well. But when using channel 1 it does seem to work OK. (given the gateway node also uses channel 1 to connect to WiFi)

This mesh layer allows you to forward MQTT messages from anywhere in the mesh to the broker and will sync time on all nodes. (quite accurately)

It has been tested upto 6 "hops" in the mesh and since the ESP-NOW layer uses a lower data rate than WiFi, the range is also a lot longer. Upto 200m per hop in the field with line-of-sight.
However, sometimes some nodes (at least 3) seem to think their "neighbor" has the shortest distance to the gateway and thus a packet may hop infinetely between these nodes.
For debugging you may send a message from a mesh node via rules to the broker where the topic ends with "/traceroute".
If you include the node name in the topic too, you can see via which nodes the messages are being forwarded.

Just like in the ESPEasy p2p via UDP, you need to set a unique unit nr on each node and this cannot be 0 or 255.

BuddhaZen
Normal user
Posts: 13
Joined: 07 Apr 2018, 14:23

Re: p2p automatic time synchronization

#4 Post by BuddhaZen » 05 Sep 2022, 10:16

oh, this is a bit tricky for me so far... I'm using the premade Mega builds.
I need time to figure it out :)
I thought to send the time setting function to dependent molules - Datetime, 2022-09-05, 10:00:00, but everything turned out to be more complicated)

TD-er
Core team member
Posts: 8739
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: p2p automatic time synchronization

#5 Post by TD-er » 05 Sep 2022, 11:08

Problem is that you need to have WiFi connection to the p2p nodes for the current ESPEasy p2p to work as it needs UDP.

BuddhaZen
Normal user
Posts: 13
Joined: 07 Apr 2018, 14:23

Re: p2p automatic time synchronization

#6 Post by BuddhaZen » 05 Sep 2022, 15:04

there is no problem in this. The Wi-fi network is stable and constant. The question was in moments of lack of Internet, when modules cannot receive data from NTP. But the modules have a wi-fi network.

TD-er
Core team member
Posts: 8739
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: p2p automatic time synchronization

#7 Post by TD-er » 05 Sep 2022, 15:24

OK, I can add some command/feature to allow any node to act as a local NTP source via p2p.

BuddhaZen
Normal user
Posts: 13
Joined: 07 Apr 2018, 14:23

Re: p2p automatic time synchronization

#8 Post by BuddhaZen » 05 Sep 2022, 15:32

I think this would be a useful feature in systems related to RTC dependent cycles

igorka
Normal user
Posts: 74
Joined: 17 Jul 2022, 13:41
Location: Ukraine

Re: p2p automatic time synchronization

#9 Post by igorka » 17 Sep 2022, 08:15

TD-er wrote: 05 Sep 2022, 15:24 OK, I can add some command/feature to allow any node to act as a local NTP source via p2p.
I would also be glad if you did it. Let me know when it will be possible to test it in practice.

Post Reply

Who is online

Users browsing this forum: No registered users and 75 guests