JizzaDaMan
Posts: 66
Joined: Sun Apr 07, 2013 2:14 pm

Send information directly over a network

Sat Mar 22, 2014 8:13 pm

Hi, I'm going to set up a local network which will include a server (a linux mint pc) and 3 or 4 raspberry pis.

(You'll have to bear with me when it comes to networking, I am a complete noob and my understanding of the jargon extends to 'IP address'.)

What I want to happen:

I write and run a script on the server, so that when I press 'enter,' a byte of information containing a single number is sent to all the pis (hopefully simultaneously). The number will correspond directly to the name of a directory on each pi.

When each pi receives the byte, it reads the byte, and runs the script(s) within the directory the number corresponds to.

I want this to happen as instantaneously as possible. I don't want things to be slowed down by encryption or passwords or whatever other fancy stuff goes on that I don't understand :P

Quite a few questions:
What is the best way to achieve this?
In terms of setting up the network, will I need to use a hub or can I just use an Ethernet splitter and direct connections?
After connecting everything together via Ethernet, is there anything else I need to do to make it a 'network'?
Is this even possible?!
Finally, how can I have the pis constantly waiting for the byte of data, and then execute a script when it detects it?

Thank you very much in advance for answering any of my probably basic questions :P

User avatar
FLYFISH TECHNOLOGIES
Posts: 1750
Joined: Thu Oct 03, 2013 7:48 am
Location: Ljubljana, Slovenia
Contact: Website

Re: Send information directly over a network

Sat Mar 22, 2014 8:26 pm

Hi,
JizzaDaMan wrote:What is the best way to achieve this?
Probably via sockets communication. Ask google for details and examples.
JizzaDaMan wrote:In terms of setting up the network, will I need to use a hub or can I just use an Ethernet splitter and direct connections?
Take a hub (most likely you cannot get one anymore, they are/were replaced by switches).
JizzaDaMan wrote:After connecting everything together via Ethernet, is there anything else I need to do to make it a 'network'?
Depends on your definition of "after connecting everything together via Ethernet". If this means that you just plug wires together, then there are some things left to be configured/verified.
JizzaDaMan wrote:Is this even possible?!
Definitely.
JizzaDaMan wrote:Finally, how can I have the pis constantly waiting for the byte of data, and then execute a script when it detects it?
You're going to get this answer within sockets study proposed above.


Best wishes, Ivan Zilic.
Running out of GPIO pins and/or need to read analog values?
Solution: http://www.flyfish-tech.com/FF32

Tarcas
Posts: 740
Joined: Thu Jan 09, 2014 5:38 am
Location: USA

Re: Send information directly over a network

Sat Mar 22, 2014 9:56 pm

Given your level of network knowledge, my suggestion is to not do raw socket programming. If all you want is for a script to be run on each Pi, there's already a framework for that through SSH. It allows you to run a command on another computer, just by passing it through the SSH program. I know you said you don't want extra overhead, but unless you're working in the nanosecond timescale, this should easily be fast enough. Most people underestimate the raw speed that computers and networks function at, and I think you've done this. What are you trying to accomplish with your instantaneous script executions?
JizzaDaMan wrote:In terms of setting up the network, will I need to use a hub or can I just use an Ethernet splitter and direct connections?


Take a hub (most likely you cannot get one anymore, they are/were replaced by switches).
There is no such thing as an (in-spec) Ethernet splitter, and there never has been or will be. Ethernet connections might look like phone connections, but they're fundamentally very different. Hubs were the closest thing to an "Ethernet Splitter" that ever existed, and as Ivan said, they've been replaced by switches. Unless you're looking at used gear from decades ago, it's very hard to find a hub anymore, and there are very few reasons you'd even want one instead of a switch.

JizzaDaMan
Posts: 66
Joined: Sun Apr 07, 2013 2:14 pm

Re: Send information directly over a network

Sat Mar 22, 2014 11:08 pm

Thanks for suggesting using sockets, after a bit of experimenting I can see that they are exactly the kind of thing I was looking for :) I will undoubtedly be back after having a go at the other issues :P

JizzaDaMan
Posts: 66
Joined: Sun Apr 07, 2013 2:14 pm

Re: Send information directly over a network

Sat Mar 22, 2014 11:25 pm

Tarcas wrote:Given your level of network knowledge, my suggestion is to not do raw socket programming. If all you want is for a script to be run on each Pi, there's already a framework for that through SSH. It allows you to run a command on another computer, just by passing it through the SSH program. I know you said you don't want extra overhead, but unless you're working in the nanosecond timescale, this should easily be fast enough. Most people underestimate the raw speed that computers and networks function at, and I think you've done this. What are you trying to accomplish with your instantaneous script executions?

