The first thing I discovered is that the te923con application has a bug in decoding UV index data from the station. The index jumps from .9 to 10.0. A simple patch to te923_com.h is required. This diff output actually is a change to a single line that I split up for clarity here:
@@ -138,7 +138,7 @@
}
else {
- data->uv = bcd2int( buf[18] & 0x0F ) / 10.0 +
bcd2int( buf[18] & 0xF0 ) +
bcd2int( buf[19] & 0x0F ) * 10.0;
+ data->uv = bcd2int( buf[18] & 0x0F ) / 10.0 +
bcd2int( ( buf[18] & 0xF0 ) >> 4 ) +
bcd2int( buf[19] & 0x0F ) * 10.0;
data->_uv = 0;
}
The next thing to address is the permissions problem. To this point, the only way to get data from the station was to be root. Otherwise, you get this error:
[mcp:…/te923/te923] te923con -D
Error while setting configuration (-1).
This is a generic issue with USB devices, and I found an item on a wiki (http://wiki.openstreetmap.org/wiki/USB_Garmin_on_GNU/Linux#Fixing_Device_Permissions) about GPS units that got me going.
That page discusses how to set the group ownership on the device, as well as the permissions on the device. Long story short, I created the device rule set /etc/udev/rules.d/99-te923.rules (all on one line):
ATTRS{idVendor}=="1130", ATTRS{idProduct}=="6801",
MODE="0660", GROUP="plugdev"
idVendor and idProduct identify the TE923 weather station, mode tells the USB driver to give read/write permissions to the user and group that owns the device, and group tells the driver to assign group ownership to “plugdev”. My user on the machine is a member of that group so I should be OK.
Ask the system to reload the USB rulesets:
[mcp:.../te923/te923] sudo udevadm control --reload_rules
And now I can get valid data back from the unit without being root:
[mcp:.../cwanek/cronjobs] te923con
1273414489::::59:::::::::1003.1:5.0:3:0:9:0.4:0.0:11.7:215
Unfortunately, though, some readings (specifically current temp readings) are empty. Even wide-open permissions on the device don’t help. This doesn’t make sense to me, and I have not yet solved this issue, so I’m still stuck with being root to run te923con. I’d love to know why it would work only partially.
Still, I don’t really want to have root’s crontab running the script, so I configured sudo to skip the password prompt for the group plugdev for the te928con application. With visudo, add:
%plugdev ALL=NOPASSWD: /usr/local/bin/te923con
Moving on, the I was still not able to run te923con without removing the USB human interface device module (sudo rmmod usbhid). While removing it allows access to the te923 station, it would also cause any other HID like a mouse or keyboard to stop functioning. So the trick is to get the usbhid module to release just the weather station.
There are many sites that document how to get usbhid to unbind a device. I found http://lwn.net/Articles/143397/, which gave me the following command:
sudo bash -c "echo -n 2-1:1.0 > /sys/bus/usb/drivers/usbhid/unbind"
bash -c is required so the shell redirection to unbind will succeed.
Digging deeper, I learned (http://reactivated.net/writing_udev_rules.html) that you can configure the unbind to happen immediately after the device is connected, by using the “RUN=” option in the device rules file (this is all on one line in /etc/udev/rules.d/99-te923.rules):
ATTRS{idVendor}=="1130", ATTRS{idProduct}=="6801",
MODE="0660", GROUP="plugdev",
RUN="/bin/sh -c 'echo -n $id:1.0 > /sys/bus/usb/drivers/usbhid/unbind'"
So now, apart from the missing data when running as a non-privileged user, the te923 weather station is coexisting with other USB devices, and I am able to schedule the upload script in my own user crontab.
There’s one last thing…