Today, Marc and I started to work on the common time reference shared between Phyllos.
As you may recall, we need this common time reference to be able to play synchronized animations with several Phyllos. Here is a gif to visualize an example of synchronized animation :
As explained in this post, we know since a long time that it is possible to transmit precisely enough a time reference with UDP. But we still have to choose one ESP32 to be the master ESP32 and to enforce its time reference to all other ESP32, and by extension all other Phyllos.
Since the ESP32 of the bottom PCB do not have anything to do except receiving speed instructions from the main board, and since it is not powered through ball bearings, we have decided that only the ESP32 of the bottom PCBs are candidates to become the time master.
Here is a state diagram on the election protocol :
Each Phyllo has two identifiers : one for the ESP32 on the main board and the other one for the ESP32 on the bottom PCB, let’s call it BottomID.
The bottom ESP32 exchange 3 types of messages :
- time_top : uint32_t representing the common time reference.
- master_exist<BottomID> : inform that the Phyllo with BottomID is the current master.
- master_request<BottomID> : ask if the Phyllo with BottomID can be the master.
When the election process starts, the ESP32 starts a thread sending several master_request messages then waits to receive other messages from other ESP32, or until a timeout is reached. If the timeout is reached, there is no other Phyllo wanting to become the master, so it becomes the master. If it receives a master_exist message, or a master_request message from a Phyllo with a smaller BottomID, then in both cases, it becomes a client. If not (only master_request messages are exchanged, and it has the smaller BottomID), it becomes the master and sends regularly master_exist messages and time_top messages.
When a Phyllo is a Client, it has to monitor the master_exist messages. If it doesn’t receive any during a long time, the master may be disabled, so it starts over the election process.
We have implemented this protocol this afternoon and we will test it tomorrow 🙂
Stay tuned !