Andymator
Posts: 27
Joined: Sat Jun 30, 2018 9:38 am

Pi to Pi python communication

Sat Feb 09, 2019 1:01 pm

Hello
What do you think would be the easiest way to have two pies send data between each other with python?
I want each pi to run a python program and be able to communicate.

Scenario 1:
Both pies are on the same wifi.

Scenario 2:
Pies are not on the same wifi.

Thanks!

ElEscalador
Posts: 849
Joined: Tue Dec 15, 2015 4:55 pm
Location: Detroit, MI USA
Contact: Website

Re: Pi to Pi python communication

Sat Feb 09, 2019 1:41 pm

1. Allegedly MQTT..it's cool and probably easier with python - I had some hiccups with C++ but it's great once it works.

2. Little uart tx/rx wireless transceiver chips of all sorts out there pretty cheap now. Then you can just use uart comms like the PIs were just wired together. More parts, but some of us are quicker at a few extra wires than learning new code.
Robotics tips, hacks, book extras https://youtube.com/practicalrobotics

Andymator
Posts: 27
Joined: Sat Jun 30, 2018 9:38 am

Re: Pi to Pi python communication

Sat Feb 09, 2019 4:10 pm

I followed this example and it works great:
https://www.baldengineer.com/mqtt-tutorial.html

ElEscalador
Posts: 849
Joined: Tue Dec 15, 2015 4:55 pm
Location: Detroit, MI USA
Contact: Website

Re: Pi to Pi python communication

Tue Feb 12, 2019 1:09 pm

Nice, saving that.
Robotics tips, hacks, book extras https://youtube.com/practicalrobotics

ejolson
Posts: 5810
Joined: Tue Mar 18, 2014 11:47 am

Re: Pi to Pi python communication

Wed Feb 13, 2019 12:13 am

Andymator wrote:
Sat Feb 09, 2019 4:10 pm
I followed this example and it works great:
https://www.baldengineer.com/mqtt-tutorial.html
When people talk about communicating between Pi computers on separate WiFi networks by sending messages to an MQTT message broker running in the cloud and then write
but eventually, we need to look at adding some security stuff (hey, future post idea!)
it pretty well summarises the idea of security as an afterthought.

hippy
Posts: 8255
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Pi to Pi python communication

Wed Feb 13, 2019 11:09 am

ejolson wrote:
Wed Feb 13, 2019 12:13 am
When people talk about communicating between Pi computers on separate WiFi networks by sending messages to an MQTT message broker running in the cloud and then write
but eventually, we need to look at adding some security stuff (hey, future post idea!)
it pretty well summarises the idea of security as an afterthought.
I understand what you are saying but I don't completely agree here. The potential need for security has been acknowledged up-front.

A typical process for any development is; get it working, make it work well, make it secure.

'Security as an afterthought' to me is when it's not even thought about up-front, when something is released without any thought having been given to security issues.

And to be fair to the author; they did write -
By default, mosquitto runs on port 1883 with virtually no security. For getting started, this is fine, but eventually, we need to look at adding some security stuff
That is reasonable to me in the context of the article; which is a fast-track for how to get started with MQTT.

It's those similar articles which don't even mention security where accusations of 'security as an afterthought' could be more accurately levelled.

User avatar
PeterO
Posts: 5958
Joined: Sun Jul 22, 2012 4:14 pm

Re: Pi to Pi python communication

Wed Feb 13, 2019 11:24 am

hippy wrote:
Wed Feb 13, 2019 11:09 am
A typical process for any development is; get it working, ship it, forget about the rest.
Fixed it for you :-)
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Heater
Posts: 16556
Joined: Tue Jul 17, 2012 3:02 pm

Re: Pi to Pi python communication

Wed Feb 13, 2019 11:49 am

hippy,

That article is typical of the "security later" approach. It was written in February, 2016 and as far as I can tell the security follow up never happened.

I have seen this play out a few times. "Get it working first" with a passing nod to adding security later. Sure enough it does not happen or by the time it should the budget has run out the project team reassigned, nobody even knows what to secure anymore.

That is why security consultants make a good living, being called in to fix the mess, at great expense, after the thing has been hacked.

More profoundly, security is not pixie dust one can sprinkle on a project at the end. Security concerns impact all layers and corners of the design and construction of a system. From the design to the languages used down to the OS, down to the hardware. Hackers don't care about your levels of abstraction. Have you checked and sanitized all inputs? Have you taken steps to ensure there are no buffer overruns, out of range errors? etc. Have you considered possible back doors and side channels?

It's not just a case of switching on TLS or whatever.
Memory in C++ is a leaky abstraction .

hippy
Posts: 8255
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Pi to Pi python communication

Wed Feb 13, 2019 1:56 pm

Heater wrote:
Wed Feb 13, 2019 11:49 am
That article is typical of the "security later" approach. It was written in February, 2016 and as far as I can tell the security follow up never happened.
They wouldn't be the first author who hasn't followed up with an article they suggested would or should be produced later. But at least they acknowledged security was an issue when they published the first article.

It's not unreasonable for an author to write articles on what they know about, note that security is an issue, but never know how to achieve that security where it is important and needed.

Besides "security later" is not the same as "security as an afterthought". It may be it never gets implemented, but that's different to not even thinking about it.
Heater wrote:
Wed Feb 13, 2019 11:49 am
I have seen this play out a few times. "Get it working first" with a passing nod to adding security later. Sure enough it does not happen or by the time it should the budget has run out the project team reassigned, nobody even knows what to secure anymore.
C'est la vie. But that's not 'security as an afterthought'; that's not doing what they knew should be done.

One cannot blame those who knew security should be provided for that failure, cannot fairly say they ignored the issue, that it was only an afterthought for them.
Heater wrote:
Wed Feb 13, 2019 11:49 am
More profoundly, security is not pixie dust one can sprinkle on a project at the end.
True. Common practice is to get it working without security in an environment where that security is not essential, then move on to the second phase where the implementation includes the security for the environment it will be used in.

It's not the author's fault if others don't do that. This author documented the first phase, not the second, but did note the security issue, was very clear that this was only good enough for getting started.

It seems a bit unfair to me to pillory someone who noted the need for security for the failings of others not doing things properly.

mattmiller
Posts: 2247
Joined: Thu Feb 05, 2015 11:25 pm

Re: Pi to Pi python communication

Wed Feb 13, 2019 2:07 pm

What do you think would be the easiest way to have two pies send data between each other with python?
Just going back to your original question :)

MQTT is a good way of doing either.

Slight learning curve (as with everything) but very useful tool to have under your belt and code complexity is small


MUCH much easier than trying to send data using bare socket connections

Heater
Posts: 16556
Joined: Tue Jul 17, 2012 3:02 pm

Re: Pi to Pi python communication

Wed Feb 13, 2019 3:00 pm

hippy,
It seems a bit unfair to me to pillory someone who noted the need for security for the failings of others not doing things properly.
I did not mean to pillory that author. Only relaying my experiences and saying it the way I see it.

Security is very much mingled with correctness. Creating a secure system is like creating a bug free system, very hard and potentially expensive to do and impossible to tell when you have achieved it. If it is indeed possible at all.

It's all that difficulty and cost that tends to be underestimated when the boss suggests "security later".

I do agree though, often one will try out some new software by setting up insecurely on a local system. It's the quick and simple way to evaluate it and get familiar. That is only the very beginning...
Memory in C++ is a leaky abstraction .

Return to “General discussion”