SWAP sur Raspbian

13 x served & 2 x viewed

Lire le lien : https://raspberrypi.stackexchange.com/questions/84390/how-to-permanently-disable-swap-on-raspbian-stretch-lite (Merci Michel)

J’ai fait un petit script pour faire un free -h et un uname -r sur tous les serveurs :

$ ./ssh-distant-2.sh 
Cnx sur 127.0.0.1 
4.14.34-6-osmc total used free shared buff/cache available Mem: 746M 138M 231M 20M 376M 539M Swap: 0B 0B 0B
Cnx sur 192.168.0.70 
4.14.50+ total used free shared buff/cache available Mem: 433M 28M 51M 5,7M 353M 351M Swap: 99M 0B 99M
Cnx sur 192.168.0.71 
4.14.71-v7+ total used free shared buff/cache available Mem: 927M 183M 138M 46M 604M 633M Swap: 99M 768K 99M
Cnx sur 192.168.0.72 
4.14.50-v7+ total used free shared buff/cache available Mem: 927M 415M 157M 17M 353M 429M Swap: 99M 0B 99M
Cnx sur 192.168.0.73 
4.14.50-v7+ total used free shared buff/cache available Mem: 927M 153M 337M 17M 435M 691M Swap: 99M 0B 99M
Cnx sur 192.168.0.74 
4.14.70-v7+ total used free shared buff/cache available Mem: 927M 158M 127M 57M 641M 647M Swap: 99M 768K 99M

Si je regarde la valuer dans le fichier /etc/dphys-swapfile, via un script : cat /etc/dphys-swapfile | grep CONF_SWAPSIZE

$ ./ssh-distant-3.sh 
Cnx sur 127.0.0.1 
cat: /etc/dphys-swapfile: Aucun fichier ou dossier de ce type
Cnx sur 192.168.0.70 
CONF_SWAPSIZE=100
Cnx sur 192.168.0.71 
CONF_SWAPSIZE=100
Cnx sur 192.168.0.72 
CONF_SWAPSIZE=100
Cnx sur 192.168.0.73 
CONF_SWAPSIZE=100
Cnx sur 192.168.0.74 
CONF_SWAPSIZE=100

Le problème c’est l’écriture sur la carte microSD, je veux être sûr de ne pas user rapidement la carte.

A suivre.

PSSH/SSHPASS : Lancer des scripts en parallèle.

10 x served & 3 x viewed

Etape n°1 :

Installation, facile avec pip :

$ sudo pip install pssh
Collecting pssh
  Downloading https://files.pythonhosted.org/packages/60/9a/8035af3a7d3d1617ae2c7c174efa4f154e5bf9c24b36b623413b38be8e4a/pssh-2.3.1.tar.gz
Installing collected packages: pssh
  Running setup.py install for pssh ... done
Successfully installed pssh-2.3.1

Etape n°2 :

Utilisation simple, tous les serveurs ont le même login (par exemple pi2base) et le même mot de passe :

$ cat pssh-hosts
192.168.0.80  
192.168.0.70 
192.168.0.71  
192.168.0.72   
192.168.0.73 
192.168.0.74 
$ pssh -h pssh-hosts -l pi2base -A -i "hostnamectl"

On fait donc la commande hostnamectl via le login pi2base, sur tous les serveurs dans le fichier pssh-hosts.
Plus complexe, les utilisateurs sont différents mais les mots de passe sont identiques :
pi2base) et le même mot de passe :

$ cat pssh-hosts
user1@192.168.0.80  
user2@192.168.0.70 
user3@192.168.0.71  
user4@192.168.0.72   
user5@192.168.0.73 
user6@192.168.0.74 
$ pssh -h pssh-hosts  -A -i "hostnamectl"

Encore plus complexe, sans demander les mots de passe :

$ apt-get install sshpass pssh

Ensuite il suffit de faire un script :

$ cat ssh-distant.sh 
#!/bin/bash

serveur[1]=127.0.0.1
login[1]=xxxx
password[1]=zzzz
serveur[2]=192.168.0.70
login[2]=xxxx
password[2]=zzzz
serveur[3]=192.168.0.71
login[3]=xxxx
password[3]=zzzz
serveur[4]=192.168.0.72
login[4]=xxxx
password[4]=zzzz
serveur[5]=192.168.0.73
login[5]=xxxx
password[5]=zzzz
serveur[6]=192.168.0.74
login[6]=xxxx            
password[6]=zzzz

