Russh
Posts: 45
Joined: Mon Jul 22, 2013 8:08 pm

pi to pi wifi

Sun Oct 06, 2013 11:35 pm

Hi

I was wondering if it was at all possible for two pi's to talk to each other other wifi. Nothing too complicated, simply for pi 1 to tell pi 2 when a gpio event (such as a switch) has occured.

if this difficult to do?

SirLagz
Posts: 1705
Joined: Mon Feb 20, 2012 8:53 am
Location: Perth, Australia
Contact: Website

Re: pi to pi wifi

Mon Oct 07, 2013 2:07 am

Is there a WiFi router / AP between the 2 ?
If there is, then it's as easy as if they were connected via ethernet.

If not then you could use one Pi to create an AP and the other can connect to it.
Then it's as easy as if they were connected via ethernet.
My Blog - http://www.sirlagz.net
Visit my blog for Tips, Tricks, Guides and More !
WiFi Issues ? Have a look at this post ! http://www.raspberrypi.org/phpBB3/viewtopic.php?f=28&t=44044

User avatar
pluggy
Posts: 3635
Joined: Thu May 31, 2012 3:52 pm
Location: Barnoldswick, Lancashire,UK
Contact: Website

Re: pi to pi wifi

Mon Oct 07, 2013 2:07 am

Depends what you call difficult. Its more than possible and I would consider it straightforward, depends on your experience. There are many ways of achieving it. Its just networking 2 computers.
Don't judge Linux by the Pi.......
I must not tread on too many sacred cows......

Russh
Posts: 45
Joined: Mon Jul 22, 2013 8:08 pm

Re: pi to pi wifi

Mon Oct 07, 2013 8:11 am

Hi,
thanks for the replies.

I would say my knowledge is quite limited, I would certainly need to find a tutorial/example on it.

It will indeed have a router between the two

Oakham
Posts: 366
Joined: Tue Aug 20, 2013 9:11 pm

Re: pi to pi wifi

Mon Oct 07, 2013 8:39 am

If you have wireless router and both Pi's are connected to the router successfully you are almost there.

If using Raspbian Wheezy, then install Samba on both Pi's and set up sharing.
Searching is easy, most questions have been asked before !

Russh
Posts: 45
Joined: Mon Jul 22, 2013 8:08 pm

Re: pi to pi wifi

Mon Oct 07, 2013 9:07 am

Perfect, I will get samba installed today.

Then is it easy to tell pi 2when a GPIO pin has been activated on pi 1.

For example, a security system runs a motion detector, the motion detector sends an on signal to a GPIO pin of Rpi 1. Rpi 1 then sends a signal wirelessly to Rpi 2 to tell it to turn activate an alarm (speaker connected to a GPIO pin)

User avatar
Hove
Posts: 1205
Joined: Sun Oct 21, 2012 6:55 pm
Location: Cotswolds, UK
Contact: Website

Re: pi to pi wifi

Mon Oct 07, 2013 10:55 am

Do you have a program (Python, C etc) running on both Pi's, one watching the motion detector, and the listening to the other Pi waiting to sound the alarm?

