Hi. I have spent a whole day trying to follow the Networking Lessons on the raspberrypi.org website. I am a secondary teacher and want to offer this task to my computer science students. Others may have also discovered that there are some crucial errors in the networking lessons, particularly in the chat.py code. It took me ages and much internet searching and trial and error to get my two raspi computers to chat to each other. Here is the correct chat.py code:
Code: Select all
import network
import sys
def heard(phrase):
print "them:" + phrase
print "Chat Program"
if (len(sys.argv) >= 2):
network.call(sys.argv[1], whenHearCall=heard)
else:
network.wait(whenHearCall=heard)
print "Chat away!"
while network.isConnected():
phrase = raw_input()
print "me:" + phrase
network.say(phrase)
You'll notice a few differences with the notes in the Raspberry Pi Networking Lessons.
The other thing to note is that you need to edit the etc/network/interfaces file (you can use sudo nano /etc/network/interfaces as a way to edit this file). You need to add the following code to this file:
Code: Select all
iface eth0 inet static
address 192.168.0.2
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
gateway 192.168.0.1
The address in line 2 is each raspi's unique ip address. You need to do this for both of the raspi computers that you are networking, and they will of course have different addresses. You will need to reboot your pi for these changes to take effect.
You can then use ifconfig to check the ip address is exactly as you set it.
The other thing you might get is an error message saying something like "Network unreachable". This may mean you need to configure your ip address. Try configuring the eth0 by typing in a command: $ sudo ifconfig eth0 192.168.0.? netmask 255.255.255.0
Do this for both pi’s, client and server (both will have different eth0 ip addresses of course)
So there are a few tips from my experience. I found the following website more accurate and helpful than the raspberry pi networking lessons:
http://blog.whaleygeek.co.uk/raspberry- ... in-python/