Skip to content

Wireless Projects over the Web: Digi Dia for Hackers Part 1

2011 May 2

Suppose you want to log data from a group of sensors, like temperatures around the house, or turn lights on and off remotely via a webpage, and you want to do this wirelessly.  You could use a WiFi shield for an Arduino, but they’re notoriously hard to set up and stay reliably connected.

My preferred way uses Digi XBee radio modules with the ConnectPort gateway, which connects a network of XBee modules with a LAN over ethernet.  So far, easy: build your microcontroller project that sends and receives data via an XBee ZigBee module (using “Series 2” hardware), and the ConnectPort is your mesh’s coordinator.

Then the question becomes how to send and receive the data from the coordinator.  If you had the coordinator plugged into a computer, you could write an interface however you liked.  Lucky for us, the ConnectPort is basically a tiny computer that runs Python!  So how do you access your project’s data via the ConnectPort over the web?There are two overall approaches: transmit to another webserver, or use the ConnectPort as a webserver itself.  XBee fiend Rob Faludi and I developed a handy way to do the first approach, called the XBee Internet Gateway (XIG), and Digi mastermind Jordan Husney vastly improved it.

XIG’s one ability is simple but hugely useful: it allows your Arduino to retreive a URL from the Internet.  Say you’re collecting temperatures from sensors via your microcontroller.  With XIG, you can post the values to a web script on a server somewhere by sending this string to the ConnectPort: “http://my.server.com/myscript.php?val1=6&val2=10&etc=etc”.  Your script can then optionally return some string for your Arduino to parse and use.

This is fast, easy, and effective!  Its only downside is that you need an external webserver to get the data moving.  For many of us, this is no problem, but wouldn’t it be nice to cut out the middleman?

Enter Digi’s Dia platform.  Dia (Device Integration Application) is a Python program that runs on the ConnectPort that talks to your XBees and—the important part—runs its own web server so you can talk directly to the ConnectPort instead of using an external web server.

Now, Dia is a fairly new platform, and definitely designed for engineers more than hackers like ourselves.  So I did a deep dive into the platform recently and have brought the results to you!  Stay tuned for the next part!

Related Posts:


10 Responses
  1. Julien permalink
    July 19, 2011

    I’ve tried uncessfully to do just that… can’t wait to read your part2!

    • July 19, 2011

      Thanks—working on it! I’ll try to get it up ASAP :)

  2. August 17, 2011

    Count me in, waiting for the follow-up post. I love the arduino, but for most of my projects, I don’t need it in my stack. I attach sensors directly to the xbee module.

    My setup has been a little different in that I’ve been using an ASUS WL520GU wifi router as my gateway. It has an xbee receiver soldered to an internal serial port. I re-flashed the wifi with OpenWRT and then added python. It was tricky but now it’s done.

    In my python scripts I’ve been able to hook into Pachube.com, Thinkspeak.com and Open.Sen.se. These are all data logger services with slightly different APIs but that offer data storage, charting and triggers.

    I’m now looking at a Digi X2 with a Smart Plug and the XIG lib looks like a path to getting some values delivered to these data logger web services. I see samples for PHP and Arduino, but none for good old python. Is there a reason, or just haven’t gotten around to it? My goal is to collect the data from a device like the Smart Plug and deliver it to web services from a python script running in the gateway.

    I look forward to your next post about the XIG and Dia.

    • August 17, 2011

      Wow, awesome—a DIY connectport! I can highly recommend the X2, it really works nicely and the non-industrial enclosure version is downright cheap.

      It’d be easy to write a Python data logger web service; I think many people just tend to use PHP more for general-purpose web scripts (I’d rather use Python any day over PHP). However, part of the point of the ConnectPort for me is not having to have an additional web server, because Dia is set up to provide a web interface directly on the unit. Good for local administration but not if it’s going to be opened to the internet at large 😉

      Getting Xig up and running is easy, and provides a very quick way of letting your XBees talk to the internet. Dia is VASTLY more complicated, but worth the trouble if you want a web interface right there on your X2. I dearly hope I can put together the next Dia post in the next month, but I’ve got to make sure my clients are happy first 😉 Thanks for your feedback!

    • Siegfried Loeffler permalink
      October 14, 2011

      Chris

      can you share a bit more detail on how you managed to launch they Python on your OpenWRT router? I have the same configuration as you, and I’d really like to get rid of my X4, as it consumes energy for something that should in principle be possible with my existing ASUS WiFi router (which has quite a lot of RAM and Flash, and which has a USB port, so I don’t see why it shouldn’t be possible…).

      I’m not sure to have fully understood if you used your own Python code on OpenWRT or if you also successfully used XIG on the OpenWRT device?

      Siegfried

  3. August 17, 2011

    I understand keeping the clients happy. Muy, importante…

    Just to clarify, quickly, the scripts I’ve developed in python run within the Asus Gateway (my DIY x2, $35 at NewEgg). The web services I’m accessing are http://ThingSpeak.com, http://Open.Sen.se, and http://Pachube.com (the equivalents of the PHP service examples).

    Now I’m learning the X2.

    I saw the XIG example code where you’ve written the web service in PHP and the web requests in Arduino code. I don’t have any arduino based sensors, just xbee modules with analog voltages on the analog inputs. I only have python scripts (loaded into the X2) and I’m trying to figure out if I can use XIG to send web requests from a python script, or perhaps I need to re-engineer the XIG or create something like it.

    The example method below is what I use to send data to ThingSpeak from my DIY X2. It requires a python package called urllib. Not sure yet if I can add that to the X2. We’ll see.

    I’ll check back in Sept,
    Chris.

    # ————————-
    def logtothing(lnSensorNum, lnAvgUnits, lcThingSpeakKey, fieldnum):

    if lcThingSpeakKey == “”:
    return

    feedUrl = THINGSPEAKURL + “:80”
    fieldname = “field” + str(fieldnum +1)

    try:
    # define a Python data dictionary
    params = urllib.urlencode({fieldname : lnAvgUnits,’key’:lcThingSpeakKey})
    headers = {“Content-type”: “application/x-www-form-urlencoded”,”Accept”: “text/plain”}

    conn = httplib.HTTPConnection(feedUrl)
    conn.request(“POST”, “/update”, params, headers)
    response = conn.getresponse()
    data = response.read()
    conn.close()

    except Exception, e:
    print “Exception: “, feedUrl, ” – “, str(e)

  4. Jeff permalink
    December 28, 2011

    waiting for part 2 !!

  5. January 8, 2012

    I’m waiting for part 2! I have a bunch of XBee-connected Arduinos and ConnectPort X2 and it is a really nice device for its price. Currently I’m using Arduion+Ethernet shield as my “internet gateway” and it is a limited solution (I’ve already almost maxed out Arduino’s flash with a project that periodically uploads all the collected data to Pachube). However, I cannot run even a simple iDigi Dia sample on ConnectPort X2, because it does not have enough memory and slow, undereliably uploads a very large dia.zip file (which is still large even in minial RCI-only presentation config).

    So, inspired by XIG, I plan to write my own internet-to-xbee-network gateway. Any insight in this direction will be highly appreciated.

    • January 8, 2012

      Yeah, the memory limitation on the X2 is frustrating. How big is your dia.zip file? It shouldn’t be any larger than 500k, in my experience…?

  6. Slim permalink
    December 23, 2012

    There is no next part…you have never made up to your promise…..not good my man

Comments are closed.