0% found this document useful (0 votes)
32 views8 pages

TxThing Tutorial v2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views8 pages

TxThing Tutorial v2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

txThings Tutorial

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/

txThings uses MIT License (like Twisted itself).


http://opensource.org/licenses/mit-license.php

Copyright (c) 2012 Maciej Wasilak


http://sixpinetrees.blogspot.com/

2 TXTHINGS PYTHON LIBRARY FEATURES

txThings has the following features:

• support for draft-ietf-core-coap-13 - including automatic piggyback/separate response handling. No


caching support.
• support for draft-ietf-core-block-12 (no support for server initiative though - waiting for the
resolution)
• limited support for RFC6690 (Core Link Format) - server only.

Other nice things:

• txThings works nicely on RaspberryPi


• txThings is compatible with Kivy - brilliant new Python GUI library (I'll post some examples soon).
• txThings is fully asynchronous (thanks to twisted framework)
3 TXTHINGS INSTALLATION HOWTO
txThings is posted on Github. The easiest way to get it is to clone the repository to your local machine using
the command below:

git clone git://github.com/siskin/txThings.git

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)

Figure 1. Running the CoAP Server on Raspberry-Pi using SSH

7 RUN COAP CLIENT ON PC


1. If using Windows, open Cygwin
2. Go to the examples directory at : Twisted/txThings/examples
3. Change the resource name and remote IP address in the source code of client_GET.py or
client_PUT.py (see Figure 2)
4. Run the CoAP clients (see Figure 3):
a. For GET operation: python client_GET.py
b. For PUT operation: python client_PUT.py
Figure 2. Change the resource name and remote IP Address in the source code of client_GET.py
Figure 3. Run client_GET.py on a Windows PC using Cygwin

8 RUN COPPER ON FIREFOX


The Copper (Cu) CoAP user-agent is an add-on for the Firefox Web browser. It allows browsing,
bookmarking, and direct interaction with CoAP resources. Simply enter a CoAP URI into the address bar
(See Figure 4, Figure 5 and Figure 6)
Figure 4. Running the OBSERVE operation on the resource “time” using Copper
Figure 5. Running the GET operation on the resource “counter” using Copper
Figure 6. Running the PUT operation on the resource “block” using Copper

You might also like