Harmony Clean Flat Responsive WordPress Blog Theme

Saving message from other devices through MQTT

오전 4:41 Unknown 0 Comments Category :

This time,  I used 3 raspberry pies to make a network for communicating gateway with end device. I am gonna put some sensors on the end device to get data but this time I didn't and send just message from end devices to gateway. One of Raspberry is gateway for network and it receives message from two other raspberry pies through MQTT. As soon as gateway get a message,  It makes a text file to save the messages. Let's see the code followed:



I used pi3_01 for gateway and the messages come from pi2 and pi3_02. Gateway always keep listening topic by using subscribe and each end device has their own topic. When gateway get a message, it saves the message to text file whose name is test.txt by using appendFIleSync. So gateway can save all message what end device send to it.

Moreover, this is end device code:


I made this device to send message and topic periodically(every 1 sec).  In next time, I will try to make a gateway program which can count how many messages gateway got and end devices which can publish a message and stop to send message if it send a message once.


RELATED POSTS

0 개의 댓글