2

Hello I received two Pi 4 for Christmas. It is the first time I use RPI, I have succeeded to turn them on and to connect them to my local wifi !

I am a a beginner and I wanted to start with a simple project : connecting 2 RPI together and send data( file of 60 Mo) through Wi-fi between them.

After startup, an automatic connection is set up between the RPI[1] and the RPI[2], RPI[1] sends a set of data to the RPI[2].

The idea would be that RPI [1] should send a "presence" signal only every 30 min approximatively (configurable)

The RPI[2] would be in permanent listening, and as soon as it receives the signal of presence of the RPI[1], it opens a communication protocol with the RPI[2] of the type : "I know that RPI[1] is there, RPI[1] confirms that it is sending me data, I receive the data, I check the integrity of the data (how ..?), I confirm receipt to RPI[1], I close the communication". "If the integrity of the data is not good, I ask for the data to be sent back from RPI[1] following the same process as before".

I was wondering :

  • the simpliest way to send file through Wi-fi ?
  • Which protocol to choose ? TCP or MQTT ( seemed better than http)
  • which languages to choose ? Python or C ?
  • Any good ressources to help me started or similar projects ?
  • This is a good "scenario" ?

Thank you in advance for your help,
Antoine

2
  • I would read up on CRON for timing and RSYNC for sending files. MQTT is really designed for small (byte sized) messages rather than files. Linux is a very mature operating system and often there is a tool already and often it's more important to lever existing tools than re-invent the world. – user115418 Dec 25 '20 at 16:13
  • your question is not about a Raspberry Pi ... it is a question about Linux – jsotola Dec 25 '20 at 17:35
4

To answer your last point

  • This is a good "scenario" ?

and with the announcement

I am a a beginner and I wanted to start with a simple project : connecting 2 RPI together and send data( file of 60 Mo) through Wi-fi between them.

I would say "No".

To transfer a file form RPi1 to RP2 just use:

rpi ~$ scp /path/to/file pi@rpi2:/path/to/file

To repeat this automatically after a time, create a systemd service with a timer:

rpi ~$ sudo systemctl edit --force --full transfer-file.service

In the empty editor insert these statements, save them and quit the editor:

[Unit]
Description=Transfer file
[Service]
Type=oneshot
ExecStart=/usr/bin/scp /path/to/file pi@rpi2:/path/to/file

rpi ~$ sudo systemctl edit --force --full transfer-file.timer

In the empty editor insert these statements, save them and quit the editor:

[Timer]
OnActiveSec=30min

Enable and manage this with

rpi ~$ sudo systemctl enable --now transfer-file.timer
rpi ~$ sudo systemctl status transfer-file.timer
rpi ~$ sudo systemctl edit --full transfer-file.timer

This will transfer a file every 30 minutes. All error handling and handshake is done by the operating system, the scp program and the TCP network protocol.

2
  • +1 I did not know about service timers – Tom Knapen Dec 26 '20 at 8:32
  • How can I manage the password issue between the two RPI ? I think this is the reason why it doesn't work. when using "sudo systemctl enable --now transfer-file.timer" I get sudo systemctl enable --now transfer-file.timer The unit files have no installation config (WantedBy=, RequiredBy=, Also=, Alias= settings in the [Install] section, and DefaultInstance= for template units). This means they are not meant to be enabled using systemctl. – Antoine Riguillard Jan 5 at 17:02
2

If this file transfer is to be an ongoing effort, you may wish to consider rsync. If you're using the RPi OS, rsync is pre-installed, and you can learn about its use by perusing man rsync.

You have at least two choices for running rsync across two RPis:

  1. set up an SSH connection

  2. set up a Samba server(s) on one or both RPis & mount the shared drives

If you use the SSH connection, you may find it convenient to set up a public-private key pair as that will avoid userid+password authentication which can be messy and insecure.

All of the information you need to do this is available online for the cost of an Internet search. Please take a few minutes to read some of these search results. If you have specific questions, please post those as separate questions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.