Persistent USB Devices

This Forum is about the Opentherm gateway (OTGW) from Schelte

Moderator: hvxl

Post Reply
roblom
Starting Member
Starting Member
Posts: 40
Joined: Wed Apr 16, 2014 9:18 pm

Persistent USB Devices

Post by roblom »

I have 1 RPi with 2 USB serial devices. One is a USB to RS232 cable to log my inverter. The other one is the USB cable of the OTGW.
The problem is that I think it are both pl2303 so the idVendor is both 067b and the idProduct is both 2303. The main problem is that they have both no serial number. Therefore i'm not able to set one persistent to USB21 and the other to USB22 (for example).

Code: Select all

[    3.979164] usb 1-1.3.3: new full-speed USB device number 6 using dwc_otg
[    4.112200] usb 1-1.3.3: New USB device found, idVendor=067b, idProduct=2303
[    4.131437] usb 1-1.3.3: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[    4.153235] usb 1-1.3.3: Product: USB-Serial Controller
[    4.168873] usb 1-1.3.3: Manufacturer: Prolific Technology Inc.
[    4.278949] usb 1-1.3.1.3: new full-speed USB device number 7 using dwc_otg
[    4.411239] usb 1-1.3.1.3: New USB device found, idVendor=067b, idProduct=2303
[    4.425683] usb 1-1.3.1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[    4.438136] usb 1-1.3.1.3: Product: USB-Serial Controller
[    4.448860] usb 1-1.3.1.3: Manufacturer: Prolific Technology Inc.
Somebody a solution to this?
ThinkPad
Member
Member
Posts: 75
Joined: Sat Nov 15, 2014 1:49 pm

Re: Persistent USB Devices

Post by ThinkPad »

Interesting problem. I use this: http://www.domoticz.com/wiki/PersistentUSBDevices for Domoticz (Raspbian image).
But my PL2303 all have no serial number indeed, so it is hard to keep them separated.

I will follow this thread to see if someone has a good solution.
roblom
Starting Member
Starting Member
Posts: 40
Joined: Wed Apr 16, 2014 9:18 pm

Re: Persistent USB Devices

Post by roblom »

I think I already found one.
Udevadm info starts with the device specified by the devpath and then walks up the chain of parent devices. It prints for every device found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device and the attributes from one single parent device.

Code: Select all

udevadm info -a -n /dev/ttyUSB1
Gives for the first

Code: Select all

looking at parent device '/devices/platform/bcm2708_usb/usb1/1-1/1-1.2':
    KERNELS=="1-1.2"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bDeviceProtocol}=="00"
    ATTRS{devpath}=="1.2"
    ATTRS{idVendor}=="067b"
    ATTRS{speed}=="12"
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{busnum}=="1"
    ATTRS{devnum}=="4"
    ATTRS{configuration}==""
    ATTRS{bMaxPower}=="100mA"
    ATTRS{authorized}=="1"
    ATTRS{bmAttributes}=="80"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{maxchild}=="0"
    ATTRS{bcdDevice}=="0300"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{quirks}=="0x0"
    ATTRS{version}==" 1.10"
    ATTRS{urbnum}=="1486"
    ATTRS{ltm_capable}=="no"
    ATTRS{manufacturer}=="Prolific Technology Inc."
    ATTRS{removable}=="removable"
    ATTRS{idProduct}=="2303"
    ATTRS{bDeviceClass}=="00"
    ATTRS{product}=="USB-Serial Controller"
And for the other

Code: Select all

looking at parent device '/devices/platform/bcm2708_usb/usb1/1-1/1-1.3':
    KERNELS=="1-1.3"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bDeviceProtocol}=="00"
    ATTRS{devpath}=="1.3"
    ATTRS{idVendor}=="067b"
    ATTRS{speed}=="12"
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{busnum}=="1"
    ATTRS{devnum}=="5"
    ATTRS{configuration}==""
    ATTRS{bMaxPower}=="100mA"
    ATTRS{authorized}=="1"
    ATTRS{bmAttributes}=="a0"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{maxchild}=="0"
    ATTRS{bcdDevice}=="0300"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{quirks}=="0x0"
    ATTRS{version}==" 2.00"
    ATTRS{urbnum}=="64"
    ATTRS{ltm_capable}=="no"
    ATTRS{manufacturer}=="Prolific Technology Inc."
    ATTRS{removable}=="removable"
    ATTRS{idProduct}=="2303"
    ATTRS{bDeviceClass}=="00"
    ATTRS{product}=="USB-Serial Controller"
Then look at the differences and ad one that is different to the 99-usb-serial.rules file.
If you put in the USB always at the same fysical port you can use the ATTRS{devpath}=="1.3" and ATTRS{devpath}=="1.2". Then you have to place the code below in the 99-usb-serial.rules file.

Code: Select all

