J’ai donc pris une clef USB afin de mesurer la température du Rack de Raspberry :
- TOOGOO(R) Or TEMPer PC portable capteur USB Thermometre Temperature Collecteur de Donnees Enregistreur : 6,41 Euros.
( voir l’article : https://www.cyber-neurones.org/2018/10/si-tu-nas-pas-de-salle-serveur-a-50-ans-on-peut-dire-que-tu-as-rate-ta-vie/ ) .
Quand on branche la clef USB sur le Raspberry on peut lire via dmesg :
[167573.702646] usb 1-1.4: new full-speed USB device number 6 using dwc_otg [167573.835187] usb 1-1.4: New USB device found, idVendor=413d, idProduct=2107 [167573.835203] usb 1-1.4: New USB device strings: Mfr=0, Product=0, SerialNumber=0 [167573.839803] input: HID 413d:2107 as /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/0003:413D:2107.0002/input/input3
C’est un premier bon signe 🙂 Par contre la suite c’est pas top :
[167573.903681] hid-generic 0003:413D:2107.0002: input,hidraw1: USB HID v1.11 Keyboard [HID 413d:2107] on usb-3f980000.usb-1.4/input0 [167573.907408] hid-generic 0003:413D:2107.0003: hiddev96,hidraw2: USB HID v1.10 Device [HID 413d:2107] on usb-3f980000.usb-1.4/input1
J’ai donc pris le projet suivant ( Plan A ) : https://github.com/bitplane/temper.git :
$ cd /usr/local/src/ $ sudo git clone https://github.com/bitplane/temper.git Clonage dans 'temper'... ... $ cd temper/ $ sudo make temper gcc -Wall temper.c pcsensor.c -o temper -lusb In file included from temper.c:8:0: pcsensor.h:25:17: fatal error: usb.h: Aucun fichier ou dossier de ce type #include ^ compilation terminated. In file included from pcsensor.c:25:0: pcsensor.h:25:17: fatal error: usb.h: Aucun fichier ou dossier de ce type #include ^ compilation terminated. Makefile:8 : la recette pour la cible « temper » a échouée make: *** [temper] Erreur 1
Si c’est ainsi c’est qu’il faut installer les libs pour USB :
$ sudo apt install libusb-1.0-0-dev cmake
Je tente à nouveau une compilation :
$ sudo make temper gcc -Wall temper.c pcsensor.c -o temper -lusb In file included from temper.c:8:0: pcsensor.h:25:17: fatal error: usb.h: Aucun fichier ou dossier de ce type #include ^ compilation terminated. In file included from pcsensor.c:25:0: pcsensor.h:25:17: fatal error: usb.h: Aucun fichier ou dossier de ce type #include ^ compilation terminated. Makefile:8 : la recette pour la cible « temper » a échouée make: *** [temper] Erreur 1
Pas mieux … pas de panique, quand c’est ainsi on installe apt-file
$ sudo apt install apt-file
...
$ sudo apt-file update
...
$ apt-file search /usr/include/usb.h
libusb-dev: /usr/include/usb.h
Ok, il fallait donc installer libusb-dev et non libusb-1.0-0-dev . Effectivement la version générique est toujours préférable.
$ sudo apt-get install libusb-dev $ sudo make gcc -Wall temper.c pcsensor.c -o temper -lusb pcsensor.c:50:18: warning: ‘reqBulkLen’ defined but not used [-Wunused-const-variable=] const static int reqBulkLen=8;
Un petit test :
$ sudo ./temper
Il n’affiche rien. Je vais essayer le plan B : https://github.com/edorfaus/TEMPered .
$ sudo git clone https://github.com/edorfaus/TEMPered
$ cd TEMPered/
$ sudo cmake .
...
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
HIDAPI_HEADER_DIR
...
Nouvelle erreur, on ne perd pas courage. On fait l’installation des headers :
$ sudo apt-get install libhidapi-dev -y
Et on refait une compilation :
$ sudo cmake . CMake Warning (dev) at CMakeLists.txt:57: Syntax Warning in cmake code at column 54 Argument not separated from preceding token by whitespace. This warning is for project developers. Use -Wno-dev to suppress it. -- Configuring done -- Generating done -- Build files have been written to: /usr/local/src/TEMPered $ sudo make Scanning dependencies of target tempered-shared [ 4%] Building C object libtempered/CMakeFiles/tempered-shared.dir/core.c.o [ 9%] Building C object libtempered/CMakeFiles/tempered-shared.dir/temper_type.c.o [ 13%] Building C object libtempered/CMakeFiles/tempered-shared.dir/type_hid/common.c.o [ 18%] Building C object libtempered/CMakeFiles/tempered-shared.dir/type_hid/fm75.c.o [ 22%] Building C object libtempered/CMakeFiles/tempered-shared.dir/type_hid/ntc.c.o /usr/local/src/TEMPered/libtempered/type_hid/ntc.c: In function ‘tempered_type_hid_read_sensor_group_ntc’: /usr/local/src/TEMPered/libtempered/type_hid/ntc.c:8:66: warning: unused parameter ‘group’ [-Wunused-parameter] tempered_device* device, struct tempered_type_hid_sensor_group* group, ^~~~~ /usr/local/src/TEMPered/libtempered/type_hid/ntc.c:9:41: warning: unused parameter ‘group_data’ [-Wunused-parameter] struct tempered_type_hid_query_result* group_data ^~~~~~~~~~ /usr/local/src/TEMPered/libtempered/type_hid/ntc.c: In function ‘tempered_type_hid_get_temperature_ntc’: /usr/local/src/TEMPered/libtempered/type_hid/ntc.c:20:60: warning: unused parameter ‘tempC’ [-Wunused-parameter] struct tempered_type_hid_query_result *group_data, float *tempC ^~~~~ [ 27%] Building C object libtempered/CMakeFiles/tempered-shared.dir/type_hid/sht1x.c.o [ 31%] Building C object libtempered/CMakeFiles/tempered-shared.dir/type_hid/si7005.c.o [ 36%] Linking C shared library libtempered.so [ 36%] Built target tempered-shared Scanning dependencies of target tempered-util-shared [ 40%] Building C object libtempered-util/CMakeFiles/tempered-util-shared.dir/calibration.c.o [ 45%] Building C object libtempered-util/CMakeFiles/tempered-util-shared.dir/dew-point.c.o [ 50%] Building C object libtempered-util/CMakeFiles/tempered-util-shared.dir/temp-scale.c.o [ 54%] Linking C shared library libtempered-util.so [ 54%] Built target tempered-util-shared Scanning dependencies of target tempered-exe [ 59%] Building C object utils/CMakeFiles/tempered-exe.dir/tempered.c.o [ 63%] Linking C executable tempered [ 63%] Built target tempered-exe Scanning dependencies of target hid-query [ 68%] Building C object utils/CMakeFiles/hid-query.dir/hid-query.c.o [ 72%] Linking C executable hid-query [ 72%] Built target hid-query Scanning dependencies of target enumerate [ 77%] Building C object examples/CMakeFiles/enumerate.dir/enumerate.c.o [ 81%] Linking C executable enumerate [ 81%] Built target enumerate Scanning dependencies of target read-all [ 86%] Building C object examples/CMakeFiles/read-all.dir/read-all.c.o [ 90%] Linking C executable read-all [ 90%] Built target read-all Scanning dependencies of target read-repeat [ 95%] Building C object examples/CMakeFiles/read-repeat.dir/read-repeat.c.o [100%] Linking C executable read-repeat [100%] Built target read-repeat $ sudo make install [ 36%] Built target tempered-shared [ 54%] Built target tempered-util-shared [ 63%] Built target tempered-exe [ 72%] Built target hid-query [ 81%] Built target enumerate [ 90%] Built target read-all [100%] Built target read-repeat Install the project... -- Install configuration: "" -- Installing: /usr/local/include/tempered.h -- Installing: /usr/local/lib/libtempered.so.0 -- Installing: /usr/local/lib/libtempered.so -- Installing: /usr/local/include/tempered-util.h -- Installing: /usr/local/lib/libtempered-util.so.0 -- Installing: /usr/local/lib/libtempered-util.so -- Installing: /usr/local/bin/hid-query -- Installing: /usr/local/bin/tempered -- Set runtime path of "/usr/local/bin/tempered" to ""
Synchro des ld :
$ sudo ldconfig -v
Petit test :
$ /usr/local/bin/tempered -s Fahrenheit Failed to enumerate devices: (null)
Je me demande s’il n’y a pas un appel à lsusb :
$ sudo apt-file search bin/lsusb ... usbutils: /usr/bin/lsusb $ sudo apt-get install usbutils
Petit test de la commande :
$ lsusb
Bus 001 Device 005: ID 0eef:0005 D-WAV Scientific Co., Ltd
Bus 001 Device 006: ID 413d:2107
Bus 001 Device 004: ID 2537:1068
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
$ /usr/local/bin/tempered -s Fahrenheit
Failed to enumerate devices: (null)
J’essaye le « reboot », pas mieux :
$ /usr/local/bin/tempered Failed to enumerate devices: (null) $ sudo /usr/local/bin/tempered Failed to enumerate devices: (null) $ lsusb Bus 001 Device 006: ID 0eef:0005 D-WAV Scientific Co., Ltd Bus 001 Device 005: ID 413d:2107 Bus 001 Device 004: ID 2537:1068 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 $ cd /usr/local/src/TEMPered/utils $ ./hid-query -e /dev/hidraw0 : 413d:2107 interface 0 : (null) (null) /dev/hidraw1 : 413d:2107 interface 1 : (null) (null) /dev/hidraw2 : 0eef:0005 interface 0 : WaveShare WS170120 $ sudo ./hid-query /dev/hidraw1 0x01 0x80 0x33 0x01 0x00 0x00 0x00 0x00 Device /dev/hidraw1 : 413d:2107 interface 1 : (null) (null) Writing data (9 bytes): 00 01 80 33 01 00 00 00 00 Response from device (8 bytes): 80 80 10 36 4e 20 00 00 $ sudo ./hid-query /dev/hidraw1 0x01 0x86 0xff 0x01 0x00 0x00 0x00 0x00 Device /dev/hidraw1 : 413d:2107 interface 1 : (null) (null) Writing data (9 bytes): 00 01 86 ff 01 00 00 00 00 Response from device (8 bytes): 6c 64 5f 56 33 2e 31 20 $ sudo ./hid-query /dev/hidraw0 0x01 0x80 0x33 0x01 0x00 0x00 0x00 0x00 Device /dev/hidraw0 : 413d:2107 interface 0 : (null) (null) Writing data (9 bytes): 00 01 80 33 01 00 00 00 00 No data was read from the device (timeout).
On passe au plan C : http://dev-random.net/wp-content/uploads/2016/01/temperv14.zip
$ sudo apt-get install dos2unix $ wget http://dev-random.net/wp-content/uploads/2016/01/temperv14.zip $ unzip temperv14.zip $ cd temperv14 $ dos2unix temperv14.c dos2unix: conversion du fichier temperv14.c au format Unix…
Modification du code :
//#define VENDOR_ID 0x0c45 //#define PRODUCT_ID 0x7401 #define VENDOR_ID 0x413d #define PRODUCT_ID 0x2107
Le code sans modification :
$ sudo ./temperv14 Couldn't find the USB device, Exiting
Le code avec modification :
$ sudo ./temperv14 USB interrupt read: Resource temporarily unavailable Fatal error> USB read failed
On passe au plan D : git://github.com/padelt/temper-python.git
$ sudo apt-get install python-usb python-setuptools $ git clone git://github.com/padelt/temper-python.git $ cd temper-python
Misère de python :
$ sudo python3.5 setup.py install
Traceback (most recent call last):
File "setup.py", line 1, in
from setuptools import setup
ImportError: No module named 'setuptools'
$ sudo apt-get install python3-setuptools
$ sudo python3.5 setup.py install
Finished processing dependencies for temperusb==1.5.3
$ temper-poll
Found 0 devices
Si je regarde le programme en python : ( fichier temper.py )
VIDPIDS = [ (0x0c45, 0x7401), (0x0c45, 0x7402), ] REQ_INT_LEN = 8 ENDPOINT = 0x82 INTERFACE = 1 CONFIG_NO = 1 TIMEOUT = 5000
J’ajoutes donc le miens, et je refais l’installation :
...
VIDPIDS = [
(0x0c45, 0x7401),
(0x0c45, 0x7402),
(0x413d, 0x2107),
]
...
$ sudo python3.5 setup.py install
$ sudo temper-poll
Found 1 devices
WARNING:temperusb.temper:Encountered [Errno 110] Operation timed out, resetting and trying again.
ERROR:temperusb.temper:[Errno 110] Operation timed out
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/temperusb-1.5.3-py3.5.egg/temperusb/temper.py", line 244, in get_data
File "/usr/local/lib/python3.5/dist-packages/temperusb-1.5.3-py3.5.egg/temperusb/temper.py", line 403, in _interrupt_read
File "/usr/local/lib/python3.5/dist-packages/pyusb-1.0.2-py3.5.egg/usb/core.py", line 988, in read
File "/usr/local/lib/python3.5/dist-packages/pyusb-1.0.2-py3.5.egg/usb/backend/libusb1.py", line 851, in intr_read
File "/usr/local/lib/python3.5/dist-packages/pyusb-1.0.2-py3.5.egg/usb/backend/libusb1.py", line 936, in __read
File "/usr/local/lib/python3.5/dist-packages/pyusb-1.0.2-py3.5.egg/usb/backend/libusb1.py", line 595, in _check
usb.core.USBError: [Errno 110] Operation timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/bin/temper-poll", line 11, in
load_entry_point('temperusb==1.5.3', 'console_scripts', 'temper-poll')()
File "/usr/local/lib/python3.5/dist-packages/temperusb-1.5.3-py3.5.egg/temperusb/cli.py", line 55, in main
File "/usr/local/lib/python3.5/dist-packages/temperusb-1.5.3-py3.5.egg/temperusb/temper.py", line 323, in get_temperatures
File "/usr/local/lib/python3.5/dist-packages/temperusb-1.5.3-py3.5.egg/temperusb/temper.py", line 273, in get_data
File "/usr/local/lib/python3.5/dist-packages/temperusb-1.5.3-py3.5.egg/temperusb/temper.py", line 244, in get_data
File "/usr/local/lib/python3.5/dist-packages/temperusb-1.5.3-py3.5.egg/temperusb/temper.py", line 403, in _interrupt_read
File "/usr/local/lib/python3.5/dist-packages/pyusb-1.0.2-py3.5.egg/usb/core.py", line 988, in read
File "/usr/local/lib/python3.5/dist-packages/pyusb-1.0.2-py3.5.egg/usb/backend/libusb1.py", line 851, in intr_read
File "/usr/local/lib/python3.5/dist-packages/pyusb-1.0.2-py3.5.egg/usb/backend/libusb1.py", line 936, in __read
File "/usr/local/lib/python3.5/dist-packages/pyusb-1.0.2-py3.5.egg/usb/backend/libusb1.py", line 595, in _check
usb.core.USBError: [Errno 110] Operation timed out
On passe au plan E : https://github.com/edorfaus/TEMPered/issues/51 . J’ai l’impression que c’est le même problème que moi. En fait le plan E est au mauvais plan B.
Effectivement dans libtempered/temper_type.c , j’ai :
{ .name="TEMPerV1.2 or TEMPer2V1.3", .vendor_id=0x0c45, .product_id=0x7401, .interface_number=0 }, { .name="TEMPerV1.2 or TEMPer2V1.3", .vendor_id=0x0c45, .product_id=0x7401, .interface_number=1,
Je fais donc une première modification :
{ .name="TEMPerV1.2 or TEMPer2V1.3", .vendor_id=0x413d, .product_id=0x2107, .interface_number=0 }, { .name="TEMPerV1.2 or TEMPer2V1.3", .vendor_id=0x413d, .product_id=0x2107, .interface_number=1,
Et j’ajoutes la structure 0x04 qui est une copie de la 0x02 :
(struct temper_subtype*)&(struct temper_subtype_hid){ .base = { .id = 4, .name = "TEMPer2V1.3", .open = tempered_type_hid_subtype_open, .read_sensors = tempered_type_hid_read_sensors, .get_sensor_count = tempered_type_hid_get_sensor_count, .get_temperature = tempered_type_hid_get_temperature, }, .sensor_group_count = 1, .sensor_groups = (struct tempered_type_hid_sensor_group[]){ { .query = { .length = 9, .data = (unsigned char[]){ 0, 1, 0x80, 0x33, 1, 0, 0, 0, 0 } }, .read_sensors = tempered_type_hid_read_sensor_group, .sensor_count = 2, .sensors = (struct tempered_type_hid_sensor[]){ { .get_temperature = tempered_type_hid_get_temperature_fm75, .temperature_high_byte_offset = 2, .temperature_low_byte_offset = 3 }, { .get_temperature = tempered_type_hid_get_temperature_fm75, .temperature_high_byte_offset = 4, .temperature_low_byte_offset = 5 } } } } },
On refaire le build :
$ sudo make Scanning dependencies of target tempered-shared [ 4%] Building C object libtempered/CMakeFiles/tempered-shared.dir/temper_type.c.o [ 9%] Linking C shared library libtempered.so [ 36%] Built target tempered-shared [ 54%] Built target tempered-util-shared [ 59%] Linking C executable tempered [ 63%] Built target tempered-exe [ 72%] Built target hid-query [ 77%] Linking C executable enumerate [ 81%] Built target enumerate [ 86%] Linking C executable read-all [ 90%] Built target read-all [ 95%] Linking C executable read-repeat [100%] Built target read-repeat $ sudo make install [ 36%] Built target tempered-shared [ 54%] Built target tempered-util-shared [ 63%] Built target tempered-exe [ 72%] Built target hid-query [ 81%] Built target enumerate [ 90%] Built target read-all [100%] Built target read-repeat Install the project... -- Install configuration: "" -- Up-to-date: /usr/local/include/tempered.h -- Installing: /usr/local/lib/libtempered.so.0 -- Up-to-date: /usr/local/lib/libtempered.so -- Up-to-date: /usr/local/include/tempered-util.h -- Up-to-date: /usr/local/lib/libtempered-util.so.0 -- Up-to-date: /usr/local/lib/libtempered-util.so -- Up-to-date: /usr/local/bin/hid-query -- Installing: /usr/local/bin/tempered -- Set runtime path of "/usr/local/bin/tempered" to ""
Et le test :
$ sudo /usr/local/bin/tempered /dev/hidraw1 0: temperature 13.57 °C /dev/hidraw1 1: temperature 78.12 °C
Miracle, cela fonctionne !
Nouveau test :
$ sudo /usr/local/bin/tempered /dev/hidraw1 0: temperature 13.72 °C /dev/hidraw1 1: temperature 78.12 °C
Par contre cela affiche n’importe quoi … il faut donc modifier :
.sensors = (struct tempered_type_hid_sensor[]){ { .get_temperature = tempered_type_hid_get_temperature_fm75, .temperature_high_byte_offset = 2, .temperature_low_byte_offset = 3 }, { .get_temperature = tempered_type_hid_get_temperature_fm75, .temperature_high_byte_offset = 2, .temperature_low_byte_offset = 3 }
Mais il faut aussi modifier libtempered/type_hid/fm75.c :
A la place de :
// This temperature formula is taken from the FM75 datasheet. // This is the same as dividing by 256; basically moving the // decimal point into place. *tempC = temp * 125.0 / 32000.0;
Mettre :
*tempC = temp / 100.0;
Nouveau test :
$ sudo /usr/local/bin/tempered /dev/hidraw1 0: temperature 35.12 °C /dev/hidraw1 1: temperature 35.12 °C
Je vais maintenant vérifier … mais il me semble que 35 c’est bon.
Et un plan F pour bien Finir : https://github.com/mreymann/temperx
$ hid-query -e /dev/hidraw0 : 413d:2107 interface 0 : (null) (null) /dev/hidraw1 : 413d:2107 interface 1 : (null) (null) /dev/hidraw2 : 0eef:0005 interface 0 : WaveShare WS170120
Ensuite installation de go
$ sudo apt-get install go $ mkdir go $ export GOPATH="$HOME/go" $ go get github.com/mreymann/temperx $ go install github.com/mreymann/temperx $ sudo go/bin/temperx Temperature: 35.75, Humidity: 200 $ sudo cp go/bin/temperx /etc/munin/plugins/ $ sudo vi /etc/munin/plugin-conf.d/temperx [temperx] user root # optional calibration parameters: env.t_offset 0 env.t_factor 1 env.h_offset 0 env.h_factor 1 $ sudo systemctl restart munin-node.service
Aie … je me trompes à chaque fois …
$ sudo cp go/bin/temperx /usr/share/munin/plugins/ $ sudo rm /etc/munin/plugins/temperx $ sudo ln -s /usr/share/munin/plugins/temperx /etc/munin/plugins/temperx $ sudo systemctl restart munin-node.service $ sudo munin-node-configure | grep temperx temperx | yes |
C’était vraiment la misère …
J’ai modifié le code GO pour avoir :
$ sudo go/bin/temperx Temperature.value 40.87 Humidity.value 200
Modifier go/src/github.com/mreymann/temperx/temperx.go :
fmt.Printf("Temperature.value %v\nHumidity.value %v\n", tmp, hum)
Sinon j’avais l’erreur dans /var/log/munin/munin-update.log .
Aie toujours pas bon :
Missing required attribute 'label' for data source 'Temperature' in service temperx on localhost.localdomain/127.0.0.1:4949 Missing required attribute 'label' for data source 'Humidity' in service temperx on localhost.localdomain/127.0.0.1:4949 [INFO] creating rrd-file for temperx->Humidity: '/var/lib/munin/localdomain/localhost.localdomain-temperx-Humidity-g.rrd'
Il doit manquer un Temperature.label & Humidity.label .
Voir aussi l’article : http://www.cyber-neurones.org/2018/10/raspberry-munin-usb-temperature-via-lusb/ . Désolé c’est un peu le bazar …