for index in 1 2 3 4 5 6
do
	printf " cnx sur ${login[index]} \n"
	output=$(sshpass -p ${password[index]} ssh -o StrictHostKeyChecking=no ${login[index]}@${serveur[index]} ' hostnamectl ' 2>&1)
	#echo "$?" 
	echo $output
done

history -c

La commande finale, permet de supprimer l’historique … sinon le mot de passe est en clair dans l’historique.
Par exemple :

$ ./ssh-distant.sh 
 cnx sur xxxxx 
Static hostname: osmc Icon name: computer Machine ID: 1671b5b617884fdf85a465a5ac731b8f Boot ID: a312213621b54c2f953202f480a070d7 Operating System: Open Source Media Center Kernel: Linux 4.14.34-6-osmc Architecture: arm
 cnx sur xxxxx 
Static hostname: raspberrypi Icon name: computer Machine ID: 0b646f6436cf4076bc65ccf9a7517e6c Boot ID: dc978e5c9f4d41a5b4b126b2dd7e923f Operating System: Raspbian GNU/Linux 9 (stretch) Kernel: Linux 4.14.50+ Architecture: arm
 cnx sur xxxxx 
Static hostname: RASP3 Icon name: computer Machine ID: 5c7798e1c4144782bfc8e591138cce5f Boot ID: 7cd79bf1fa26484d8ff98b2cba06726c Operating System: Raspbian GNU/Linux 9 (stretch) Kernel: Linux 4.14.71-v7+ Architecture: arm
 cnx sur xxxxx 
Static hostname: RASP4 Icon name: computer Machine ID: b48f53ca95ae44f8bfc503090332c390 Boot ID: c66f163ff98e4d62b0f855b07a86e0ec Operating System: Raspbian GNU/Linux 9 (stretch) Kernel: Linux 4.14.50-v7+ Architecture: arm
 cnx sur xxxxx 
Static hostname: RASP5 Icon name: computer Machine ID: 45ed4ac581ef4f3fb099a4c8791a4787 Boot ID: e46e4361b8e44dae9f47b812525983ba Operating System: Raspbian GNU/Linux 9 (stretch) Kernel: Linux 4.14.50-v7+ Architecture: arm
 cnx sur xxxxx 
Static hostname: RASP6 Icon name: computer Machine ID: 072b46046e3a4cdea183a0f7d018a2a3 Boot ID: 0143eb44792f457dbe288e4bbd67a973 Operating System: Raspbian GNU/Linux 9 (stretch) Kernel: Linux 4.14.70-v7+ Architecture: arm

Sinon il reste Ansible, mais c’est beaucoup plus lourd :

$ sudo pip install ansible

… mais aussi plus performant. Il suffit de copier le fichier des hosts (pssh-hosts dans mon exemple) dans /etc/ansible/hosts . Sachant qu’il faut faire une clef : ssh-keygen, et ensuite il faut copier la clef : ssh-copy-id -i ~/.ssh/id_rsa.pub root@ip-host .

Le problème de ansible, c’est que sur Raspbian par défaut on a une erreur d’installation :

$ sudo pip install ansible
...
arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-ttpzh8/python2.7-2.7.13=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -DUSE__THREAD -DHAVE_SYNC_SYNCHRONIZE -I/usr/include/ffi -I/usr/include/libffi -I/usr/include/python2.7 -c c/_cffi_backend.c -o build/temp.linux-armv7l-2.7/c/_cffi_backend.o
      c/_cffi_backend.c:15:17: fatal error: ffi.h: Aucun fichier ou dossier de ce type
       #include 
                       ^
      compilation terminated.
      error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1
  
      ----------------------------------------
  Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-JTBUnP/cffi/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-6maTdm/install-record.txt --single-version-externally-managed --prefix /tmp/pip-build-env-JcZXMj --compile" failed with error code 1 in /tmp/pip-install-JTBUnP/cffi/
  
  ----------------------------------------
Command "/usr/bin/python -m pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-JcZXMj --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- setuptools wheel "cffi>=1.4.1; python_implementation != 'PyPy'"" failed with error code 1 in None

