A colleague and I are trying to connect two Raspberry Pis directly via ethernet. The reason is that one Pi is simulating a sensor we don't have yet but we know communicates over ethernet. However we are struggling to get a connection between them.
We've managed to get a wifi link to work but we can't get anything over the ethernet, we have tried pinging one pi's ip address from the other but it doesn't work. Below is the code we have come up with from different sources on the net and the changes we have made to the network interfaces file. We are totally new to the Pi and python so hopefully someone more experienced can point out our rookie mistakes?
Our code on the first Pi is
Code: Select all
import socket
import time
HOST = ''
PORT = 50007
x = 1
s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST,PORT))
s.listen(1)
conn, addr = s.accept()
print 'Connected by', addr
conn.sendall('Test')
while 1:
data = conn.recv(1024)
if not data: break
conn.sendall(data)
conn.close()
Code: Select all
auto lo
iface lo inet loopback
iface eth0 inet static
address 172.16.1.21
netmask 255.255.255.0
gateway 192.168.1.2
Code: Select all
import socket
import sys
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print('Socket Created')
port = 50007
remote_ip = '172.16.1.21'
s.connect((remote_ip , port))
s.sendall('Test Message')
s.close()
Code: Select all
auto lo
iface lo inet loopback
iface eth0 inet static
address 172.16.0.1
netmask 255.255.255.0
gateway 172.16.0.2
Thanks in advance
