urwen / temper

Simple python for accessing TEMPer USB thermometers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rpi 3B+ with 0c45:7401 TEMPerF1.4

nigels-com opened this issue · comments

Made both of these changes and updated the timeout from 0.2 to 0.5 and still get failures every other read when running
while true; do sudo ./temper2.py; sleep 5; done
on an RPi 3 B+

Just investigating, the regularity of it made me call hardware into question, checking dmesg it shows brownout on each successful read, subsequently returning rubbish. Will confirm with new PSU.

__ Update:
PSU swapped for a high current one, no improvement - power drop out doesn't happen but still get errors.

Output modified as I don't need all the bumf, but....
--@--:/home/pi# ./temper2.py
21.5 2020-01-21 21:01:39
--@--:/home/pi# ./temper2.py
21.5 2020-01-21 21:01:41
--@--:/home/pi# ./temper2.py
Traceback (most recent call last):
File "./temper2.py", line 434, in
sys.exit(temper.main())
File "./temper2.py", line 427, in main
results = self.read(args.verbose)
File "./temper2.py", line 345, in read
results.append({ **info, **usbread.read() })
File "./temper2.py", line 272, in read
return self._read_hidraw(self.device)
File "./temper2.py", line 180, in _read_hidraw
firmware = self._read_hidraw_firmware(fd, self.verbose)
File "./temper2.py", line 159, in _read_hidraw_firmware
raise RuntimeError('Cannot read device firmware identifier')
RuntimeError: Cannot read device firmware identifier

Originally posted by @bucklevision in #16 (comment)

Further information via that discussion:

It seems to happen with successive calls within 2ish seconds. Give it 5 and most of the time it's OK.

lsusb:
Bus 001 Device 005: ID 0c45:7401 Microdia TEMPer Temperature Sensor
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. SMC9514 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

output of /sys/kernel/debug/usb/devices
T: Bus=01 Lev=02 Prnt=02 Port=02 Cnt=02 Dev#= 5 Spd=1.5 MxCh= 0
D: Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1
P: Vendor=0c45 ProdID=7401 Rev= 0.01
S: Manufacturer=RDing
S: Product=TEMPerV1.4
C:* #Ifs= 2 Cfg#= 1 Atr=a0 MxPwr=100mA
I:* If#= 0 Alt= 0 #EPs= 1 Cls=03(HID ) Sub=01 Prot=01 Driver=usbhid
E: Ad=81(I) Atr=03(Int.) MxPS= 8 Ivl=10ms
I:* If#= 1 Alt= 0 #EPs= 1 Cls=03(HID ) Sub=01 Prot=02 Driver=usbhid
E: Ad=82(I) Atr=03(Int.) MxPS= 8 Ivl=10ms

It's one of these:
https://pcsensor.com/usb-thermometers/gold-temper.html

However it was purchased from Amazon.

Indeed, I can reproduce this setup and issue here too:

$ lsusb
Bus 001 Device 103: ID 0c45:7401 Microdia TEMPer Temperature Sensor
Bus 001 Device 004: ID 0bda:8179 Realtek Semiconductor Corp. RTL8188EUS 802.11n Wireless Network Adapter
Bus 001 Device 005: ID 0424:7800 Standard Microsystems Corp. 
Bus 001 Device 003: ID 0424:2514 Standard Microsystems Corp. USB 2.0 Hub
Bus 001 Device 002: ID 0424:2514 Standard Microsystems Corp. USB 2.0 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
T:  Bus=01 Lev=02 Prnt=02 Port=02 Cnt=02 Dev#=103 Spd=1.5  MxCh= 0
D:  Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 8 #Cfgs=  1
P:  Vendor=0c45 ProdID=7401 Rev= 0.01
S:  Manufacturer=RDing
S:  Product=TEMPerV1.4
C:* #Ifs= 2 Cfg#= 1 Atr=a0 MxPwr=100mA
I:* If#= 0 Alt= 0 #EPs= 1 Cls=03(HID  ) Sub=01 Prot=01 Driver=usbhid
E:  Ad=81(I) Atr=03(Int.) MxPS=   8 Ivl=10ms
I:* If#= 1 Alt= 0 #EPs= 1 Cls=03(HID  ) Sub=01 Prot=02 Driver=usbhid
E:  Ad=82(I) Atr=03(Int.) MxPS=   8 Ivl=10ms

Works:

$ while true; do sudo ./temper.py; sleep 10; done
Bus 001 Dev 103 0c45:7401 TEMPerF1.4 33.50C 92.30F - - - -
Bus 001 Dev 103 0c45:7401 TEMPerF1.4 33.50C 92.30F - - - -
Bus 001 Dev 103 0c45:7401 TEMPerF1.4 33.50C 92.30F - - - -
Bus 001 Dev 103 0c45:7401 TEMPerF1.4 33.50C 92.30F - - - -
Bus 001 Dev 103 0c45:7401 TEMPerF1.4 33.50C 92.30F - - - -
Bus 001 Dev 103 0c45:7401 TEMPerF1.4 33.50C 92.30F - - - -
Bus 001 Dev 103 0c45:7401 TEMPerF1.4 33.50C 92.30F - - - -
Bus 001 Dev 103 0c45:7401 TEMPerF1.4 33.50C 92.30F - - - -

