Hardware Reference
In-Depth Information
Installing and testing the
python-twisted framework
com/trac/
). The Twisted framework is an open source event-driven network engine that
can be used to send control messages to other devices (for example, a pet feeder can be
operated using Raspberry Pi to dispense solid food to our animal friends). The messaging
protocol is called
AMP
(
Asynchronous Messaging Protocol
) which is
available at
http://amp-p
rotocol.net/
.
Prepare for lift off
The Raspberry Pi (with an SD card flashed with the OS image) connected to the Internet
is needed for this task along with an Arduino Ethernet Board (or any one of the boards
menioned earlier in the checklist. Network connecivity is essenial). We will install the
python-twisted
framework and review a quick example to exchange messages between
Arduino and the Raspberry Pi.
Engage thrusters
1.
The
python-twisted
framework can be installed from the terminal of the
Raspberry Pi as follows:
sudo apt-get install python-twisted
2. Once the installaion is complete, it is ime to review an example of the python-
twisted framework to test t
he framework (
http://twistedmatrix.com/
documents/current/_downloads/
simpleserv.py
).
1.
In this task, we will launch a server on the Raspberry Pi and try to
communicate to the server within the local network.
2.
Let's modify the preceding example to bind the
python-twisted
server to
the IP address of Raspberry Pi so that we can exchange messages with other
devices on the network. This device can either be an Arduino or a laptop.
3.
We will modify the
listenTCP
method to bind the server to the IP address of
the Raspberry Pi and listen to incoming messages at the port address,
8000
.
reactor.listenTCP(8000,factory,50,'192.168.1.89')
4. The web server can be launched by executing a Python script.
5.
Now, using a laptop that is connected to the same network, let's modify
the
simpleclient.py
script to send and receive messages to the server
just launched
on the Raspberry Pi (
https://twistedmatrix.com/
documents/14.0.1/_download
s/simpleclient.py
).