Reading a Seneye using a Raspberry Pi – USB devices

I recently purchased the excellent Seneye aquarium monitor. It is a small device with that sits in a fish tank and monitors various parameters.

home2

I’d been looking for a simple device like this for some time – not too complex, not too expensive. It may not sense some parameters needed in a marine tank however it does do the basics such as temperature, in/out of water, ammonia and pH. As I mentioned before, water chemistry is difficult and you shouldn’t knock those who have tried. Other devices are more complex, expensive, or actually never successfully made it to market. In essence it reads the colour change of a litmus strip by comparing it to a sealed reference, as well as temperature and water refraction.

The challenge came about because although they have a cloud solution that transmits readings every 30 minutes, the device itself has to connect to a Windows PC and thence to the cloud. I’d looked at running a low-powered Windows SBC or even purchasing Seneye’s always-on connection device, but the easiest seemed to be to read the USB device.

USB devices

USB devices are a wonder to behold. They do a lot of work internally and the USB protocol spec runs for many pages. I looked for libraries to help me read the device and found a couple which work in Python, my language of choice. USB also delineates a special form of device known as the ‘HID’, or Human Interface Device. These are things such as USB mice, track-pads and keyboards. They have a simpler interface and only use a couple of the modes of transfer: control, and interrupt.

Walking the USB tree

As USB devices have a hierarchical protocol we need to find out some things about it.

  1. Device
  2. Configuration
  3. Interface
  4. Alternate setting
  5. Endpoint

We start by looking at the device itself using Linux commands and the udevadm command. The udevadm command may not be installed on your system and should be installed using your distro’s package manager.

Firstly, using lsusb we get to see where our device is sitting on the bus – and note that this changes every time we plug it in.

lsusb
Bus 002 Device 089: ID 24f7:2204

… so our device is on the bus number 2, and is at device number 89. Now, using udevadm we can test this and get the device characteristics:

udevadm info -a -p $(udevadm info -q path -n /dev/bus/usb/002/089)
looking at device '/devices/pci0000:00/0000:00:14.0/usb2/2-1':
    KERNEL=="2-1"
    SUBSYSTEM=="usb"
    DRIVER=="usb"
    ATTR{authorized}=="1"
    ATTR{avoid_reset_quirk}=="0"
    ATTR{bConfigurationValue}=="1"
    ATTR{bDeviceClass}=="00"
    ATTR{bDeviceProtocol}=="02"
    ATTR{bDeviceSubClass}=="00"
    ATTR{bMaxPacketSize0}=="64"
    ATTR{bMaxPower}=="250mA"
    ATTR{bNumConfigurations}=="1"
    ATTR{bNumInterfaces}==" 1"
    ATTR{bcdDevice}=="0125"
    ATTR{bmAttributes}=="80"
    ATTR{busnum}=="2"
    ATTR{configuration}==""
    ATTR{devnum}=="89"
    ATTR{devpath}=="1"
    ATTR{idProduct}=="2204"
    ATTR{idVendor}=="24f7"
    ATTR{ltm_capable}=="no"
    ATTR{manufacturer}=="Seneye ltd"
    ATTR{maxchild}=="0"
    ATTR{product}=="Seneye SUD v 2.0.16"
    ATTR{quirks}=="0x0"
    ATTR{removable}=="removable"
    ATTR{serial}=="F500214755881923AEAEA4260100D020"
    ATTR{speed}=="12"
    ATTR{urbnum}=="32"
    ATTR{version}==" 2.00"

From this we can see that the device has one configuration and one interface. It also contains the device’s serial number. Other notable things are the maximum packet size, and the power requirements. That number of interfaces response is a little odd?

Advertisements

2 thoughts on “Reading a Seneye using a Raspberry Pi – USB devices

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s