TxThing Tutorial v2
TxThing Tutorial v2
In this tutorial, we will describe how to run a CoAP server on Raspberry Pi, and run the CoAP client on a
PC. The CoAP server and clients are implemented using txThings, which is a Phyton implementation of
CoAP.
1 ABOUT TXTHINGS
txThings - CoAP library for Twisted framework
txThings is a Python implementation of Constrained Application Protocol (CoAP):
http://tools.ietf.org/html/rfc7252
txThings is based on Twisted - asynchronous I/O framework and networking engine written in Python.
http://twistedmatrix.com/
Library contains CoAP code (inside "iot" directory) and three examples:
• server.py - CoAP server that starts on localhost, port 5683 and hosts several resources
• client_GET.py - example client which performs GET request to localhost, port 5683
• client_PUT.py - example client which performs PUT request to localhost, port 5683
Client_GET and client_PUT both use port 61616 - to use them simultaneously change port number in one of
the clients. Server will send blockwise responses for default settings. To use txThings you need Python 2.7
with Twisted installed (I suggest using the latest Twisted version, but older releases also work - tested with
11.1).
4 SETTING UP RASPBERRY-PI
1. Install OS on Raspberry Pi (set the appropriate raspi-config for all,including ssh and desktop
boot)
2. Install tightvncserver – optional
3. Install setup tools for python (such as pip)
https://pip.pypa.io/en/stable/installing.html#install-pip
4. Install Twisted on Raspberry Pi
a. sudo apt-get install python-pip
b. pip install twisted==15.1.0
5. Install txThings on Raspberry Pi
a. pip install txThings
5 SETTING UP PC
1. If using Windows, install Cygwin (with all the necessary packages including git, wget, ssh)
2. Install txThings and all the required dependencies (using git on Cygwin and pip)
3. Install Copper on Firefox as a GUI client – optional
https://addons.mozilla.org/en-US/firefox/addon/copper-270430/
4. Install Wireshark – optional
6 RUN THE COAP SERVER ON RASPBERRY-PI
1. From the Raspberry’s console or using ssh to the Raspberry-Pi, go to the examples directory at :
Twisted/txThings/examples
2. Run the CoAP server : python server.py
(See Figure 1)