{"id":4621,"date":"2021-12-16T19:22:45","date_gmt":"2021-12-16T18:22:45","guid":{"rendered":"https:\/\/www.fanjoe.be\/?p=4621"},"modified":"2022-01-09T00:30:27","modified_gmt":"2022-01-08T23:30:27","slug":"detecteur-de-co2-modele-2co3tb-recuperer-les-donnees-du-capteur-sur-un-raspberry-pi-avec-gatttool","status":"publish","type":"post","link":"https:\/\/www.fanjoe.be\/?p=4621","title":{"rendered":"D\u00e9tecteur de CO2 mod\u00e8le 2CO3TB : R\u00e9cup\u00e9rer les donn\u00e9es du capteur sur un Raspberry Pi avec gatttool"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\">Introduction<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Avec la pand\u00e9mie qui persiste, il est recommand\u00e9 d&rsquo;utiliser un appareil de mesure du CO<sub>2<\/sub> pour d\u00e9terminer la qualit\u00e9 de l&rsquo;air et son bon renouvellement. Je me suis donc mis \u00e0 la recherche d&rsquo;un capteur qui r\u00e9ponde \u00e0 ces besoins et, tant qu&rsquo;\u00e0 faire, essayer d&rsquo;en trouver un en Bluetooth pour compl\u00e9ter ma collection et relever les donn\u00e9es \u00e0 intervalles r\u00e9guliers.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Voici les pr\u00e9c\u00e9dents articles qui parlent de mes capteurs :<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a rel=\"noreferrer noopener\" href=\"https:\/\/www.fanjoe.be\/?p=2741\" target=\"_blank\" class=\"ek-link\">Flower Care \/ MiFlora de Xiaomi : R\u00e9cup\u00e9rer les donn\u00e9es avec Gatttool sur un RPi 3<\/a><\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/www.fanjoe.be\/?p=3520\" target=\"_blank\" class=\"ek-link\">Flower Power de Parrot : R\u00e9cup\u00e9rer les donn\u00e9es du capteur sur un Raspberry Pi avec gatttool<\/a><\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/www.fanjoe.be\/?p=2889\" target=\"_blank\" class=\"ek-link\">Linux : Importer les donn\u00e9es d\u2019un Tempo Disc de BlueMaestro<\/a><\/li><li><a href=\"https:\/\/www.fanjoe.be\/?p=3911\" target=\"_blank\" aria-label=\" (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"ek-link\">Xiaomi Mijia LYWSD03MMC : R\u00e9cup\u00e9rer les donn\u00e9es du capteur sur un Raspberry Pi avec gatttool<\/a><\/li><\/ul>\n\n\n\n<h1 class=\"wp-block-heading\">Pr\u00e9sentation du capteur<\/h1>\n\n\n\n<div class=\"wp-block-media-text alignwide is-stacked-on-mobile is-vertically-aligned-center\"><figure class=\"wp-block-media-text__media\"><a href=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2021\/12\/Capteur-CO2-01.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"300\" data-attachment-id=\"4622\" data-permalink=\"https:\/\/www.fanjoe.be\/?attachment_id=4622\" data-orig-file=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2021\/12\/Capteur-CO2-01.jpg\" data-orig-size=\"700,700\" data-comments-opened=\"1\" data-image-title=\"Capteur-CO2-01\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2021\/12\/Capteur-CO2-01-620x620.jpg\" src=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2021\/12\/Capteur-CO2-01-300x300.jpg\" alt=\"\" class=\"wp-image-4622 size-medium\" srcset=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2021\/12\/Capteur-CO2-01-300x300.jpg 300w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2021\/12\/Capteur-CO2-01-620x620.jpg 620w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2021\/12\/Capteur-CO2-01-175x175.jpg 175w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2021\/12\/Capteur-CO2-01-100x100.jpg 100w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2021\/12\/Capteur-CO2-01.jpg 700w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/figure><div class=\"wp-block-media-text__content\">\n<p class=\"wp-block-paragraph\">Mon choix s&rsquo;est port\u00e9 sur un appareil \u00ab\u00a0no name\u00a0\u00bb de type <strong>2CO3TB<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Ses dimensions sont : 70mm x 89mm x 35mm et il mesure :<\/p>\n\n\n\n<ul class=\"is-style-default wp-block-list\"><li>Le monoxyde de carbone<\/li><li>Le formald\u00e9hyde<\/li><li>Les compos\u00e9s organiques volatiles (COV)<\/li><li>La temp\u00e9rature<\/li><li>L&rsquo;humidit\u00e9<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2021\/12\/Capteur-CO2-02.png\"><img loading=\"lazy\" decoding=\"async\" width=\"620\" height=\"125\" data-attachment-id=\"4666\" data-permalink=\"https:\/\/www.fanjoe.be\/?attachment_id=4666\" data-orig-file=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2021\/12\/Capteur-CO2-02.png\" data-orig-size=\"620,125\" data-comments-opened=\"1\" data-image-title=\"Capteur-CO2-02\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2021\/12\/Capteur-CO2-02.png\" src=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2021\/12\/Capteur-CO2-02.png\" alt=\"\" class=\"wp-image-4666\" srcset=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2021\/12\/Capteur-CO2-02.png 620w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2021\/12\/Capteur-CO2-02-300x60.png 300w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2021\/12\/Capteur-CO2-02-175x35.png 175w\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" \/><\/a><\/figure>\n<\/div><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Vous pouvez le retrouver sur Amazon pour un peu plus de 30\u20ac : <a rel=\"noreferrer noopener\" href=\"https:\/\/amzn.to\/3p0KyGN\" target=\"_blank\">https:\/\/amzn.to\/3p0KyGN<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Il est muni d&rsquo;un port micro-USB pour l&rsquo;alimenter et recharger la batterie amovible (fournie) de 3.7V, de type 18650 et de 1500mAh. La batterie n&rsquo;est pas n\u00e9cessaire s&rsquo;il est aliment\u00e9 en USB. Un c\u00e2ble d&rsquo;un m\u00e8tre est livr\u00e9 dans la boite. L&rsquo;autonomie sur batterie est de quelques heures.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">L&rsquo;\u00e9cran affiche toutes les informations utiles en couleur. Il n&rsquo;est  pas de grande qualit\u00e9 et offre un faible angle de vision. Son affichage est rafraichi toutes les secondes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Un seul et unique bouton permet de :<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Allumer ou \u00e9teindre le capteur.<\/li><li>S\u00e9lectionner l&rsquo;affichage en Celsius ou Fahrenheit.<\/li><li>Activer ou d\u00e9sactiver l&rsquo;alarme sonore de d\u00e9passement de 1000ppm de CO<sub>2<\/sub>.<\/li><\/ul>\n\n\n\n<h1 class=\"wp-block-heading\">Importer les donn\u00e9es<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\">Installation du Bluetooth<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">En principe, si vous utilisez un RPi avec Jessie, Stretch, Buster ou Bullseye, les outils&nbsp;<em>gatttool<\/em>&nbsp;et&nbsp;<em>hcitool<\/em>&nbsp;que nous allons utiliser plus loin devraient d\u00e9j\u00e0 \u00eatre install\u00e9s.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Si ce n\u2019est pas le cas, je vous renvoie vers cet article :&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/fr.tipsandtrics.com\/how-setup-wi-fi-bluetooth-raspberry-pi-3-768782\" target=\"_blank\">https:\/\/fr.tipsandtrics.com<\/a><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo apt-get update\n$ sudo apt-get upgrade\n$ sudo apt-get install bluetooth bluez-utils blueman&nbsp;bluez<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">D\u00e9terminer l\u2019adresse MAC du capteur 2CO3TB<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Pour d\u00e9terminer cette adresse, nous allons utiliser l\u2019outil&nbsp;<em>hcitool<\/em>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo hcitool lescan<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Ce qui devrait nous retourner la liste des p\u00e9riph\u00e9rique Bluetooth LE (Low Energy) qui se trouvent \u00e0 proximit\u00e9 :<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">LE Scan ...\n1F:6B:29:20:B3:B7 (unknown)\n04:F7:A5:C7:2B:93 (unknown)\n<span style=\"background-color:#cf2e2e\" class=\"has-inline-background\">B6:6B:04:5C:82:B8 XS-82B8<\/span>\nB6:6B:04:5C:82:B8 XS-82B8\n59:CE:9B:42:D4:EB (unknown)\nFC:E4:1D:88:BD:59 FCE41D88\nFC:E4:1D:88:BD:59 (unknown)\n6E:A7:D6:8F:70:26 (unknown)\nC4:7C:8D:62:83:C9 (unknown)\nC4:7C:8D:62:83:C9 Flower care\nEA:80:2F:03:5B:70 (unknown)\nC4:F7:3A:21:8A:6D (unknown)\nBA:95:9F:9F:58:00 A06AMJ\nBA:95:9F:9F:58:00 (unknown)\nD9:6A:EB:12:C1:1A (unknown)\nF4:0F:24:21:C3:6A (unknown)\n90:03:B7:E7:DC:6C Parrot\nF4:0F:24:21:C3:6A (unknown)\n4F:BE:C3:52:33:73 (unknown)\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Le capteur 2CO3TB a donc la MAC Address suivante :&nbsp;<code>B6:6B:04:5C:82:B8<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Importer les donn\u00e9es avec gatttool<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">gatttool en mode interactif<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Premiers pas<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Pour commencer, nous allons nous connecter en mode interactif (&nbsp;<code>-I<\/code>&nbsp;) avec cette commande :<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo gatttool --device=B6:6B:04:5C:82:B8 -I<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Une fois d\u00e9marr\u00e9, l\u2019outil est pr\u00eat \u00e0 recevoir des commandes et ceci devrait apparaitre \u00e0 l\u2019\u00e9cran :<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[B6:6B:04:5C:82:B8][LE]&gt;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">On va se connecter avec cette commande :<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">connect<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">L\u2019outil devrait r\u00e9pondre quelque chose comme ceci et l\u2019adresse MAC devrait passer en bleu lorsque la connexion est \u00e9tablie :<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[B6:6B:04:5C:82:B8][LE]&gt; connect\nAttempting to connect to B6:6B:04:5C:82:B8\nConnection successful\nNotification handle = 0x000c value: 23 06 10 04 00 dc 00 30 5d \nNotification handle = 0x000c value: 23 08 10 04 01 9f 00 0c 00 03 07 \nNotification handle = 0x000c value: 23 06 10 04 00 dc 00 30 5d \nNotification handle = 0x000c value: 23 08 10 04 01 9f 00 0c 00 03 07 \nNotification handle = 0x000c value: 23 06 10 04 00 dc 00 30 5d \nNotification handle = 0x000c value: 23 08 10 04 01 9f 00 0c 00 03 07 \nNotification handle = 0x000c value: 23 06 10 04 00 dc 00 30 5d \nNotification handle = 0x000c value: 23 08 10 04 01 9f 00 0c 00 03 07 \nNotification handle = 0x000c value: 23 06 10 04 00 dc 00 30 5d \nNotification handle = 0x000c value: 23 08 10 04 01 9f 00 0c 00 03 07 \nNotification handle = 0x000c value: 23 06 10 04 00 dc 00 30 5d \nNotification handle = 0x000c value: 23 08 10 04 01 9f 00 0c 00 03 07 <\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u00c0 intervalles r\u00e9guliers de quelques secondes, on voit s\u2019ajouter des lignes de \u00ab\u00a0<code>Notification handle<\/code>\u00ab\u00a0. Ce sont les donn\u00e9es du capteur qui sont renvoy\u00e9es sous forme de notifications.<\/p>\n\n\n\n<div class=\"wp-block-media-text alignwide is-stacked-on-mobile is-vertically-aligned-center\" style=\"grid-template-columns:15% auto\"><figure class=\"wp-block-media-text__media\"><a href=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2021\/12\/Capteur-CO2-03.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"122\" height=\"175\" data-attachment-id=\"4732\" data-permalink=\"https:\/\/www.fanjoe.be\/?attachment_id=4732\" data-orig-file=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2021\/12\/Capteur-CO2-03.jpg\" data-orig-size=\"495,708\" data-comments-opened=\"1\" data-image-title=\"Capteur-CO2-03\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2021\/12\/Capteur-CO2-03.jpg\" src=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2021\/12\/Capteur-CO2-03-122x175.jpg\" alt=\"\" class=\"wp-image-4732 size-thumbnail\" srcset=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2021\/12\/Capteur-CO2-03-122x175.jpg 122w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2021\/12\/Capteur-CO2-03-300x429.jpg 300w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2021\/12\/Capteur-CO2-03.jpg 495w\" sizes=\"auto, (max-width: 122px) 100vw, 122px\" \/><\/a><\/figure><div class=\"wp-block-media-text__content\">\n<p class=\"wp-block-paragraph\">Dans le bouquin \u00ab\u00a0Inside bluetooth low energy &#8211; Second Edition\u00a0\u00bb de Naresh Gupta aux \u00e9ditions Artech House, \u00e0 la page 323 (<a rel=\"noreferrer noopener\" href=\"https:\/\/books.google.be\/books?id=3nCuDgAAQBAJ&amp;pg=PA323&amp;lpg=PA323&amp;dq=bluetooth+le+notifications+handles&amp;source=bl&amp;ots=rMVcu0w8sa&amp;sig=ACfU3U1hAcA2PI2prydDkfsAjpH_d7RcNg&amp;hl=fr&amp;sa=X&amp;ved=2ahUKEwjppN29yOj0AhXX_7sIHdUDAooQ6AF6BAgTEAM#v=onepage&amp;q=bluetooth%20le%20notifications%20handles&amp;f=false\" target=\"_blank\" class=\"ek-link\">https:\/\/books.google.be\/<\/a>, l&rsquo;auteur explique le principe des notifications ATT (Attribute Protocol).<\/p>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-medium\"><a href=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2021\/12\/Capteur-CO2-04.png\"><img loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"185\" data-attachment-id=\"4739\" data-permalink=\"https:\/\/www.fanjoe.be\/?attachment_id=4739\" data-orig-file=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2021\/12\/Capteur-CO2-04.png\" data-orig-size=\"1015,625\" data-comments-opened=\"1\" data-image-title=\"Capteur-CO2-04\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2021\/12\/Capteur-CO2-04-620x382.png\" src=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2021\/12\/Capteur-CO2-04-300x185.png\" alt=\"\" class=\"wp-image-4739\" srcset=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2021\/12\/Capteur-CO2-04-300x185.png 300w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2021\/12\/Capteur-CO2-04-620x382.png 620w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2021\/12\/Capteur-CO2-04-175x108.png 175w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2021\/12\/Capteur-CO2-04.png 1015w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Le serveur envoie des notifications au client sans attendre d&rsquo;accus\u00e9 de r\u00e9ception. Ces notifications comprennent un descripteur et une valeur d&rsquo;attribut.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Identification des UUID des handles<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">La commande&nbsp;<code>char-desc<\/code>&nbsp;va explorer les descripteurs de caract\u00e9ristiques et nous retourner tous les&nbsp;<code>handle<\/code>&nbsp;disponibles avec leurs num\u00e9ros et leurs uuid :<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[B6:6B:04:5C:82:B8][LE]&gt; char-desc\nhandle: 0x0001, uuid: 00002800-0000-1000-8000-00805f9b34fb\nhandle: 0x0002, uuid: 00002803-0000-1000-8000-00805f9b34fb\n<span class=\"has-inline-color has-vivid-red-color\">handle: 0x0003, uuid: 00002a00-0000-1000-8000-00805f9b34fb<\/span>\nhandle: 0x0004, uuid: 00002800-0000-1000-8000-00805f9b34fb\nhandle: 0x0005, uuid: 00002803-0000-1000-8000-00805f9b34fb\nhandle: 0x0006, uuid: 00002a05-0000-1000-8000-00805f9b34fb\nhandle: 0x0007, uuid: 00002902-0000-1000-8000-00805f9b34fb\nhandle: 0x0008, uuid: 00002800-0000-1000-8000-00805f9b34fb\nhandle: 0x0009, uuid: 00002803-0000-1000-8000-00805f9b34fb\nhandle: 0x000a, uuid: 0000c762-0000-1000-8000-00805f9b34fb\nhandle: 0x000b, uuid: 00002803-0000-1000-8000-00805f9b34fb\n<span class=\"has-inline-color has-vivid-red-color\">handle: 0x000c, uuid: 0000c761-0000-1000-8000-00805f9b34fb<\/span>\nhandle: 0x000d, uuid: 00002902-0000-1000-8000-00805f9b34fb\nhandle: 0x000e, uuid: 00002800-0000-1000-8000-00805f9b34fb\nhandle: 0x000f, uuid: 00002803-0000-1000-8000-00805f9b34fb\nhandle: 0x0010, uuid: f000ffc1-0451-4000-b000-000000000000\nhandle: 0x0011, uuid: 00002902-0000-1000-8000-00805f9b34fb\nhandle: 0x0012, uuid: 00002901-0000-1000-8000-00805f9b34fb\nhandle: 0x0013, uuid: 00002803-0000-1000-8000-00805f9b34fb\nhandle: 0x0014, uuid: f000ffc2-0451-4000-b000-000000000000\nhandle: 0x0015, uuid: 00002902-0000-1000-8000-00805f9b34fb\nhandle: 0x0016, uuid: 00002901-0000-1000-8000-00805f9b34fb\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Allons t\u00e9l\u00e9charger la liste des UUID standardis\u00e9s du Bluetooth : <a href=\"https:\/\/www.bluetooth.com\/specifications\/assigned-numbers\/\" class=\"ek-link\">https:\/\/www.bluetooth.com\/<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Malheureusement, l&rsquo;UUID du handle <code>0x000c<\/code> : <code>0000c761<\/code> ne correspond \u00e0 rien de standardis\u00e9 dans la liste.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Le seul qui peut nous int\u00e9resser est le <code>0x0003<\/code> : <code>00002a00<\/code> qui correspond au <strong>Device Name<\/strong>. Les autres UUID ne figurent pas dans la liste.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Lire un handle<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Pour lire le contenu d\u2019un&nbsp;<em>handle<\/em>, on utilise la commande&nbsp;<code>char-read-hnd<\/code>&nbsp;suivie du n\u00b0 du&nbsp;<em>handle<\/em>&nbsp;qui nous int\u00e9resse :<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><meta charset=\"utf-8\">[B6:6B:04:5C:82:B8][LE]&gt; char-read-hnd 0x0003\nCharacteristic value\/descriptor: 58 53 2d 31 32 33 34 00<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Convertir un handle<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Pour convertir les donn\u00e9es, il suffit d&rsquo;utiliser la table ASCII :<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-09-620x412.png\"><img loading=\"lazy\" decoding=\"async\" width=\"620\" height=\"412\" data-attachment-id=\"3954\" data-permalink=\"https:\/\/www.fanjoe.be\/?attachment_id=3954\" data-orig-file=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-09.png\" data-orig-size=\"1600,1064\" data-comments-opened=\"1\" data-image-title=\"gatttool-mijia-09\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-09-620x412.png\" src=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-09-620x412.png\" alt=\"\" class=\"wp-image-3954\" srcset=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-09-620x412.png 620w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-09-300x200.png 300w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-09-175x116.png 175w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-09-1536x1021.png 1536w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-09.png 1600w\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Dans notre cas :<\/p>\n\n\n\n<figure class=\"wp-block-table caption-align-default\"><table><tbody><tr><td class=\"has-text-align-center\" data-align=\"center\">58<\/td><td class=\"has-text-align-center\" data-align=\"center\">53<\/td><td class=\"has-text-align-center\" data-align=\"center\">2d<\/td><td class=\"has-text-align-center\" data-align=\"center\">31<\/td><td class=\"has-text-align-center\" data-align=\"center\">32<\/td><td class=\"has-text-align-center\" data-align=\"center\">33<\/td><td class=\"has-text-align-center\" data-align=\"center\">34<\/td><td class=\"has-text-align-center\" data-align=\"center\">00<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">X<\/td><td class=\"has-text-align-center\" data-align=\"center\">S<\/td><td class=\"has-text-align-center\" data-align=\"center\">&#8211;<\/td><td class=\"has-text-align-center\" data-align=\"center\">1<\/td><td class=\"has-text-align-center\" data-align=\"center\">2<\/td><td class=\"has-text-align-center\" data-align=\"center\">3<\/td><td class=\"has-text-align-center\" data-align=\"center\">4<\/td><td class=\"has-text-align-center\" data-align=\"center\">(NULL)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Nous obtenons : <strong>XS-1234<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">gatttool en ligne de commande<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Lire un handle<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Pour lire un handle en ligne de commande, nous utiliserons :<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo gatttool --device=<meta charset=\"utf-8\">B6:6B:04:5C:82:B8 --char-read -a 0x03\nCharacteristic value\/descriptor: 58 53 2d 31 32 33 34 00<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u00c9couter les Notification handle<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Dans le cas qui nous occupe, pour lire les donn\u00e9es, il n\u2019est pas possible de lire directement le handle <code>0c<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Voici les valeurs qui seraient retourn\u00e9es :<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo gatttool --device=B6:6B:04:5C:82:B8 --char-read -a 0x0c\nCharacteristic value\/descriptor: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Pour obtenir les donn\u00e9es, nous allons inscrire une valeur arbitraire dans le handle 31 qui n&rsquo;existe pas et \u00e9couter tout ce qui se passe ensuite (&nbsp;<code>--listen<\/code>&nbsp;):<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo gatttool --device=B6:6B:04:5C:82:B8 --char-write-req --handle=0x0031 --value=0100 --listen\nCharacteristic Write Request failed: Invalid handle\nNotification handle = 0x000c value: 23 06 10 04 00 e9 00 2c 64 \nNotification handle = 0x000c value: 23 08 10 04 01 a5 00 0d 00 04 0f \nNotification handle = 0x000c value: 23 06 10 04 00 e9 00 2c 64 \nNotification handle = 0x000c value: 23 08 10 04 01 a2 00 0d 00 03 13 \nNotification handle = 0x000c value: 23 06 10 04 00 e9 00 2c 64 \nNotification handle = 0x000c value: 23 08 10 04 01 a2 00 0e 00 03 12 \nNotification handle = 0x000c value: 23 06 10 04 00 e9 00 2c 64 \nNotification handle = 0x000c value: 23 08 10 04 01 a5 00 0e 00 04 0e \nNotification handle = 0x000c value: 23 06 10 04 00 e9 00 2c 64 \nNotification handle = 0x000c value: 23 08 10 04 01 a5 00 0d 00 04 0f \nNotification handle = 0x000c value: 23 06 10 04 00 e9 00 2c 64 \n^C<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Une fois la tentative d&rsquo;\u00e9criture \u00e9chou\u00e9e, la commande va continuer \u00e0 recevoir les notifications du bo\u00eetier jusqu\u2019\u00e0 interruption avec&nbsp;<code>[ctrl] C<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Pour \u00e9viter ce blocage, on va restreindre le temps d\u2019ex\u00e9cution \u00e0 5 secondes (&nbsp;<code>timeout 5<\/code>&nbsp;).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Dans les donn\u00e9es, on remarque que la commande nous retourne successivement 2 lignes diff\u00e9rentes. On va donc ne r\u00e9cup\u00e9rer que 2 lignes de ces notifications (&nbsp;<code>grep<\/code>&nbsp;) :<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo timeout 5 gatttool --device=B6:6B:04:5C:82:B8 --char-write-req --handle=0x0031 --value=0100 --listen | grep --max-count=2 \"Notification handle\"<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Et voici la r\u00e9ponse retourn\u00e9e apr\u00e8s 15 secondes :<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Notification handle = 0x000c value: 23 08 10 04 01 9b 00 06 00 04 fe\nNotification handle = 0x000c value: 23 06 10 04 00 e9 00 2c 64<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Exploitation des donn\u00e9es<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Dans les donn\u00e9es, on s&rsquo;aper\u00e7oit que certains octets gardent toujours la m\u00eame valeur alors que d&rsquo;autres varient.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Notification handle = 0x000c value: <span class=\"has-inline-color has-vivid-red-color\">23 08 10 04<\/span> <span class=\"has-inline-color has-vivid-green-cyan-color\">01 9b 00 0a 00 0d<\/span> fe\nNotification handle = 0x000c value: <span class=\"has-inline-color has-vivid-red-color\">23 06 10 04<\/span> <span class=\"has-inline-color has-vivid-green-cyan-color\">00 e9 00 2c<\/span> 64<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">En rouge, les octets fixes et en vert, ceux qui nous int\u00e9ressent.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Voici comment se structurent les donn\u00e9es :<\/p>\n\n\n\n<table id=\"tablepress-8\" class=\"tablepress tablepress-id-8 tbody-has-connected-cells\">\n<thead>\n<tr class=\"row-1\">\n\t<th colspan=\"2\" class=\"column-1\">CO2<\/th><th colspan=\"2\" class=\"column-3\">TVOC<\/th><th colspan=\"2\" class=\"column-5\">HCHO<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr class=\"row-2\">\n\t<td class=\"column-1\">01<\/td><td class=\"column-2\">9b<\/td><td class=\"column-3\">00<\/td><td class=\"column-4\">0a<\/td><td class=\"column-5\">00<\/td><td class=\"column-6\">0d<\/td>\n<\/tr>\n<tr class=\"row-3\">\n\t<td colspan=\"2\" class=\"column-1\">411<\/td><td colspan=\"2\" class=\"column-3\">10<\/td><td colspan=\"2\" class=\"column-5\">13<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<!-- #tablepress-8 from cache -->\n\n\n\n<table id=\"tablepress-9\" class=\"tablepress tablepress-id-9 tbody-has-connected-cells\">\n<thead>\n<tr class=\"row-1\">\n\t<th colspan=\"2\" class=\"column-1\">Temp\u00e9rature<\/th><th colspan=\"2\" class=\"column-3\">Humidit\u00e9<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr class=\"row-2\">\n\t<td class=\"column-1\">00<\/td><td class=\"column-2\">e9<\/td><td class=\"column-3\">00<\/td><td class=\"column-4\">2c<\/td>\n<\/tr>\n<tr class=\"row-3\">\n\t<td colspan=\"2\" class=\"column-1\">233<\/td><td colspan=\"2\" class=\"column-3\">44<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<!-- #tablepress-9 from cache -->\n\n\n\n<p class=\"wp-block-paragraph\">Les octets sont regroup\u00e9s par deux et convertis d&rsquo;hexad\u00e9cimal vers d\u00e9cimal : <code>019b =&gt; 411<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Il faut diviser la temp\u00e9rature par 10 : <code>00e9 =&gt; 233 =&gt; 23,3\u00b0C<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Les taux TVOC et HCHO doivent \u00eatre divis\u00e9s par 1000 : <code>000a =&gt; 10 =&gt; 0,010 mg\/m\u00b3 et 000d =&gt; 13 =&gt; 0,013 mg\/m\u00b3<\/code><\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Script<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Voici un petit script qui va nous retourner toutes les valeurs utiles du capteur :<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n#!\/bin\/bash\n\n# V\u00e9rifie que l&#039;on est en Root\nif &#x5B;&#x5B; $EUID -ne 0 ]];\nthen\n\techo &quot;Ce script doit \u00eatre ex\u00e9cut\u00e9 avec les privil\u00e8ges administrateur&quot;\n   \texit 1\nfi\n\nMACadd=&quot;B6:6B:04:5C:82:B8&quot;\n\nhciconfig hci0 down\nhciconfig hci0 up\n\n\nhnd03=$(gatttool --device=$MACadd --char-read -a 0x03)\n#Characteristic value\/descriptor: 58 53 2d 31 32 33 34 00\nname=$(echo &quot;$hnd03&quot; | cut -c34-57 | xxd -r -p | tr -d &#039;\\0&#039;)\necho &quot;Nom : $name&quot;\necho\n\ndata=$((timeout 5 gatttool --device=$MACadd --char-write-req --handle=0x0031 --value=0100 --listen | grep --max-count=2 &quot;Notification handle&quot;) 2&gt;\/dev\/null)\n\ndata1=$(echo &quot;$data&quot; | grep --max-count=1 &quot;Notification handle = 0x000c value: 23 08 10 04&quot;)\ndata2=$(echo &quot;$data&quot; | grep --max-count=1 &quot;Notification handle = 0x000c value: 23 06 10 04&quot;)\n\nco2=${data1:48:2}${data1:51:2}\nco2=$((16#$co2))\necho &quot;CO2 : $co2 ppm&quot;\n\ntvoc=${data1:54:2}${data1:57:2}\ntvoc=$((16#$tvoc))\ntvoc=$(echo &quot;scale=3;$tvoc\/1000&quot; | bc | sed &#039;s\/^\\.\/0.\/&#039;)\necho &quot;TVOC : $tvoc mg\/m\u00b3&quot;\n\nhcho=${data1:60:2}${data1:63:2}\nhcho=$((16#$hcho))\nhcho=$(echo &quot;scale=3;$hcho\/1000&quot; | bc | sed &#039;s\/^\\.\/0.\/&#039;)\necho &quot;HCHO : $hcho mg\/m\u00b3&quot;\n\ntemp=${data2:48:2}${data2:51:2}\ntemp=$((16#$temp))\ntemp=$(echo &quot;scale=3;$temp\/10&quot; | bc | sed &#039;s\/^\\.\/0.\/&#039;)\necho &quot;Temp\u00e9rature : $temp \u00b0C&quot;\n\nhum=${data2:54:2}${data2:57:2}\nhum=$((16#$hum))\necho &quot;Humidit\u00e9 : $hum %&quot;\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\"><strong>Edit 09\/01\/2022 :<\/strong> Les modifications propos\u00e9es par <strong>Francesco Talamona<\/strong> dans les commentaires ont \u00e9t\u00e9 impl\u00e9ment\u00e9es au script.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Voici ce que le script devrait retourner comme r\u00e9sultat :<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Nom : XS-1234\n\nCharacteristic Write Request failed: Invalid handle\nCO2 : 418 ppm\nTVOC : 0.013 mg\/m\u00b3\nHCHO : 0.003 mg\/m\u00b3\nTemp\u00e9rature : 23.300 \u00b0C\nHumidit\u00e9 : 44 %<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Introduction <\/p>\n<p class=\"wp-block-paragraph\">Avec la pand\u00e9mie qui persiste, il est recommand\u00e9 d&rsquo;utiliser un appareil de mesure du CO2 pour d\u00e9terminer la&#8230;<\/p>\n","protected":false},"author":1,"featured_media":4952,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","jetpack_post_was_ever_published":false},"categories":[179,10,3,173,12],"tags":[397,13,396,395,17,287,22],"class_list":["post-4621","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-domotique","category-geek","category-informatique","category-linux","category-raspberrypi","tag-2co3tb","tag-bluetooth","tag-capteur","tag-co2","tag-domotique","tag-gatttool","tag-raspberry-pi","end"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2021\/12\/Capteur-CO2-00.png","_links":{"self":[{"href":"https:\/\/www.fanjoe.be\/index.php?rest_route=\/wp\/v2\/posts\/4621","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.fanjoe.be\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fanjoe.be\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fanjoe.be\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fanjoe.be\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4621"}],"version-history":[{"count":0,"href":"https:\/\/www.fanjoe.be\/index.php?rest_route=\/wp\/v2\/posts\/4621\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.fanjoe.be\/index.php?rest_route=\/wp\/v2\/media\/4952"}],"wp:attachment":[{"href":"https:\/\/www.fanjoe.be\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4621"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fanjoe.be\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4621"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fanjoe.be\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4621"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}