issue with USBDevice.read_data failed

39 views
Skip to first unread message

Marcin

unread,
May 21, 2023, 1:25:14 PM5/21/23
to pywws
Hi,

Jim first thanks for creating and supporting Pywws for so many years. 
I'm using if from 2012 running on router connected to WH2080 weather station  base. Since 2012 my original station broke - first by just not showing proper pressure then with years passing there were periodical errors with reading data that ended with not reading data at all so I replaced it 3 years ago with another WH3080 clone and its working fine since.
Recently I decided to replace my router from 2012 with new model as previous one was running with Extroot and breaking pendrive from time to time also I was running on old Python and on old pywws version from 2014 that was not supporting pip.

My new setup is Linksys EA6350 v4 running OpenWrt 22.03 and most recent Pywws 23.2. 
When I connected weather station to it it was throwing USBDevice.read_data errors with each of drivers I tested. 
As I know that my station is ok because it is running properly on old router I debug your code and found that actually data is returned from station but in 8 bytes chunks instead of 32 bytes at once. I modified your device_libusb1 code in read_data(self, size) function and instead executing self.dev.bulkRead(0x81, size, timeout=1200) one time I'm executing it 4 times and return  concatenation of results from function
Pywws is running fine after this change since yesterday but I don't know what can be implications - do you think it would freeze usb more often as it have to read 4 times instead of one?
Have anyone had such issue earlier?

Below libraries installed in python on new router:
root@OpenWrt:/mnt/pendr/weather# pip list
Package             Version
------------------- --------
bcrypt              3.1.7
certifi             2023.5.7
cffi                1.15.0
charset-normalizer  3.1.0
cryptography        3.4.8
idna                3.4
importlib-metadata  6.6.0
importlib-resources 5.12.0
libusb1             3.0.0
packaging           23.1
paho-mqtt           1.6.1
paramiko            2.10.1
pip                 23.0.1
pkg-about           1.0.8
ply                 3.11
pycparser           2.21
PyNaCl              1.5.0
python-dateutil     2.8.2
pyusb               1.2.1
pywws               23.2.0
requests            2.30.0
semantic-version    2.10.0
setuptools          65.5.0
setuptools-rust     1.6.0
six                 1.16.0
tomli               2.0.1
typing_extensions   4.5.0
tzlocal             5.0.1
urllib3             2.0.2
wheel               0.40.0
zipp                3.15.0

And output of cat /sys/kernel/debug/usb/devices for my station, its exactly the same for both routers
T:  Bus=01 Lev=02 Prnt=02 Port=01 Cnt=01 Dev#=  3 Spd=1.5  MxCh= 0
D:  Ver= 1.10 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 8 #Cfgs=  1
P:  Vendor=1941 ProdID=8021 Rev= 1.00
C:* #Ifs= 1 Cfg#= 1 Atr=80 MxPwr=100mA
I:* If#= 0 Alt= 0 #EPs= 1 Cls=03(HID  ) Sub=00 Prot=00 Driver=(none)
E:  Ad=81(I) Atr=03(Int.) MxPS=   8 Ivl=10ms

Regards
Marcin










Jim Easterbrook

unread,
May 21, 2023, 1:35:28 PM5/21/23
to py...@googlegroups.com
On 21/05/2023 11:51, Marcin wrote:
>
> My new setup is Linksys EA6350 v4 running OpenWrt 22.03 and most recent
> Pywws 23.2.
> When I connected weather station to it it was
> throwing USBDevice.read_data errors with each of drivers I tested.
> As I know that my station is ok because it is running properly on old
> router I debug your code and found that actually data is returned from
> station but in 8 bytes chunks instead of 32 bytes at once. I modified
> your device_libusb1 code in read_data(self, size) function and instead
> executing self.dev.bulkRead(0x81, size, timeout=1200) one time I'm
> executing it 4 times and return  concatenation of results from function

Do you simply call self.dev.bulkRead 4 times in succession or are you
requesting 8-byte chunks four times?

> Pywws is running fine after this change since yesterday but I don't know
> what can be implications - do you think it would freeze usb more often
> as it have to read 4 times instead of one?

If it's simply replacing one 32-byte read with four 8-byte reads then I
wouldn't expect any difference with USB hangups. I suspect the
difference is in the USB hardware on the Linksys.

> Have anyone had such issue earlier?

Not that I've heard about. It's an interesting discovery though - thanks
for reporting it.

--
Jim Easterbrook <http://www.jim-easterbrook.me.uk/>

Marcin

unread,
May 21, 2023, 2:20:46 PM5/21/23
to pywws
I just call it 4 times in a row, request is for 32 bytes as size parameter originally passed to function, tried to change it to 200 but still got only 8 bytes at a time
        result = self.dev.bulkRead(0x81, size, timeout=1200)
        result1=result
        result = self.dev.bulkRead(0x81, size, timeout=1200)
        result1.extend(result)
        result = self.dev.bulkRead(0x81, size, timeout=1200)
        result1.extend(result)
        result = self.dev.bulkRead(0x81, size, timeout=1200)
        result1.extend(result)
        if not result1 or len(result1) < size:
            raise IOError('pywws.device_libusb1.USBDevice.read_data failed')
Its not too elegant, I could put some loop instead but it was just for a test purpose and I left it like that
If not that it behaves exactly the same for all 3 libraries it could be some library bug where it ignores this size parameter.
I also checked what would happen when I execute  bulkRead 5th time but then it fails with timeout error.

Regards
Marcin

Marcin

unread,
Jun 3, 2023, 7:40:49 AM6/3/23
to pywws
You were right, it must be something with how USB is handled in my new router.
It worked without issues for almost two weeks but today it failed with:
:pywws.livelog:LIBUSB_ERROR_NO_DEVICE [-4]

dmesg shows:
[  201.229020] usb 1-1.1: reset low-speed USB device number 3 using xhci-mtk
[1122825.523545] usb 1-1.1: USB disconnect, device number 3
[1122825.923021] usb 1-1.1: new low-speed USB device number 5 using xhci-mtk
[1127791.502557] usb 1-1.1: reset low-speed USB device number 5 using xhci-mtk

So seems router lost usb device and connected it again with different ID, hadn't seen such issue earlier on previous router
I restarted livelog and its working again without need for router reboot

Cheers
Marcin
Reply all
Reply to author
Forward
0 new messages