Does not:

$ while true; do sudo ./temper.py; sleep 1; done
Traceback (most recent call last):
  File "./temper.py", line 432, in <module>
    sys.exit(temper.main())
  File "./temper.py", line 425, in main
    results = self.read(args.verbose)
  File "./temper.py", line 342, in read
    results.append({ **info, **usbread.read() })
  File "./temper.py", line 269, in read
    return self._read_hidraw(self.device)
  File "./temper.py", line 177, in _read_hidraw
    firmware = self._read_hidraw_firmware(fd, self.verbose)
  File "./temper.py", line 157, in _read_hidraw_firmware
    raise RuntimeError('Cannot read device firmware identifier')
RuntimeError: Cannot read device firmware identifier
Bus 001 Dev 103 0c45:7401 TEMPerF1.4 33.81C 92.86F - - - -
Traceback (most recent call last):
  File "./temper.py", line 432, in <module>
    sys.exit(temper.main())
  File "./temper.py", line 425, in main
    results = self.read(args.verbose)
  File "./temper.py", line 342, in read
    results.append({ **info, **usbread.read() })
  File "./temper.py", line 269, in read
    return self._read_hidraw(self.device)
  File "./temper.py", line 177, in _read_hidraw
    firmware = self._read_hidraw_firmware(fd, self.verbose)
  File "./temper.py", line 157, in _read_hidraw_firmware
    raise RuntimeError('Cannot read device firmware identifier')
RuntimeError: Cannot read device firmware identifier

Changing the timeout from 0.2 to 0.6 seems to work for this setup.
It does seem like an excessively long time to use by default, though.
https://github.com/nigels-com/temper/tree/timeout-rpi3b

I also hava a Raspberry Pi Zero W, which exhibits a similar problem for the same TEMPerF1.4:

Feb 19 22:13:19 raspberrypi td-agent-bit[1079]: Traceback (most recent call last):
Feb 19 22:13:19 raspberrypi td-agent-bit[1079]:   File "/usr/local/bin/temper.py", line 432, in <module>
Feb 19 22:13:19 raspberrypi td-agent-bit[1079]:     sys.exit(temper.main())
Feb 19 22:13:19 raspberrypi td-agent-bit[1079]:   File "/usr/local/bin/temper.py", line 425, in main
Feb 19 22:13:19 raspberrypi td-agent-bit[1079]:     results = self.read(args.verbose)
Feb 19 22:13:19 raspberrypi td-agent-bit[1079]:   File "/usr/local/bin/temper.py", line 342, in read
Feb 19 22:13:19 raspberrypi td-agent-bit[1079]:     results.append({ **info, **usbread.read() })
Feb 19 22:13:19 raspberrypi td-agent-bit[1079]:   File "/usr/local/bin/temper.py", line 269, in read
Feb 19 22:13:19 raspberrypi td-agent-bit[1079]:     return self._read_hidraw(self.device)
Feb 19 22:13:19 raspberrypi td-agent-bit[1079]:   File "/usr/local/bin/temper.py", line 177, in _read_hidraw
Feb 19 22:13:19 raspberrypi td-agent-bit[1079]:     firmware = self._read_hidraw_firmware(fd, self.verbose)
Feb 19 22:13:19 raspberrypi td-agent-bit[1079]:   File "/usr/local/bin/temper.py", line 157, in _read_hidraw_firmware
Feb 19 22:13:19 raspberrypi td-agent-bit[1079]:     raise RuntimeError('Cannot read device firmware identifier')
Feb 19 22:13:19 raspberrypi td-agent-bit[1079]: RuntimeError: Cannot read device firmware identifier
...
Feb 19 22:15:03 raspberrypi td-agent-bit[1079]: [0] temper: [1582114500.107316296, {"internal temperature"=>25.625000}]
...
$ make logs | grep temper:
Feb 19 22:17:16 raspberrypi td-agent-bit[1422]: [0] temper: [1582114632.933642098, {"internal temperature"=>26.562500}]
Feb 19 22:17:21 raspberrypi td-agent-bit[1422]: [0] temper: [1582114637.978755096, {"internal temperature"=>26.750000}]
Feb 19 22:17:26 raspberrypi td-agent-bit[1422]: [0] temper: [1582114642.938570485, {"internal temperature"=>26.625000}]
Feb 19 22:17:31 raspberrypi td-agent-bit[1422]: [0] temper: [1582114647.963719339, {"internal temperature"=>26.500000}]
Feb 19 22:17:36 raspberrypi td-agent-bit[1422]: [0] temper: [1582114652.947055894, {"internal temperature"=>26.625000}]
Feb 19 22:17:41 raspberrypi td-agent-bit[1422]: [0] temper: [1582114657.954845623, {"internal temperature"=>26.500000}]