port 1 disabled by hub (EMI?), re-enabling and wview weather

Me and a friend recently reinstalled a crashing Windows XP minipc used as weather station with Ubuntu 13.10 server. Since Linux is normally better working than Windows we thought it could be a good move, also because from time to time XP had to be rebooted. We choose wview as management software, as it seems pretty popular.

Sadly the day after installation and configuration we found Ubuntu to be less reliable than before. Well, maybe it wasn’t a Linux fault, it’s probably just more sensitive to some hardware issues. The culprit was found to be EMI (ElectroMagnetic Interference). Syslog showed the following:

hub 4-0:1.0: port 1 disabled by hub (EMI?), re-enabling...
usb 4-1: USB disconnect, device number 2
cp210x ttyUSB0: cp210x converter now disconnected from ttyUSB0
cp210x 4-1:1.0: device disconnected
usb 4-1: new full-speed USB device number 3 using uhci_hcd
usb 4-1: New USB device found, idVendor=10c4, idProduct=ea60
usb 4-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
usb 4-1: Product: CP2101 USB to UART Bridge Controller
usb 4-1: Manufacturer: Silicon Labs
usb 4-1: SerialNumber: 0001
cp210x 4-1:1.0: cp210x converter detected
usb 4-1: reset full-speed USB device number 3 using uhci_hcd
usb 4-1: cp210x converter now attached to ttyUSB1

The usb port has been reset, /dev/ttyUSB0 disconnected and rediscovered as /dev/ttyUSB1. At this point the wview damon would try accessing an inexistent device and will crash. Apparently there’s no solution to the source of the problem, the only solution is to handle it. Restarting the server on every disconnect was too much, someone suggested to monitor the log file for these messages and restart wview accordingly, but again this is a passive approach. What manages /dev? udev! So why not delegating to udev the handling of the problem?

I have to thank this wview mailing list post for the suggestion. I then decided to post my solution here in the hope it could be useful for others.

First, create the file /usr/local/bin/restart_wview.sh with the following content:

#!/bin/bash

# Restart wview after usb replug
# @author: Lorenzo Milesi <io@maxxer.it>

LOGFILE="/var/log/`basename $0`.log"

DATEFMT="+%Y.%m.%d.%H.%M"
echo -e "`date $DATAFMT` executing..." > $LOGFILE 

# First check wview is already running. The udev script could be triggered on boot, when the daemon is not launched yet
PROCS=`pgrep -c '^wview.*' `
echo -e "`date $DATAFMT` wview process count: $PROCS" >> $LOGFILE 
if [ $PROCS -ne 0 ] ; then
        echo -e "`date $DATAFMT` Restarting" >> $LOGFILE 
        #wview is running, stop it
        service wview stop >> $LOGFILE 2>&1
        sleep 5;
        # Remove any stale pid it could be left around if the wview daemon crashed before we could stop it
        rm /var/lib/wview/*.pid
        service wview start >> $LOGFILE 2>&1
else
        echo -e "`date $DATAFMT` Not doing anything (boot?)" >> $LOGFILE 
fi

Make it executable with the command chmod +x /usr/local/bin/restart_wview.sh, then create another file /etc/udev/rules.d/99-vantagepro.rules with this content:

# Create /dev/vantagepro symlynk, restart wview on USB replug
# https://groups.google.com/forum/#!topic/wview/wiE_lHBPN7Y
ACTION=="add", SUBSYSTEM=="tty", ENV{ID_BUS}=="usb", ENV{ID_VENDOR_ID}=="10c4", ENV{ID_MODEL_ID}=="ea60", SYMLINK+="vantagepro", RUN+="/usr/local/bin/restart_wview.sh"

Note: the ID_VENDOR_ID and ID_MODEL_ID values are based on my case (Vantage Pro 2). You can easily find your own with the command lsusb:

Bus 003 Device 002: ID 10c4:ea60 Cygnal Integrated Products, Inc. CP210x UART Bridge / myAVR mySmartUSB light

Configure wview to use /dev/vantagepro as device, restart your Ubuntu server (or issue udevadm control –reload-rules and replug the usb cable). You should be done!

Un pensiero su “port 1 disabled by hub (EMI?), re-enabling and wview weather

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *

Solve : *
20 − 12 =


Questo sito usa Akismet per ridurre lo spam. Scopri come i tuoi dati vengono elaborati.