There is no such thing as an (in-spec) Ethernet splitter, and there never has been or will be. Ethernet connections might look like phone connections, but they're fundamentally very different. Hubs were the closest thing to an "Ethernet Splitter" that ever existed, and as Ivan said, they've been replaced by switches. Unless you're looking at used gear from decades ago, it's very hard to find a hub anymore, and there are very few reasons you'd even want one instead of a switch.

I managed to get exactly the kind of set up I'm after using this tutorial:
http://www.binarytides.com/python-socke ... -tutorial/

But I'm interested how one would use SSH. It was my first thought, but after experimenting it seemed to clunky for my purposes (at least the command line interface did).

How do you suggest I set up a local network?

Tarcas
Posts: 740
Joined: Thu Jan 09, 2014 5:38 am
Location: USA

Re: Send information directly over a network

Sun Mar 23, 2014 3:14 am

JizzaDaMan wrote:
Tarcas wrote:Given your level of network knowledge, my suggestion is to not do raw socket programming. If all you want is for a script to be run on each Pi, there's already a framework for that through SSH. It allows you to run a command on another computer, just by passing it through the SSH program. I know you said you don't want extra overhead, but unless you're working in the nanosecond timescale, this should easily be fast enough. Most people underestimate the raw speed that computers and networks function at, and I think you've done this. What are you trying to accomplish with your instantaneous script executions?

There is no such thing as an (in-spec) Ethernet splitter, and there never has been or will be. Ethernet connections might look like phone connections, but they're fundamentally very different. Hubs were the closest thing to an "Ethernet Splitter" that ever existed, and as Ivan said, they've been replaced by switches. Unless you're looking at used gear from decades ago, it's very hard to find a hub anymore, and there are very few reasons you'd even want one instead of a switch.

I managed to get exactly the kind of set up I'm after using this tutorial:
http://www.binarytides.com/python-socke ... -tutorial/

But I'm interested how one would use SSH. It was my first thought, but after experimenting it seemed to clunky for my purposes (at least the command line interface did).

How do you suggest I set up a local network?
Here's a tutorial with some examples of how to use SSH to execute a command remotely. Basically it's just "ssh user@host command arguments." There's a link near the bottom of that page to set up public key based authentication so that you don't need to put in your password every time. You'll want that for doing this in an automated fashion, which is clearly what you're doing here.

How to set up a local network depends greatly on how the network will be used. Since you haven't described your project very thoroughly, I'll make some assumptions based on what you have stated, and design a simple network based on those.
1) 4 devices: a server and 3 pis
2) wired connection to each (no wifi)
3) no router, no Internet connectivity, no DHCP, no special IP addressing requirements or restrictions

Step 1 - Get an Ethernet switch and 4 Ethernet cables. Since not much data will be passing, a 10 Mbps switch will probably be fine, but 100 Mbps will be easier to find, not much more expensive, and allow for better future expansion. You could also get a home router with 4 or more switch ports built in (don't count the uplink port - that's not a switch port.) but that will change some of my future steps, so stop here and ask for the alternate design if you choose a router instead.
Step 2 - Connect the cables from each device to the switch. It doesn't matter which port you plug each device into, but keeping them in some order that makes sense to you is wise. Labeling them is also wise if you don't want to have to guess and check when you need to change something in a few months or a few years. As you connect, each set of lights should come on.
Step 3 - Assign static IP addresses and subnet mask to each device. For your setup, use 192.168.0.10 through 192.168.0.14 (only the last octet of the IP changes. It must be unique on each device, and the other 3 must match.) with subnet mask 255.255.255.0. Look up tutorials on setting up a static IP on each device. Google and Youtube will have loads of instructions for this.
Step 4 - Test. From each device, ping the IP addresses of each other device. If any fails, have that device ping itself. If pinging itself fails, that device's IP was set up wrong. If pinging others fails, post the ping results here or google them for interpretation.

Note that this is an EXTREMELY basic network with no functionality besides what you will create for it separately. It can't get to the outside world, and any new device will need another IP assigned in the correct range.

EDIT: Added link to the tutorial on using SSH to run commands remotely. Apparently I forgot to put it in the first time.
Last edited by Tarcas on Sun Mar 23, 2014 9:22 pm, edited 1 time in total.

JizzaDaMan
Posts: 66
Joined: Sun Apr 07, 2013 2:14 pm

Re: Send information directly over a network

Sun Mar 23, 2014 6:22 pm

Thanks, that is exactly the kind of network I wanted :) Just basic data transmission between devices, so that will work perfectly. Thank you for your help :)

User avatar
DougieLawson
Posts: 36098
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Send information directly over a network

Sun Mar 23, 2014 6:32 pm

Before you start writing your own code take a look at http://mqtt.org. It is perfect for one-to-one and one-to-many comms with either end being a publisher or a subscriber.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Return to “Beginners”