SUBSYSTEM=="tty", ATTRS{devpath}=="1.2", ATTRS{idVendor}=="067b", ATTRS{idProduct}=="2303", SYMLINK+="ttyUSB12"
SUBSYSTEM=="tty", ATTRS{devpath}=="1.3", ATTRS{idVendor}=="067b", ATTRS{idProduct}=="2303", SYMLINK+="ttyUSB13"
hvxl
Senior Member
Senior Member
Posts: 1965
Joined: Sat Jun 05, 2010 11:59 am
Contact:

Re: Persistent USB Devices

Post by hvxl »

Why use names that look like what the system might generate (and may cause conflicts if you add enough of these devices)? I'd go for names that refer to what the devices are used for, like otgw and solar. That way you can point otmonitor to /dev/otgw and not having to remember if it was ttyUSB12 or ttyUSB13 you needed for otmonitor.
Schelte
roblom
Starting Member
Starting Member
Posts: 40
Joined: Wed Apr 16, 2014 9:18 pm

Re: Persistent USB Devices

Post by roblom »

That's because it is stated in the Domoticz wiki about persistent USB devices. There it says it's better not to use names. So I blindly followed that :-)
But it seems that I still had some trouble. Domoticz keeps crashing after a while when I have the script running that monitors the PV system and the OTGW through Domoticz. They both work for a while so it seems that the connection to the USB ports work.
hvxl
Senior Member
Senior Member
Posts: 1965
Joined: Sat Jun 05, 2010 11:59 am
Contact:

Re: Persistent USB Devices

Post by hvxl »

Oh, I didn't look at the link before. It does say that, but doesn't provide any explanation why. It might be a silly limitation of Domoticz then (or just superstition of the person who wrote that wiki page), because I use that with other programs all the time.
Schelte
hvxl
Senior Member
Senior Member
Posts: 1965
Joined: Sat Jun 05, 2010 11:59 am
Contact:

Re: Persistent USB Devices

Post by hvxl »

I just checked the Domoticz sources. It imposes this limitation because it doesn't use the correct method to find serial ports. It just looks for /dev/ttyUSB*, /dev/ttyS*, /dev/tty.usbserial*, or /dev/ttyAMA*. So, for Domoticz you will have to continue to use ttyUSBxxx (or get Domoticz fixed).
Schelte
ThinkPad
Member
Member
Posts: 75
Joined: Sat Nov 15, 2014 1:49 pm

Re: Persistent USB Devices

Post by ThinkPad »

hvxl wrote:I just checked the Domoticz sources. It imposes this limitation because it doesn't use the correct method to find serial ports. It just looks for /dev/ttyUSB*, /dev/ttyS*, /dev/tty.usbserial*, or /dev/ttyAMA*. So, for Domoticz you will have to continue to use ttyUSBxxx (or get Domoticz fixed).
Thanks for searching, i added the reason on the wiki.
roblom
Starting Member
Starting Member
Posts: 40
Joined: Wed Apr 16, 2014 9:18 pm

Re: Persistent USB Devices

Post by roblom »

The OTGW does 3 cycles (about 3x30 sec.) And then nothing any more. Then is restarted by the embedded restart function and it works again for about 3 cycles.

There is something going wrong but there are no errors in the Domoticz log shown.

The solar script was working without errors for about a year but since I added the OTGW to the RPi it is unstable to. The script is working outside Domoticz it only uses json to put the data in Domoticz.

So the problem is that I don't know where to look for to solve the problem.
roblom
Starting Member
Starting Member
Posts: 40
Joined: Wed Apr 16, 2014 9:18 pm

Re: Persistent USB Devices

Post by roblom »

It seems that I found the solution.
According to the RPi website.
GENERAL LIMITATIONS

The OTG hardware on Raspberry Pi has a simpler level of support for certain devices, which may present a higher software processing overhead. The Raspberry Pi also has only one root USB port: all traffic from all connected devices is funnelled down this bus, which operates at a maximum speed of 480mbps.
The USB specification defines three device speeds - Low, Full and High. Most mice and keyboards are Low-speed, most USB sound devices are Full-speed and most video devices (webcams or video capture) are High-speed.
Generally, there are no issues with connecting multiple High-speed USB devices to a Pi.
The software overhead incurred when talking to Low- and Full-speed devices means that there are soft limitations on the number of simultaneously active Low- and Full-speed devices. Small numbers of these types of devices connected to a Pi will cause no issues.
So the USB port of the Pi is full speed only it is splitted. That explains why I have trouble using the OTGW and the serial cable to my Inverter at the same time.
After a tip of someone at the Domoticz forum I used the cheapest USB hub I could find at home and it seems that it is working now. Domoticz hasn't crashed yet and the data from the OTGW keeps updating.
I only do not completely understand why the cheap hub solution works....
Post Reply

Return to “Opentherm Gateway Forum”