Thursday, September 19, 2013

txThings - "Good enough" is good enough

Long time no see! Last update here was posted more than a year ago. There are multiple reasons for that, but the most important one is that I decided to pause embedded development for a while, and learn more about application layer, and user applications. For a start I decided to write a library for CoAP - new protocol for Internet of Things. I also decided to write it in Python, using Twisted framework. The development has been quite slow, but last month I accidentaly found pyvideo.org site with various Python related videos, and found a brilliant talk by Alex Martelli : "Good enough is good enough"



After watching the video, I decided to quickly finish the work on current features, and release the first version of library, with some features completed, and some missing. I hope to get some feedback from users, so that I can improve the library.

txThings - CoAP Python library

I've decided to call the library txThings - Twisted has a tradition of calling modules with plural nouns (also Coap LIbrary for Twisted gave really bad acronym ;) ).

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)

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/mwasilak/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).

Current work

Next step is to add Observe and full Core Link Format support to txThings. I am also planning to continue investigating Kivy library.

If you are interested in using txThings and have any questions, don't hesitate to contact me.

7 comments:

  1. Hi Maciej, looks good but does it work with IPV6?
    Best wishes
    Ron

    ReplyDelete
  2. Hi, I have 2 raspberry pis running txThings. It works as required, I can access data from one to other. However, I would like to access larger amount of data with higher block size. The SZX doesn't seem to change, would you please guide me, how can I go about changing it?

    ReplyDelete
  3. Hey,

    please change the default block size in coap.py file. Look for the lines:

    DEFAULT_BLOCK_SIZE_EXP = 2 # Block size 64
    """Default size exponent for blockwise transfers."""

    Change this value to 6 - it should rise the limit to 1024.
    Unfortunately there is no proper configuration method for this.
    Regards

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Hey, Thank you. It works great now.
    Cheers!

    ReplyDelete
  6. Perfect! Good luck with your project!

    ReplyDelete
  7. Hi,
    Trying to set server.py for ipv6 and got the following error:
    2016-10-30 22:06:22-0300 [Coap (UDP)] Received 'D\x01\x19\x12\x00\x00\xc6j`Ttest' from fe80::8164:728:c395:e3d9%eth0:55998
    2016-10-30 22:06:22-0300 [Coap (UDP)] Unhandled Error

    How should i configure it, and being able to choose another interface as well if possible?
    I believe it is within line reactor.listenUDP(...

    Best,

    ReplyDelete