A suivre.

Développement en C sous Linux : pthread et la fonction sleep().

13 x served & 2 x viewed

Un petit exemple vaut mieux que de grands discours, voici le source en C :

#include 
#include 
#include 
#include <sys/time.h>
#include <sys/types.h>
#include 
static long debut = 0;
void* longue_pause(void* a){
        pid_t t = getpid();
        printf("pid = %d\n",(int)t);
        printf("thread longue_pause %d debut : %ld\n",(int)pthread_self(),time(0)-debut);
        sleep(10);
        printf("thread longue_pause %d fin : %ld\n",(int)pthread_self(),time(0)-debut);
}
void* petites_pauses(void* a){
	int i = 0;
        pid_t t = getpid();
        printf("pid = %d\n",t);
        printf("thread petites_pauses %d debut : %ld \n",(int)pthread_self(), time(0)-debut);
        for(; i < 10 ;++i){
                printf("thread petites_pauses %d en cours : %ld \n",(int)pthread_self(), time(0)-debut);
                sleep(1);
        }
}
int main(){
        pthread_t longue;
        pthread_t petit1;
        pthread_t petit2;
        debut = time(0);
        pthread_create(&longue,NULL,longue_pause,NULL);
        pthread_create(&petit1,NULL,petites_pauses,NULL);
        pthread_create(&petit2,NULL,petites_pauses,NULL);
	sleep(8);
	printf("Debut join: %ld\n",time(0)-debut);
        pthread_join(longue,NULL);
        printf("fin long : %ld\n",time(0)-debut); 
        pthread_join(petit1,NULL);
	printf("fin petit1 : %ld\n",time(0)-debut);	
        pthread_join(petit2,NULL);
	printf("fin petit2 : %ld\n",time(0)-debut);
}

Pour la compilation :

$ gcc test_pthread_test.c -lpthread -o test2

On lance le test :

$ ./test2 
pid = 324
thread longue_pause 1078445824 debut : 0
pid = 324
thread petites_pauses 1070053120 debut : 0 
thread petites_pauses 1070053120 en cours : 0 
pid = 324
thread petites_pauses 1061660416 debut : 0 
thread petites_pauses 1061660416 en cours : 0 
thread petites_pauses 1070053120 en cours : 1 
thread petites_pauses 1061660416 en cours : 1 
thread petites_pauses 1070053120 en cours : 2 
thread petites_pauses 1061660416 en cours : 2 
thread petites_pauses 1070053120 en cours : 3 
thread petites_pauses 1061660416 en cours : 3 
thread petites_pauses 1070053120 en cours : 4 
thread petites_pauses 1061660416 en cours : 4 
thread petites_pauses 1061660416 en cours : 5 
thread petites_pauses 1070053120 en cours : 5 
thread petites_pauses 1061660416 en cours : 6 
thread petites_pauses 1070053120 en cours : 6 
thread petites_pauses 1070053120 en cours : 7 
thread petites_pauses 1061660416 en cours : 7 
Debut join: 8
thread petites_pauses 1070053120 en cours : 8 
thread petites_pauses 1061660416 en cours : 8 
thread petites_pauses 1070053120 en cours : 9 
thread petites_pauses 1061660416 en cours : 9 
thread longue_pause 1078445824 fin : 10
fin long : 10
fin petit1 : 10
fin petit2 : 10

Le petit exemple nous montre bien qu’aucun sleep() ne fait une attente sur les autres pthreads, même celui dans le main().

J’ai pu voir sur des forums :

Effectivement sur le POSIX il est marqué : http://pubs.opengroup.org/onlinepubs/9699919799/functions/sleep.html :

The sleep() function shall cause the calling thread to be suspended from execution until either the number of realtime seconds specified by the argument seconds has elapsed or a signal is delivered to the calling thread and its action is to invoke a signal-catching function or to terminate the process.

Mais si beaucoup de personne se pose la question c’est que cela n’a pas toujours été le cas. Sauf problème de mémoire j’ai vu le changement entre la Redhat 8.0 et la Fédora 9.0.

