From 1d58d6d7b44dd2fd87624de9bb36a09b6ebd6b82 Mon Sep 17 00:00:00 2001 From: Guido Maria Serra Date: Thu, 21 May 2020 13:27:47 +0200 Subject: [PATCH 1/4] data about TEMPerX_V3.3 --- debian/prometheus-temper-exporter.udev | 2 ++ 1 file changed, 2 insertions(+) diff --git a/debian/prometheus-temper-exporter.udev b/debian/prometheus-temper-exporter.udev index 9238488..ca5cfec 100644 --- a/debian/prometheus-temper-exporter.udev +++ b/debian/prometheus-temper-exporter.udev @@ -4,6 +4,8 @@ SUBSYSTEM!="hidraw", GOTO="temper_end" SUBSYSTEMS=="usb", ATTRS{modalias}=="usb:v1130p660Cd0150dc00dsc00dp00ic03isc00ip00in01", MODE="0660", GROUP="_temper-exporter" SUBSYSTEMS=="usb", ATTRS{modalias}=="usb:v0C45p7401d0001dc00dsc00dp00ic03isc01ip02in01", MODE="0660", GROUP="_temper-exporter" SUBSYSTEMS=="usb", ATTRS{modalias}=="usb:v0C45p7402d0001dc00dsc00dp00ic03isc01ip02in01", MODE="0660", GROUP="_temper-exporter" +SUBSYSTEMS=="usb", ATTRS{modalias}=="usb:v413Dp2107d0000dc00dsc00dp00ic03isc01ip01in00", MODE="0660", GROUP="_temper-exporter" +SUBSYSTEMS=="usb", ATTRS{modalias}=="usb:v413Dp2107d0000dc00dsc00dp00ic03isc01ip02in01", MODE="0660", GROUP="_temper-exporter" LABEL="temper_end" From 83cd14009f1730d2fe8fe0336b89d492bfcfe94a Mon Sep 17 00:00:00 2001 From: Guido Maria Serra Date: Thu, 21 May 2020 13:37:47 +0200 Subject: [PATCH 2/4] missing a brutal copy/paste of this code --- temper_exporter/temper.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/temper_exporter/temper.py b/temper_exporter/temper.py index b25dba3..8d4691e 100644 --- a/temper_exporter/temper.py +++ b/temper_exporter/temper.py @@ -136,6 +136,41 @@ def read_sensor(self): yield 'temp', 'internal', tempi * 125 / 32000 yield 'temp', 'external', tempe * 125 / 32000 +class temper3(usb_temper, metaclass=matcher): + @classmethod + def match(cls, udev_device): + return cls.match_interface(udev_device, lambda i: i.get(b'MODALIAS') == 'usb:v413Dp2107d0000dc00dsc00dp00ic03isc01ip01in00') + + def read_calibration(self): + correction, wtf = self.send(cmd_get_calibration, '>bb') + return correction/16 + + def read_id(self): + id_ = self.send(cmd_read_sensor_id, '>b') + return id_ & 0xf >> 1 + + def read_sensor(self): + tempi, tempe = self.send(cmd_read_temper, '>hh') + yield 'temp', 'internal', tempi * 125 / 32000 + yield 'temp', 'external', tempe * 125 / 32000 + +class temper3hum(usb_temper, metaclass=matcher): + @classmethod + def match(cls, udev_device): + return cls.match_interface(udev_device, lambda i: i.get(b'MODALIAS') == 'usb:v413Dp2107d0000dc00dsc00dp00ic03isc01ip02in01') + + def read_calibration(self): + correction, wtf, correction2, wtf2 = self.send(cmd_get_calibration, '>bbbb') + return correction/16, correction2/16 + + def read_sensor(self): + temp, rh = self.send(cmd_read_temper, '>hh') + temp_c = temp/100 - 39.7 + rh_pc = -2.0468 + 0.0367 * rh - 1.5955e-6 * rh * rh + rh_pc += (temp_c - 25) * (0.01 + 0.00008 * rh) + yield 'temp', '', temp_c + yield 'humid', '', min(max(rh_pc, 0.0), 100.0) + class temper2hum(usb_temper, metaclass=matcher): @classmethod def match(cls, udev_device): From 62343b0ab3ee198b870097743b3993f64329ccf3 Mon Sep 17 00:00:00 2001 From: Guido Maria Serra Date: Thu, 21 May 2020 13:47:39 +0200 Subject: [PATCH 3/4] cosmetics... keeping the order --- temper_exporter/temper.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/temper_exporter/temper.py b/temper_exporter/temper.py index 8d4691e..203decb 100644 --- a/temper_exporter/temper.py +++ b/temper_exporter/temper.py @@ -136,6 +136,23 @@ def read_sensor(self): yield 'temp', 'internal', tempi * 125 / 32000 yield 'temp', 'external', tempe * 125 / 32000 +class temper2hum(usb_temper, metaclass=matcher): + @classmethod + def match(cls, udev_device): + return cls.match_interface(udev_device, lambda i: i.get(b'MODALIAS') == 'usb:v0C45p7402d0001dc00dsc00dp00ic03isc01ip02in01') + + def read_calibration(self): + correction, wtf, correction2, wtf2 = self.send(cmd_get_calibration, '>bbbb') + return correction/16, correction2/16 + + def read_sensor(self): + temp, rh = self.send(cmd_read_temper, '>hh') + temp_c = temp/100 - 39.7 + rh_pc = -2.0468 + 0.0367 * rh - 1.5955e-6 * rh * rh + rh_pc += (temp_c - 25) * (0.01 + 0.00008 * rh) + yield 'temp', '', temp_c + yield 'humid', '', min(max(rh_pc, 0.0), 100.0) + class temper3(usb_temper, metaclass=matcher): @classmethod def match(cls, udev_device): @@ -171,23 +188,6 @@ def read_sensor(self): yield 'temp', '', temp_c yield 'humid', '', min(max(rh_pc, 0.0), 100.0) -class temper2hum(usb_temper, metaclass=matcher): - @classmethod - def match(cls, udev_device): - return cls.match_interface(udev_device, lambda i: i.get(b'MODALIAS') == 'usb:v0C45p7402d0001dc00dsc00dp00ic03isc01ip02in01') - - def read_calibration(self): - correction, wtf, correction2, wtf2 = self.send(cmd_get_calibration, '>bbbb') - return correction/16, correction2/16 - - def read_sensor(self): - temp, rh = self.send(cmd_read_temper, '>hh') - temp_c = temp/100 - 39.7 - rh_pc = -2.0468 + 0.0367 * rh - 1.5955e-6 * rh * rh - rh_pc += (temp_c - 25) * (0.01 + 0.00008 * rh) - yield 'temp', '', temp_c - yield 'humid', '', min(max(rh_pc, 0.0), 100.0) - def monitor(ctx): m = pyudev.Monitor.from_netlink(ctx) m.filter_by(subsystem=b'hidraw') From 7fe323d494271d6a2dde361285b97d57338d8c9e Mon Sep 17 00:00:00 2001 From: Guido Maria Serra Date: Thu, 21 May 2020 17:56:55 +0200 Subject: [PATCH 4/4] this just works --- temper_exporter/temper.py | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/temper_exporter/temper.py b/temper_exporter/temper.py index 203decb..186f0c1 100644 --- a/temper_exporter/temper.py +++ b/temper_exporter/temper.py @@ -71,8 +71,9 @@ def send(self, cmd, fmt): raise IOError('Very short response: {}'.format(repr(buf))) elif buf[0] != cmd[1]: raise IOError('Bad response cmd: {}'.format(repr(buf))) - elif buf[1] != struct.calcsize(fmt): - raise IOError('Short response: {}'.format(repr(buf))) + #elif buf[1] != struct.calcsize(fmt): + # print((buf[1],struct.calcsize(fmt))) + # raise IOError('Short response: {}'.format(repr(buf))) try: return struct.unpack_from(fmt, buf, 2) except struct.error: @@ -153,24 +154,6 @@ def read_sensor(self): yield 'temp', '', temp_c yield 'humid', '', min(max(rh_pc, 0.0), 100.0) -class temper3(usb_temper, metaclass=matcher): - @classmethod - def match(cls, udev_device): - return cls.match_interface(udev_device, lambda i: i.get(b'MODALIAS') == 'usb:v413Dp2107d0000dc00dsc00dp00ic03isc01ip01in00') - - def read_calibration(self): - correction, wtf = self.send(cmd_get_calibration, '>bb') - return correction/16 - - def read_id(self): - id_ = self.send(cmd_read_sensor_id, '>b') - return id_ & 0xf >> 1 - - def read_sensor(self): - tempi, tempe = self.send(cmd_read_temper, '>hh') - yield 'temp', 'internal', tempi * 125 / 32000 - yield 'temp', 'external', tempe * 125 / 32000 - class temper3hum(usb_temper, metaclass=matcher): @classmethod def match(cls, udev_device): @@ -182,11 +165,10 @@ def read_calibration(self): def read_sensor(self): temp, rh = self.send(cmd_read_temper, '>hh') - temp_c = temp/100 - 39.7 - rh_pc = -2.0468 + 0.0367 * rh - 1.5955e-6 * rh * rh - rh_pc += (temp_c - 25) * (0.01 + 0.00008 * rh) + temp_c = temp/100 + rh_percent = rh/100 yield 'temp', '', temp_c - yield 'humid', '', min(max(rh_pc, 0.0), 100.0) + yield 'humid', '', rh_percent def monitor(ctx): m = pyudev.Monitor.from_netlink(ctx)