User avatar
raspberrypiguy1
Posts: 379
Joined: Sun Sep 02, 2012 7:01 pm

Python WiFi communication between 3 Pis

Wed Feb 08, 2017 6:04 pm

Hi folks,

Got a small query surrounding the use of WiFi as a medium of communication between 3 Raspberry Pis. Essentially I am creating a lidar system that has 3 independent subsystems, each controlled by a Pi. The subsystems are: 1) stepper motor control for rotation 2) distance measurement 3) touchscreen UI. All of these Pis need to be able to ideally communicate with one another and not be bogged down by one of them being the server etc. An overview of the flow of data can be found attached.

Also note that the data is just text (distance and rotational position), but it would be quite neat to extend the project to use a Pi camera as well, so preferably images would be able to be sent over the network between the Pis too.

What is the best way to network 3 Pis in Python that would facilitate both text and image communication?

Thanks

Matt
flow_of_data.png
Flow of Data
flow_of_data.png (26.98 KiB) Viewed 2168 times
Matt, The Raspberry Pi Guy YouTube channel, author of Learn Robotics with Raspberry Pi, available now: http://mybook.to/raspirobots, Computer Science & Electronics Undergraduate at The University of Edinburgh

User avatar
kusti8
Posts: 3439
Joined: Sat Dec 21, 2013 5:29 pm
Location: USA

Re: Python WiFi communication between 3 Pis

Wed Feb 08, 2017 7:51 pm

Easiest way would be to make one be a AP and have them talk to each other with sockets or mqtt or something. It wouldn't get bogged down at all by traffic since it's pretty powerful.
There are 10 types of people: those who understand binary and those who don't.

User avatar
DougieLawson
Posts: 38830
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Python WiFi communication between 3 Pis

Wed Feb 08, 2017 8:09 pm

How closely located are they? Because up to 100m is easiest with a cat5 cable and a small 5-port 100Mbps switch (which cost about a tenner including VAT+P&P). The ones I use are: https://www.amazon.co.uk/TP-LINK-TL-SF1 ... B000FNFSPY

If you give one RPi an RTC board it can serve the time of day to the other two (the NTP set-up for that is trivial). If you also run dnsmasq on there then the master machine hands out the IP addresses to the other two (so everyone can find the master). Run avahi-daemon and everyone can find every other machine with $(hostname).local The side effect of that is that if you plug a laptop into the switch for maintenance then it gets an IP address assigned from the same dnsmasq server. It's then easy to find all the machines on your small self-contained LAN.

You can do it with WiFi with one master machine running hostapd and dnsmasq as a WiFi AP, but you won't gain much over a wired set-up. Again the master machine can have the RTC so that all the clocks can sync to it. Again your laptop can be used to connect to the WiFi "mesh". You only need WiFi if the machines can move. If they're screwed down use wired.

MQTT is clearly the best choice for your command & control messages, that's what it was designed for by Dr Stanford-Clark and others.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Return to “Python”