Let’s go all the way !

As I already wrote on previous post, we implemented a MQTT communication to send data from the server to the ESP, we also implemented an UART communication to pass data from the ESP to the STM. Now it is time to go all the way : sending data from the server all the way to the STM.

To do so we had to make a choice: at which point will we encode the data in regard of the communication protocol between ESP and STM.
As a remainder, to be able to differentiate data from commands, the bytes that will contain data will always start with a 1 and then code the state of 7 marbles. We decided that the data published on the Broker will have this same form. That way, the ESP imply has to transmit the data from the server to the STM.

Then we had to implement two threads on the ESP. One of them is in charge of receiving data from MQTT and put them into a shared variable. The second one will take this variable and send it to the STM. We had a few issue to make all the modules work together but we finally got it right.

Here are the log of the three parts.
On the left we have the server. It prints the data that will be sent then “publish done” and finally a number just to see the evolution.
In the middle part of the screen there is the ESP. When it receive data from the MQTT server it prints in white “TOPIC= “followed by the topic where the data got published. then it starts the communication with the STM and before sendiing the data it prints them.
On the right part, there is the STM. It print “IDLE” followed by “Waiting for image” when the command received is an incoming image. Then once the image is received it prints the data.

This video might be hard to understand so here is what appends:
The video starts right after the 25th publish. the interesting part start as soon as the 26th starts (bottom left corner). Right after this happens, the ESP receive the data (“TOPIC=Cause Everytime”) and initiate a communication with the STM (“SEND_TO_STM: Wrote 1 byte”). At this point, the STM received it and sends the ACK (“Waiting for image”). The ESP then sends the data (you see all the numbers printing on the middle screen) and the STM receive it right after (once again the numbers are printed).
Then everything start over again.

Leave a Reply

Your email address will not be published. Required fields are marked *