Is it possible to connect two RPi’s via network or wifi only (i.e. no particle pi)??
If it is… how would I go about sending a text file from one pi to another?
Hey @Denver42165, thanks for bringing your question to the forum.
The short answer is yes. Once both Pis are on a network, they are connected. The command to use is secure network copy - scp
- which has the following syntax:
scp <source> <destination>
To copy a file from B to A while logged into B:
scp /path/to/file username@a:/path/to/destination
To copy a file from B to A while logged into A:
scp username@b:/path/to/file /path/to/destination
where a
and b
are the Pis hostnames or local IP addresses
Here’s a concrete example; I have two Pis that I develop on:
- A Raspberry Pi 3 B that I call
devpi3b
- A Raspberry Pi Zero W, called
devpi0w
Lets pretend there’s a data file (data
) in the user-directory of devpi0w
that I want to fetch, and I’m working on devpi3b
I can execute:
scp pi@devpi0w.local:/home/pi/data.txt /home/pi/data.txt
Here I’m using the hostname of the Pis, followed by .local
- this will usually work for DHCP routers. If you must/want, you can use the actual IP address. By default, the hostname when using Raspbian is raspberrypi
.
After executing I’ll be prompted for a security confirmation and the user’s password, then the file will copy.
Of course, this will work for any type of file - not just a text file.
Hey, @Denver42165 - To help you and anybody else looking to run a shell command from a Python script, I’ve created a new forum topic here.
Thanks guys, I was only thinking about this over the weekend… Saved me a lot of head-scratching:slight_smile:
J
@Michael_R I have tried to add the scp into a python3 script. The script works but it asks for a password. Do you have any suggestions on how to remove the password or automatically fill it out?
Hi @Denver42165,
You’ll need to create a public+private key pair. Here’s how
https://www.raspberrypi.org/documentation/remote-access/ssh/passwordless.md
Thanks @Graham. I tried that last night and it didn’t work. After reading the instructions, I realised I was doing the process wrong. I try with the instructions you have provided tonight.