Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Building Embedded Systems with Twisted

Building Embedded Systems with Twisted

Twisted is an asynchronous networking engine written in Python. This talk will show how we, at Zilogic Systems, built an automated library management system, using Twisted and an ARM board running Emdebian Grip. The system uses an RFID reader for user authentication, reed switches to monitor the shelves and a buzzer to raise alerts.

Vijay Kumar

October 23, 2014
Tweet

Other Decks in Programming

Transcript

  1. The Problem Lots of shared resources in any office. books,

    CDs development kits, add-ons, pen drives, sdcards, SIM cards, … Engineers use these resources to complete their task. What happens after the task is completed? left at the engineer’s workplace, and then forgotten. stored in some randome location, and then forgotten. handed over to another engineer, and to another, … and many such possibilities, resulting in the resource getting lost.
  2. The Solution Use a shelf to keep all the resources

    to be tracked. Use a notebook to track the resources. When an engineer takes a resource from shelf, an entry is to be made.
  3. Pitfalls Does not work! Day 1: entries were made. Day

    2: few people made the entry. Day 3: the notebook was gone! There is no way to intimate the user to return back the item, after use.
  4. Restate the Requirements A shelf - for resources to be

    tracked. The system should track who took a resource, from the shelf. The system should intimate the engineer to return the resource, after a period of one week. Should be fully automated - no human intervention. Return of the resource, and renewal of the resource can be manual.
  5. Design Each engineer is given an RFID card. Each resource

    to be tracked has an RFID tag. Every time the engineer has to take a resource Swipes his RFID card Swipes the RFID tag of all the resources An embedded system takes this information and pushes to a server on the Internet. The server will then intimate the engineer after a period of 1 week, to return the resource or renew.
  6. RFID Serial Data Format Each RFID card contains a unique

    10 byte ID string. When the RFID card is swiped, the reader produces the following string. LF D0 D1 D2 D3 D4 D5 D6 D7 D8 D9 CR
  7. Twisted based RFID Listener from twisted.internet import reactor from twisted.protocols.basic

    import LineReceiver from twisted.internet.serialport import SerialPort class RFIDListener(LineReceiver): def __init__(self, app_sm): self.delimiter = '\r' self.app_sm = app_sm def lineReceived(self, line): rfid = line.lstrip() print rfid app_sm = AppSM() rfid_listener = RFIDListener(app_sm) SerialPort(rfid_listener, "/dev/ttyS0", reactor, 9600) reactor.run()
  8. Platform Atmel AT91SAM9260: ARM9, 180 MHz, 64MB SDRAM Runs Embedded

    Debian Grip distribution off an SD-Card. Python and Twisted Debian packages installed.
  9. How to Enforce It? Anybody can take an item without

    swiping his card or the resource! Not on purpose, but … Engineers are forgetful. In a hurry, to complete the task. New engineers do not know the system.
  10. Alerts and Tripwires Rig up the shelf with a tripwire.

    Raise an audible alert, if the shelf is opened without a card swipe. Reminds engineers, about the procedure!
  11. Reed Switch The reed switch is an electrical switch operated

    by an applied magnetic field. It consists of a pair of contacts on ferrous metal reeds in a airtight sealed glass envelope. The contacts may be normally open, closing when a magnetic field is present, … — Wikipedia
  12. Door Sensor Door sensor based on reed switch. Magnet on

    the door, reed switch on the frame.
  13. Twisted based Reed Switch Listener from serial import Serial from

    twisted.internet import reactor from twisted.internet.task import LoopingCall class ReedSwitchListener(object): def __init__(self, app_sm, serial_dev, baud): self.serial = Serial(serial_dev, baud) self.app_sm = app_sm loop = LoopingCall(self.__listen_reed) loop.start(0.5) def __listen_reed(self): print self.serial.getCTS() app_sm = AppSM() listener = ReedSwitchListener(app_sm, "/dev/ttyS0", 9600) reactor.run()
  14. Credits Reed Switch Animation from Wikimedia Commons by Stefan Riepl

    Reed Switch Photo from Wikimedia Commons by Andre Karwath RFID Reader Photo is from RhydoLabz. Door Sensor Photo is from Adafruit.