Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ In the following table "I" means the sensor is internal to the USB stick and
Product | Id | Firmware | Temp | Hum | Notes
-----------|-----------|-----------------|------|-----|---------------
TEMPer | 0c45:7401 | TEMPerF1.4 | I | | Metal
TEMPer | 413d:2107 | TEMPerGold_V3.1 | I | | Metal
TEMPerHUM | 413d:2107 | TEMPerX_V3.1 | I | I | White plastic
TEMPer2 | 413d:2107 | TEMPerX_V3.3 | I,E | | White plastic
TEMPer1F | 413d:2107 | TEMPerX_V3.3 | E | | White plastic
Expand Down
14 changes: 11 additions & 3 deletions temper.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import select
import struct
import sys
import time

# Non-standard modules
try:
Expand All @@ -38,6 +37,7 @@
print('Cannot import "serial". Please sudo apt-get install python3-serial')
sys.exit(1)


class USBList(object):
'''Get a list of all of the USB devices on a system, along with their
associated hidraw or serial (tty) devices.
Expand Down Expand Up @@ -182,6 +182,11 @@ def _read_hidraw(self, device):
self._parse_bytes('internal temperature', 2, 256.0, bytes, info)
return info

if info['firmware'][:15] == 'TEMPerGold_V3.1':
info['firmware'] = info['firmware'][:15]
self._parse_bytes('internal temperature', 2, 100.0, bytes, info)
return info

if info['firmware'][:12] in [ 'TEMPerX_V3.1', 'TEMPerX_V3.3' ]:
info['firmware'] = info['firmware'][:12]
self._parse_bytes('internal temperature', 2, 100.0, bytes, info)
Expand All @@ -190,8 +195,10 @@ def _read_hidraw(self, device):
self._parse_bytes('external humidity', 12, 100.0, bytes, info)
return info

return { 'error' : 'Unknown firmware %s: %s' % (info['firmware'],
binascii.hexlify(bytes)) }
info['error'] = 'Unknown firmware %s: %s' % (info['firmware'],
binascii.hexlify(bytes))
return info


def _read_serial(self, device):
'''Using the Linux serial device, send the special commands and receive the
Expand Down Expand Up @@ -404,6 +411,7 @@ def main(self):
self.print(results, args.json)
return 0


if __name__ == "__main__":
temper = Temper()
sys.exit(temper.main())