Sheevaplug + Python Daemon + MySQL = RS232 Logging Made Easy

Picture of Sheevaplug + Python Daemon + MySQL = RS232 Logging Made Easy
So, you've got some kinda RS232 device and you want to log a bunch of data from it. No problem. What you need is a little Sheevaplug. The Sheevaplug is a 5 watt full blown solid state Linux box running at 1.2 GHz. Now, how cool is that?

Here is a link for a bunch more info on the Sheevaplug:

I think the Sheevaplug is just so darn neat. All that juice in the palm of your hand.

Just recently I re-flashed my old Sheevaplug with the new Ubuntu 9.04 Arm build. After the re-flash the USB/RS232 cables started working for the first time. Seems there was some problem with the old Debian build.

OK, so here is the deal, I'm playing with a bunch of Zigbee radios that generate a few RS232 messages every second. I want to log all those messages so I can analyze them later. Just shoving all those strings into a text file would not be difficult. But, that makes it hard to handle. Plus, it would make it hard to look at the data while the data being collected. Also consider, I'm collecting data for weeks and weeks. Just how big that text file would grow is anybodies guess.

The solution to large amounts of data is a MySQL database. And the solution to pumping data into a MySQL database is Python.

Read on to understand all the plumbing involved in getting your Sheevaplug to pack all that data into a database for you.

Can you tell I'm rather smitten with the Sheevaplug? Disclaimer, although it sounds like I'm a salesman for the Sheevaplug, I'm not. I have no personal interest in the plug other than I think it is cool.
Remove these adsRemove these ads by Signing Up
storm0171 year ago
I'm trying your script but directly reading to Mysql. This is my first python script. I'm having an issue loading the data into the db. Here is the code:

import serial
import MySQLdb
ser = serial.Serial( '/dev/ttyUSB1', 9600, timeout=1 )
conn = MySQLdb.connect( host='localhost', db='Weatherboard', user='rich', passwd='wordpass' )
curs = conn.cursor()

s = ser.readline().strip("\r\n")

curs.execute( 'insert into weatherdata (humiditycol, sht15tempcol, scp1000tempccol, scp1000presscol, scp1000tempfcol, temt6000lightcol, batterycol) \
values (%s, %s, %s, %s, %s, %s, %s)', (humidity, sht15temp, scp1000tempC, scp1000press, scp1000tempF, temt6000light, battery))

The error I'm receiving is the Name humidity is not defined.
Do you see a issue with the code.
jimk3038 (author)  storm0171 year ago

Forgive me, it's been a long time since I used any of this stuff. I'm going to be rusty with this stuff.

I don't see anything directly wrong with your source code.

Here are a couple of things I would check. Use a "print" statement just before the "curs.execute" to make sure "humidity", as well as all the variables, are defined. Also, make sure all the database table column names are defined and spelled correctly. Awful easy to get the name just slight wrong. Lastly, check your database permissions to make sure user "rich" with "wordpress" password has permission to write to the database. You can use the SQL Tools to verify database table names. You can also run your "insert into" query in SQL Tools to make sure it works. Just form the insert query with some dummy data to test with.

The problem with this stuff is everything must be formatted perfectly for any of it to work. However, it is sweet when it does all work!

Good luck,
MY3 years ago
So true Jim! One decade's supercomputer is the next decade's consumer appliance, and one decade's "toy" is the next decade's indispensable business tool!
dukechem4 years ago
I've been googling for an hour and looking at spec sheets, but cannot find if the dev-kit comes with any sort of serial cable, be it rs232 and/or usb.

Seems there may be commands to switch the FT2232DF between rs232 and usb mode?

Can you provide any details on the cable connecting to your Zigbee(s), and are you using the rs232 or usb port of the radio(s)?  I want to gather data from old instruments that may use rs232-signals with voltages higher than TTL (plus or minus 5 volts max), typically +12 or -12 volts I think. Currently these connect to laptop com1 port via 9-pin-D connectors.

The spec-sheet for the FT2232DF chip seems to say you need a TTL-to-RS232 voltage-level converter if you were to connect to a older devices with higher-voltage rs232 signals.

You say "The following python code opens a serial port...:
ser = serial.Serial( '/dev/ttyUSB0', 115200, timeout=1 )"

I assume this must be the usb-connector as 232 is not mentioned at:

I guess what I'd like to know is what are the pin-outs and voltages of the connector named "JTAG UART RS232" at:

Then I could figure out if I needed a voltage-clipper to use it to talk to my instruments.
One reader suggests a $4 dollar usb-to-db9 adapter here:

I suspect this would be needed for any "kinda rs232 device", right?  And you were talking to your devices with a cable similar to the usb cable as used with a printer or camera?

jimk3038 (author)  dukechem4 years ago
I've attached a picture of the cable I'm using. Here is also a link to the cable:

The cable I'm using level shifts down to 3.3V that my Zigbee board expects.

However, I think most any USB to RS232 cable that is based on the FTDI chip will work. Plugging in a USB / RS232 cable makes the port appear in /dev/ttyUSBx on the Plug computer. The Plug does not know, or care, what actual voltage level is being used on the other end of the cable.