Mes OS de développement ont été (dans l’ordre) :

  • Redhat 5.2 ( la seule version que j’ai acheté, misère – pour information la date de release est : 2 novembre 1998 ) : A l’université de Toulouse.
  • SuSE ? : Chez Centre Océanographique de Marseille.
  • Debian ? : Chez Cyber-workers / Alias .
  • Redhat ? : Chez Rightvision
  • Redhat 7.2 : Chez Honeywell / SeCOM
  • Redhat 8.0 : Chez Honeywell / SeCOM
  • Fédora 9.0 : Chez Honeywell / SeCOM
  • Fédora 14.0 : Chez Honeywell / SeCOM
  • Fédora 17.0 : Chez Honeywell / SeCOM
  • Oracle 7.0 : Chez Honeywell / SeCOM
  • Oracle 7.2 : Chez Honeywell / SeCOM
  • Oracle 7.3 : Chez Honeywell / SeCOM
  • Oracle 7.4 : Chez Honeywell / SeCOM
  • Oracle 7.5 & Fédora 26 sous Docker : Chez Honeywell / SeCOM
  • Ubuntu 16.04 :  Chez Honeywell / SeCOM

Chez moi c’est plutôt Raspbian STRETCH ( Débian )  : https://www.raspberrypi.org/downloads/raspbian/ .

Bref, cela fait seulement 20 ans que je suis sous Linux.

Ma version de Linux Ubuntu :

$ uname -a
Linux VirtualBox 4.15.0-36-generic #39~16.04.1-Ubuntu SMP Tue Sep 25 08:59:23 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

Au passage on peut aussi voir l’impact des directives de compilation sur la taille :

$ gcc test_pthread_test.c -lpthread -o test2
$ gcc test_pthread_test.c -lpthread -O2 -o test2-O2
$ gcc test_pthread_test.c -lpthread -O3 -o test2-O3
$ gcc test_pthread_test.c -lpthread -O -o test2-O
$ gcc test_pthread_test.c -lpthread -g -o test2-g
$ gcc test_pthread_test.c -lpthread -g -O3 -o test2-g-03
$ ls -l test2*
13208  test2
15024  test2-g
14880  test2-g-03
9120   test2-O
9120   test2-O2
9120   test2-O3

Voila.

(Bisous à Luc)

Raspberry / Munin / USB : Température via l’USB

14 x served & 6 x viewed

Suite de l’article : http://www.cyber-neurones.org/2018/10/munin-usb-temperature-via-lusb-ok-mais-sabstenir-si-on-nest-pas-developpeur/ : « Raspberry / Munin / USB : Température via l’USB : OK mais s’abstenir si on n’est pas développeur ! »

Finalement j’ai fait un script bash pour une meilleure gestion :

$ cat /usr/share/munin/plugins/temper_x
#!/bin/sh
VCG=/usr/sbin/temperx                                                
WARN=70 
CRIT=75     
if [ "$1" = "autoconf" ]; then  
        if [ -x $VCG ]; then  
                echo yes            
                exit 0 
        else                                                         
                echo no 
                exit 1     
        fi                                                           
elif [ "$1" = "config" ]; then                                       
        echo "graph_title USB Temperature"   
        echo "graph_args --base 1000"       
        echo "graph_vlabel Celsius"             
        echo "graph_category sensors" 
        echo "graph_info Temperature with USB"   
        echo "Temperature.label Temperature"     
        echo "Temperature.type GAUGE"           
        echo "Temperature.info Celsius."           
        echo "Temperature.colour 00ff00"          
        echo "Temperature.warning $WARN"          
        echo "Temperature.critical $CRIT"      
        exit 0 
fi                                                                                                                                 
temp=$($VCG)                                                         
echo "$temp"

$ sudo cat go/src/github.com/mreymann/temperx/temperx.go | tail -10
			return
		}

		if buf, err := device.Read(-1, 1*time.Second); err == nil {
			tmp := (float64(buf[2])*256+float64(buf[3]))/100*tf + to
			hum := (float64(buf[4])*256+float64(buf[5]))/100*hf + ho
			fmt.Printf("Temperature.value %v\nHumidity.value %v\n", tmp, hum)
		}
	})
}

Le graphique est donc le suivant :

Raspberry / Munin / USB : Température via l’USB : OK mais s’abstenir si on n’est pas développeur !

28 x served & 10 x viewed

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 : http://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 Bhttps://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 Chttp://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 .