If you do, then your (I'm assuming) Python code could opening a "listening" socket on the alarm Pi, and the motion detector Pi would open a TCP connection to the listening socket when it detects motion. This still is not difficult, all it needs is for you to learn a little bit more Python about opening netwrok connections between 2 applications.

I have a turtle that works like this - here's the turtle code which loops listening for incoming connections for commands:

Code: Select all

try:
	serversock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error as msg:
	serversock = None
try:
	serversock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
	serversock.bind((socket.gethostname(), 12345))
	DebugPrint("Waiting for contact from ", socket.gethostname(), "\n")
	serversock.listen(NUM_SOCK);
except socket.error as msg:
	serversock.close()
	serversock = None

if serversock is None:
    DebugPrint('could not open socket')
    sys.exit(1)

while True:
	(turtlesock, turtleaddr) = serversock.accept()
	DebugPrint('turtle socket accepted')
	cmd_data = turtlesock.recv(4096)
	if not cmd_data:
		break;
	DebugPrint('received: ', cmd_data)
	turtlesock.shutdown(socket.SHUT_RDWR)
	turtlesock.close()
Here's the turtle CLI app which send commands to it:

Code: Select all

	turtlesock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
	try:
		turtlesock.connect(("turtlepi.home", 12345))
	except ValueError:
		print 'Error on opening turtle socket'
		print turtlesock.error
		sys.exit(1)
                                   
	turtlesock.send(cli_text)
	turtlesock.shutdown(socket.SHUT_RDWR)
	turtlesock.close()
www.pistuffing.co.uk - Raspberry Pi and other stuffing!

User avatar
pluggy
Posts: 3635
Joined: Thu May 31, 2012 3:52 pm
Location: Barnoldswick, Lancashire,UK
Contact: Website

Re: pi to pi wifi

Mon Oct 07, 2013 11:07 am

Samba ? for Pi to Pi ?

The last thing I'd have used, but whatever. Samba is a fudge to make it appear as a M$ server which is entirely pointless when there isn't a Windoze machine to worry about. I'd just use SSH with key login. Already built in and a lot more straightforward to achieve (even with the keygen bit).
Don't judge Linux by the Pi.......
I must not tread on too many sacred cows......

SirLagz
Posts: 1705
Joined: Mon Feb 20, 2012 8:53 am
Location: Perth, Australia
Contact: Website

Re: pi to pi wifi

Mon Oct 07, 2013 1:21 pm

If it's not a time critical application - i.e. you don't need to have an instant response, it'd be easy enough to have a program on Pi 1 write to a file, and then a program on Pi 2 read from the file on Pi 1.
This could be done with NFS between the 2 Pis
My Blog - http://www.sirlagz.net
Visit my blog for Tips, Tricks, Guides and More !
WiFi Issues ? Have a look at this post ! http://www.raspberrypi.org/phpBB3/viewtopic.php?f=28&t=44044

Russh
Posts: 45
Joined: Mon Jul 22, 2013 8:08 pm

Re: pi to pi wifi

Wed Oct 09, 2013 10:39 pm

Thanks for all the replies, hugely grateful.

Ive scrapped the samba idea.....shows Im a complete noob

I plan to use it as wireless alarm module for the garden, so it depends how long the delay is, if its just seconds then that's fine, its its minutes then I wont have time to whack the bar off the thieves heads!! :)

SirLagz
Posts: 1705
Joined: Mon Feb 20, 2012 8:53 am
Location: Perth, Australia
Contact: Website

Re: pi to pi wifi

Thu Oct 10, 2013 12:20 am

Then it depends on how big your garden is haha.

You could run a job every minute that will check the file, sleep for 30 seconds, and then check the file again.
That sleep could be any period though, not just 30. it could be 5 seconds if you wanted.

I'm using a Pi as a home security system of sorts. I run motion and have it setup to email me whenever it detects motion at home when I'm not around.
My Blog - http://www.sirlagz.net
Visit my blog for Tips, Tricks, Guides and More !
WiFi Issues ? Have a look at this post ! http://www.raspberrypi.org/phpBB3/viewtopic.php?f=28&t=44044

mapsurfer
Posts: 1
Joined: Thu Oct 10, 2013 2:54 am

Re: pi to pi wifi

Thu Oct 10, 2013 3:49 am

Here is a possible solution... I recently saw a blog where a guy hacked a Transcend Wifi SD card which has 16 or 32GB which is embedded linux (a system unto itself) has the webserver, java/js, etc running with busybox. Having this gives you an extra CPU with Wifi, and a bit of space to store files, etc. for $50. I have not had time to hack one of these Wifi SD cards myself, but apparently it is pretty easy to get root and do pretty much anything you want with it.

If you got Pi doing it's specific functions, you can offload the storage, webserver and wifi to the processor on the SD card itself and you don't have to deal with the wifi module on the Pi and they will essentially share the same storage on the SD card which is a pretty elegant solution and cheap.

Someone said you need a wifi router, but I am pretty sure you could setup adhoc, or have the device act as a AP hotspot like how the AR Drone does. I don't know the specifics of how to set that up wifi without doing research myself, but I am pretty it's doable either way.

One user suggested using SSH which is a pretty good idea as well and for peer connectivity, the preferred way to communicate between the linux nodes. Another user suggested running Samba but I would suggest exporting with NFS if that's what you want to do but the wifi SD is pretty slick NAS and I believe you could export the drives and mount SD cards and you need...

Return to “General discussion”