So, to answer your question (at least I hope I'm answering it), no, there is no switch on the Plug. The Plug has a mini USB port that allows many different devices to be plugged in. The Plug automatically detects the device type and loads the device driver automatically. Its that automatic load feature that makes the RS232 cable appear as /dev/ttyUSBx.

In fact, the Plug support a USB hub attached to that mini USB port. With a hub attached, the Plug could handle bunches of simultaneous comm ports.

As an example, logging into the Plug using telnet, I just executed the command "lsusb" to get a list of all connected devices. The response on my Plug was:

Bus 001 Device 002: ID 0403:6001 Future Technology Devices International, Ltd FT232 USB-Serial (UART) IC
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

So, there is an internal root hub and the FTDI cable on my system.

If I haven't answer your question just shoot me another reply to this email.

Hope this helps & Good Luck,
frollard4 years ago
I too saw the HAD note about the guruplug today, then noticed this;

I've been itching for a reason to get one - but really, how often does the end user need to log ...anything.  I'd maybe want one as a firewall...

I just can't see using one for virtually anything though :S
jimk3038 (author)  frollard4 years ago

You gotta be kidding me. I can think of a thousand, and one, uses for one of these babies. It's kinda like saying, “What would people use an embedded Linux box for, anyway?” Holy Cow!

Note, I miss read the Hack-A-Day announcement. Looks like even the base $100 dollar GuruPlug has both WiFi and Bluetooth. So, here is a 5 watt wall wart that has two radios, two USB ports, a eSATA port, and a MicroSD slot.

So many goodies I just don't know where to begin.

I totally agree its a fantastic product; I just can't think of anything to use it for that isn't already tasked by a very small simple device!

Short of a very very full featured router or data logger I can't think of much it would excel at. It has no visual interface by default, so it's relegated to the 'automate' field of computing, which is sadly already taken up with modules in a larger computer system for most people.

For me, I guess it's like trying to come up with 'how to use an arduino' all by itself.  You can blink leds, log data, make an autonomous robot...etc - but until it's been fuufuu dusted with the magic of applications that do the actual cool stuff, it's just a piece of hardware.  Don't get me wrong; I'm super techhy and love gadgety stuff - I just can't comprehend a use for this other than 'server'.
jimk3038 (author)  frollard4 years ago
I can understand what your saying. My new Sheevaplug sat on the shelf for months before I found a good use for it.

In the past I would dedicate an old laptop to this kind of data logging task. It would run for months. I'd check on it from time-to-time to make sure the kids didn't fool with. With old worn out batteries I would have to make sure power outages didn't mess it up either. I would always feel guilty with the amount of heat rolling off the laptop too. For simple tasks - the laptop is so inefficient. The Sheevaplug has made me not feel guilty any more.

I'm also thinking of giving the Sheevaplug other tasks too. I've got a bunch of external USB drives that the Plug can turn into shared drives. It can do this while also logging my data. No extra anything required - just plug them in.

For an interface, I use simply use "ssh plug -l username" where "plug" is in my hosts file. I can open as many terminals as I want with each one running over Ethernet at a 100 Mega bits. Right out of the box, the Plug also supports shared files so the Plug shows up in file explorer. Very handy.

The new Guruplug sounds cool too. Having both WiFi and Bluetooth is just begging for something. How about controlling X10 with a Bluetooth phone? I hear folks are jacking in USB cameras for home security too. The Plug takes a picture once per minute and saves it off. At the end of the day, all the snapshots are assembled into an mpeg movie. All done on the Plug.

I also agree with you that the "fuufuu dust" is a hassle. However, that is what separates us from the rest. If you haven't played much with Python, give it a try. There are so many modules already written - it makes app development so much easier. The Python serial module is an example. Takes 10 seconds to install with the apt-get command. Takes just three, or four, lines of code to open and read strings. Now, how cool it that. Try opening a serial port using .Net - I'm not even sure you can any more using the latest release.

Anyway, sorry for the rant, I'm just so smitten with my little Plug,
Agreed 100% with everything there; great info.  Camera server is the best use that I could reasonably use in the next while::  I have an ip camera, guruplug == 2 ethernet ports.

Serial in .net is possible, but it's abstracted through so many layers and controls that you can barely use it for terminal ASCII data.  Try bit-banging one. BAH.

I digress.  Cool tech.  The video points out using hundreds of these in places you wouldn't expect - an automated milk-buying fridge, etc.  It just seems like too much power for most small tasks, and not enough power to be a standalone computer.  Five watts is unbeatable though.
jimk3038 (author)  frollard4 years ago

Have a look at the attached image. The top shelf is my "computer room". The two laptops on the left are my Drupal / Apache web servers. I have a primary and a backup - only the primary is powered. If you hit my web site at the pages come off that top laptop.

Anyway, I count over a dozen "electronics" devices on that shelf. Guess which one is the most powerful. Yep, the little Sheevaplug in the middle.

Your right, for small tasks it might be too much.

But for stand-alone it seems fine to me. We're talking 1.2GHz here! Plus, no stupid GUI to slow it down either. It's just like being back at Purdue in the late 80's. We logged into a super computer using serial terminals (I think running at 9600 baud). The little Sheeva is probably fast than those old Super Computers who hosted hundreds of students simultaneously. Just amazes me.

I don't want to sound argumentative, but, if 1.2GHz it's enough, well then, I guess we'll just have to wait another 18 months for Moore's law to kick and double the performance again. I love techno advancement.

Just my two cents,

Get More Out of Instructables

Already have an Account?


PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!