{"id":3911,"date":"2020-04-16T03:01:08","date_gmt":"2020-04-16T01:01:08","guid":{"rendered":"https:\/\/www.fanjoe.be\/?p=3911"},"modified":"2021-01-24T17:05:11","modified_gmt":"2021-01-24T16:05:11","slug":"xiaomi-mijia-lywsd03mmc-recuperer-les-donnees-du-capteur-sur-un-raspberry-pi-avec-gatttool","status":"publish","type":"post","link":"https:\/\/www.fanjoe.be\/?p=3911","title":{"rendered":"Xiaomi Mijia LYWSD03MMC : 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\">Depuis quelques temps, j&rsquo;utilise diff\u00e9rents types de capteurs Bluetooth pour effectuer des mesures de temp\u00e9rature, d&rsquo;humidit\u00e9, d&rsquo;\u00e9clairement, de fertilit\u00e9 du sol, &#8230;<\/p>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<p class=\"wp-block-paragraph\">Voici les pr\u00e9c\u00e9dents articles qui en ont parl\u00e9 :<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a rel=\"noreferrer noopener\" href=\"https:\/\/www.fanjoe.be\/?p=2741\" target=\"_blank\">Flower Care \/ MiFlora de Xiaomi : R\u00e9cup\u00e9rer les donn\u00e9es avec Gatttool sur un RPi 3<\/a><\/li><li><a href=\"https:\/\/www.fanjoe.be\/?p=3520\" target=\"_blank\" rel=\"noreferrer noopener\">Flower Power de Parrot : R\u00e9cup\u00e9rer les donn\u00e9es du capteur sur un Raspberry Pi avec gatttool<\/a><\/li><li><a href=\"https:\/\/www.fanjoe.be\/?p=2889\" target=\"_blank\" rel=\"noreferrer noopener\">Linux : Importer les donn\u00e9es d\u2019un Tempo Disc de BlueMaestro<\/a><\/li><\/ul>\n<\/div><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Aujourd&rsquo;hui, je vais d\u00e9tailler la proc\u00e9dure pour r\u00e9cup\u00e9rer les donn\u00e9es en provenance d&rsquo;un capteur de temp\u00e9rature et d&rsquo;humidit\u00e9 Xiaomi Mijia LYWSD03MMC.<\/p>\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\/2020\/04\/gatttool-mijia-01.jpg\" target=\"none\" rel=\"noopener noreferrer\"><img loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"228\" data-attachment-id=\"3915\" data-permalink=\"https:\/\/www.fanjoe.be\/?attachment_id=3915\" data-orig-file=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-01.jpg\" data-orig-size=\"1000,759\" data-comments-opened=\"1\" data-image-title=\"gatttool-mijia-01\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-01-620x471.jpg\" src=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-01-300x228.jpg\" alt=\"\" class=\"wp-image-3915 size-full\" srcset=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-01-300x228.jpg 300w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-01-620x471.jpg 620w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-01-175x133.jpg 175w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-01-460x350.jpg 460w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-01.jpg 1000w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/figure><div class=\"wp-block-media-text__content\">\n<p class=\"wp-block-paragraph\">Le capteur a une taille tr\u00e8s modeste puisqu&rsquo;il ne mesure que 4.30 x 4.30 x 1.25 cm et ne p\u00e8se pas plus de 60g.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Il est aliment\u00e9 par une pile classique CR 2032.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Il est muni d&rsquo;un petit \u00e9cran LCD qui affiche la temp\u00e9rature, le pourcentage d&rsquo;hygrom\u00e9trie et un petit smiley qui d\u00e9termine si la combinaison des deux premi\u00e8res valeurs est confortable. <\/p>\n<\/div><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">On le trouve facilement sur <a rel=\"noreferrer noopener\" href=\"https:\/\/amzn.to\/3dgDaxD\" target=\"_blank\" class=\"ek-link\">Amazon<\/a> pour moins d&rsquo;une dizaine d&rsquo;euros.<\/p>\n\n\n\n<figure class=\"wp-block-gallery columns-3 is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\"><ul class=\"blocks-gallery-grid\"><li class=\"blocks-gallery-item\"><figure><a href=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-02.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"600\" data-attachment-id=\"3938\" data-permalink=\"https:\/\/www.fanjoe.be\/?attachment_id=3938\" data-orig-file=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-02.jpg\" data-orig-size=\"600,600\" data-comments-opened=\"1\" data-image-title=\"gatttool-mijia-02\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-02.jpg\" src=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-02.jpg\" alt=\"\" data-id=\"3938\" data-full-url=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-02.jpg\" data-link=\"https:\/\/www.fanjoe.be\/?attachment_id=3938\" class=\"wp-image-3938\" srcset=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-02.jpg 600w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-02-300x300.jpg 300w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-02-175x175.jpg 175w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-02-100x100.jpg 100w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><a href=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-03.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"600\" data-attachment-id=\"3939\" data-permalink=\"https:\/\/www.fanjoe.be\/?attachment_id=3939\" data-orig-file=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-03.jpg\" data-orig-size=\"600,600\" data-comments-opened=\"1\" data-image-title=\"gatttool-mijia-03\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-03.jpg\" src=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-03.jpg\" alt=\"\" data-id=\"3939\" data-full-url=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-03.jpg\" data-link=\"https:\/\/www.fanjoe.be\/?attachment_id=3939\" class=\"wp-image-3939\" srcset=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-03.jpg 600w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-03-300x300.jpg 300w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-03-175x175.jpg 175w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-03-100x100.jpg 100w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><a href=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-04.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"600\" data-attachment-id=\"3940\" data-permalink=\"https:\/\/www.fanjoe.be\/?attachment_id=3940\" data-orig-file=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-04.jpg\" data-orig-size=\"600,600\" data-comments-opened=\"1\" data-image-title=\"gatttool-mijia-04\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-04.jpg\" src=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-04.jpg\" alt=\"\" data-id=\"3940\" data-full-url=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-04.jpg\" data-link=\"https:\/\/www.fanjoe.be\/?attachment_id=3940\" class=\"wp-image-3940\" srcset=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-04.jpg 600w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-04-300x300.jpg 300w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-04-175x175.jpg 175w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-04-100x100.jpg 100w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><a href=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-05.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"600\" data-attachment-id=\"3941\" data-permalink=\"https:\/\/www.fanjoe.be\/?attachment_id=3941\" data-orig-file=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-05.jpg\" data-orig-size=\"600,600\" data-comments-opened=\"1\" data-image-title=\"gatttool-mijia-05\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-05.jpg\" src=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-05.jpg\" alt=\"\" data-id=\"3941\" data-full-url=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-05.jpg\" data-link=\"https:\/\/www.fanjoe.be\/?attachment_id=3941\" class=\"wp-image-3941\" srcset=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-05.jpg 600w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-05-300x300.jpg 300w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-05-175x175.jpg 175w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-05-100x100.jpg 100w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><a href=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-06.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"600\" data-attachment-id=\"3942\" data-permalink=\"https:\/\/www.fanjoe.be\/?attachment_id=3942\" data-orig-file=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-06.jpg\" data-orig-size=\"600,600\" data-comments-opened=\"1\" data-image-title=\"gatttool-mijia-06\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-06.jpg\" src=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-06.jpg\" alt=\"\" data-id=\"3942\" data-full-url=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-06.jpg\" data-link=\"https:\/\/www.fanjoe.be\/?attachment_id=3942\" class=\"wp-image-3942\" srcset=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-06.jpg 600w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-06-300x300.jpg 300w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-06-175x175.jpg 175w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-06-100x100.jpg 100w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><a href=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-07.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"600\" data-attachment-id=\"3943\" data-permalink=\"https:\/\/www.fanjoe.be\/?attachment_id=3943\" data-orig-file=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-07.jpg\" data-orig-size=\"600,600\" data-comments-opened=\"1\" data-image-title=\"gatttool-mijia-07\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-07.jpg\" src=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-07.jpg\" alt=\"\" data-id=\"3943\" data-full-url=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-07.jpg\" data-link=\"https:\/\/www.fanjoe.be\/?attachment_id=3943\" class=\"wp-image-3943\" srcset=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-07.jpg 600w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-07-300x300.jpg 300w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-07-175x175.jpg 175w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-07-100x100.jpg 100w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/figure><\/li><\/ul><figcaption class=\"blocks-gallery-caption\">Images : <a href=\"https:\/\/la.shoppingdirect24.com\/Products\/xiaomi-mijia-lywsd03mmc-Bluetooth-IV-II-secundum-quod-Thermometrum-wireless-digital-dolor-electrica-opus-hygrometer-in-app-mijia\" target=\"_blank\" aria-label=\"https:\/\/fr.shoppingdirect24.com\/ (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"ek-link\">https:\/\/fr.shoppingdirect24.com\/<\/a><\/figcaption><\/figure>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>N.B. :<\/strong> Seule la version destin\u00e9e au march\u00e9 chinois est actuellement en vente. Vous devrez donc localiser l&rsquo;App iOS \u00ab\u00a0<a rel=\"noreferrer noopener\" href=\"https:\/\/apps.apple.com\/fr\/app\/mi-home-xiaomi-smarthome\/id957323480\" target=\"_blank\">Xiaomi Home<\/a>\u00a0\u00bb en Chine pour pouvoir appairer un nouveau Mijia LYWSD03MMC, sans quoi il n&rsquo;appara\u00eetra pas dans la liste des accessoires Xiaomi.<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"Mijia LYWSD03MMC Bluetooth 4.2 Household Thermometer Hygrometer  - Gearbest.com\" width=\"980\" height=\"551\" src=\"https:\/\/www.youtube.com\/embed\/AdvSkDz2SyQ?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><figcaption>Appairage avec un iPhone<\/figcaption><\/figure>\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 ou Buster, les outils <em>gatttool<\/em> et <em>hcitool<\/em> 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 : <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 Mijia LYWSD03MMC<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Pour d\u00e9terminer cette adresse, nous allons utiliser l\u2019outil <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 \u2026\n90:03:B7:E7:DC:6C (unknown)\n90:03:B7:E7:DC:6C Parrot\n4E:BD:77:42:D1:B5 (unknown)\n4E:BD:77:42:D1:B5 (unknown)\nC4:7C:8D:62:83:C9 (unknown)\nC4:7C:8D:62:83:C9 Flower care\n4E:94:AD:DE:80:33 (unknown)\n4E:94:AD:DE:80:33 (unknown)\nA4:C1:38:9D:D1:8F (unknown)\n<span class=\"has-inline-color has-vivid-red-color\">A4:C1:38:9D:D1:8F LYWSD03MMC<\/span>\n4B:13:13:68:2D:F7 (unknown)\n4B:13:13:68:2D:F7 (unknown)<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Le Mijia LYWSD03MMC a donc la MAC Address suivante : <code>A4:C1:38:9D:D1:8F<\/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 ( <code>-I<\/code> ) avec cette commande :<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo gatttool --device=A4:C1:38:9D:D1:8F -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\">[A4:C1:38:9D:D1:8F][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\">[A4:C1:38:9D:D1:8F][LE]&gt; connect\nAttempting to connect to A4:C1:38:9D:D1:8F\nConnection successful\nNotification handle = 0x0036 value: ce 08 2a 0f 0c\nNotification handle = 0x0036 value: d0 08 2a 0f 0c\nNotification handle = 0x0036 value: d0 08 2a 0f 0c\nNotification handle = 0x0036 value: d0 08 2a 0f 0c\n<span style=\"color:#0000ff\" class=\"has-inline-color\">[A4:C1:38:9D:D1:8F]<\/span>[LE]&gt;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u00c0 intervalles r\u00e9guliers de quelques secondes, on voit s&rsquo;ajouter des lignes de \u00ab\u00a0<code>Notification handle<\/code>\u00ab\u00a0. Ce sont les donn\u00e9es de temp\u00e9rature, d&rsquo;hygrom\u00e9trie et de tension de la batterie qui sont envoy\u00e9es par le petit bo\u00eetier.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Mais avant d&rsquo;analyser ces valeures retourn\u00e9es, nous allons regarder s&rsquo;il est possible d&rsquo;obtenir d&rsquo;autres informations sur le Mijia LYWSD03MMC.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Un petit <code>help<\/code> va nous retourner toutes les commandes disponibles :<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[C4:7C:8D:63:85:B1][LE]&gt; help\nhelp                                          Show this help\nexit                                          Exit interactive mode\nquit                                          Exit interactive mode\nconnect [address [address type]]              Connect to a remote device\ndisconnect                                    Disconnect from a remote device\nprimary [UUID]                                Primary Service Discovery\nincluded [start hnd [end hnd]]                Find Included Services\ncharacteristics [start hnd [end hnd [UUID]]]  Characteristics Discovery\nchar-desc [start hnd] [end hnd]               Characteristics Descriptor Discovery\nchar-read-hnd &lt;handle&gt;                        Characteristics Value\/Descriptor Read by handle\nchar-read-uuid &lt;UUID&gt; [start hnd] [end hnd]   Characteristics Value\/Descriptor Read by UUID\nchar-write-req &lt;handle&gt; &lt;new value&gt;           Characteristic Value Write (Write Request)\nchar-write-cmd &lt;handle&gt; &lt;new value&gt;           Characteristic Value Write (No response)\nsec-level [low | medium | high]               Set security level. Default: low\nmtu &lt;value&gt;                                   Exchange MTU for GATT\/ATT<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">La commande <code>primary<\/code> va explorer les <em>handles <\/em>des services primaires :<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[A4:C1:38:9D:D1:8F][LE]&gt; primary\nattr handle: 0x0001, end grp handle: 0x0007 uuid: 00001800-0000-1000-8000-00805f9b34fb\nattr handle: 0x0008, end grp handle: 0x000b uuid: 00001801-0000-1000-8000-00805f9b34fb\nattr handle: 0x000c, end grp handle: 0x0018 uuid: 0000180a-0000-1000-8000-00805f9b34fb\nattr handle: 0x0019, end grp handle: 0x001c uuid: 0000180f-0000-1000-8000-00805f9b34fb\nattr handle: 0x001d, end grp handle: 0x0020 uuid: 00010203-0405-0607-0809-0a0b0c0d1912\nattr handle: 0x0021, end grp handle: 0x004b uuid: ebe0ccb0-7a0a-4b0c-8a1a-6ff2997da3a6\nattr handle: 0x004c, end grp handle: 0x005f uuid: 0000fe95-0000-1000-8000-00805f9b34fb\nattr handle: 0x0060, end grp handle: 0x0068 uuid: 00000100-0065-6c62-2e74-6f696d2e696d<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">La commande <code>char-desc<\/code> va explorer les descripteurs de caract\u00e9ristiques et nous retourner tous les <code>handle<\/code> disponibles avec leurs num\u00e9ros et leurs uuid :<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[A4:C1:38:9D:D1:8F][LE]&gt; char-desc\nhandle: 0x0001, uuid: 00002800-0000-1000-8000-00805f9b34fb\nhandle: 0x0002, uuid: 00002803-0000-1000-8000-00805f9b34fb\nhandle: <span class=\"has-inline-color has-vivid-red-color\">0x0003<\/span>, uuid: 0000<span style=\"background-color:#00d084\" class=\"has-inline-background\">2a00<\/span>-0000-1000-8000-00805f9b34fb\n...\nhandle: <span class=\"has-inline-color has-vivid-red-color\">0x0012<\/span>, uuid: 0000<span style=\"background-color:#00d084\" class=\"has-inline-background\">2a26<\/span>-0000-1000-8000-00805f9b34fb\n...\nhandle: <span class=\"has-inline-color has-vivid-red-color\">0x0014<\/span>, uuid: 0000<span style=\"background-color:#00d084\" class=\"has-inline-background\">2a27<\/span>-0000-1000-8000-00805f9b34fb\n...\nhandle: <span class=\"has-inline-color has-vivid-red-color\">0x001b<\/span>, uuid: 0000<span style=\"background-color:#00d084\" class=\"has-inline-background\">2a19<\/span>-0000-1000-8000-00805f9b34fb\n...\nhandle: 0x0068, uuid: 00002902-0000-1000-8000-00805f9b34fb<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">En comparant certains de ces uuid avec la nomenclature standardis\u00e9e Bluetooth sur ce site <a aria-label=\"https:\/\/www.bluetooth.com (opens in a new tab)\" rel=\"noreferrer noopener\" href=\"https:\/\/www.bluetooth.com\/specifications\/gatt\/characteristics\/\" target=\"_blank\" class=\"ek-link\">https:\/\/www.bluetooth.com<\/a>, nous pouvons en d\u00e9duire ceci :<\/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-08.png\"><img loading=\"lazy\" decoding=\"async\" width=\"620\" height=\"609\" data-attachment-id=\"3964\" data-permalink=\"https:\/\/www.fanjoe.be\/?attachment_id=3964\" data-orig-file=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-08.png\" data-orig-size=\"1110,1090\" data-comments-opened=\"1\" data-image-title=\"gatttool-mijia-08\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-08-620x609.png\" src=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-08-620x609.png\" alt=\"\" class=\"wp-image-3964\" srcset=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-08-620x609.png 620w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-08-300x295.png 300w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-08-175x172.png 175w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-08.png 1110w\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" \/><\/a><figcaption><a href=\"https:\/\/www.bluetooth.com\/specifications\/gatt\/characteristics\/\" target=\"_blank\" aria-label=\"https:\/\/www.bluetooth.com\/ (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"ek-link\">https:\/\/www.bluetooth.com\/<\/a><\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Gr\u00e2ce \u00e0 ce tableau, nous apprenons que :<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>handle 0x0003 : 2A00 =&gt; Device Name<\/li><li>handle 0x0012 : 2A26 =&gt; Firmware Revision String<\/li><li>handle 0x0014 : 2A27 =&gt; Hardware Revision String<\/li><li>handle 0x001b : 2A19 =&gt; Battery Level<\/li><\/ul>\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 <em>handle<\/em>, on utilise la commande <code>char-read-hnd<\/code> suivie du n\u00b0 du <em>handle<\/em> qui nous int\u00e9resse :<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[A4:C1:38:9D:D1:8F][LE]&gt; char-read-hnd 0x0003\nCharacteristic value\/descriptor: 4c 59 57 53 44 30 33 4d 4d 43 00<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">[A4:C1:38:9D:D1:8F][LE]&gt; char-read-hnd 0x0012\nCharacteristic value\/descriptor: 31 2e 30 2e 30 5f 30 31 30 36 00<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">[A4:C1:38:9D:D1:8F][LE]&gt; char-read-hnd 0x0014\nCharacteristic value\/descriptor: 42 31 2e 34<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">[A4:C1:38:9D:D1:8F][LE]&gt; char-read-hnd 0x001b\nCharacteristic value\/descriptor: 63<\/pre>\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=A4:C1:38:9D:D1:8F --char-read -a 0x03<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Et ainsi de suite pour tous les handles \u00e0 lire, en veillant \u00e0 utiliser le num\u00e9ro correspondant \u00e0 la fin ( <code>0x03<\/code> ).<\/p>\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 la temp\u00e9rature et l&rsquo;hygrom\u00e9trie, il n&rsquo;est pas possible de lire directement le handle 36.<\/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=A4:C1:38:9D:D1:8F --char-read -a 0x36\nCharacteristic value\/descriptor: 00 00 00<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Pour obtenir les donn\u00e9es, nous allons inscrire une valeur arbitraire dans le handle 38 qui permet l&rsquo;\u00e9criture et \u00e9couter tout ce qui se passe ensuite ( <code>--listen<\/code> ):<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo gatttool -b A4:C1:38:9D:D1:8F --char-write-req --handle=0x0038 --value=0100 --listen\nCharacteristic value was written successfully\nNotification handle = 0x0036 value: f7 08 2c 05 0c\nNotification handle = 0x0036 value: fa 08 2c 05 0c\nNotification handle = 0x0036 value: f8 08 2c 05 0c\nNotification handle = 0x0036 value: f8 08 2c 05 0c\nNotification handle = 0x0036 value: fa 08 2c 05 0c\n^C<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Une fois la valeur inscrite avec succ\u00e8s, la commande va continuer \u00e0 recevoir les notifications du bo\u00eetier jusqu&rsquo;\u00e0 interruption avec <code>[ctrl] C<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Pour \u00e9viter ce blocage, on va restreindre le temps d&rsquo;ex\u00e9cution \u00e0 15 secondes ( <code>timeout 15<\/code> ) et ne r\u00e9cup\u00e9rer qu&rsquo;une seule ligne des notifications ( <code>grep<\/code> ) :<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo timeout 15 gatttool -b A4:C1:38:9D:D1:8F --char-write-req --handle=0x0038 --value=0100 --listen | grep --max-count=1 \"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 = 0x0036 value: fa 08 2c 05 0c<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">Structure des donn\u00e9es<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\">Table ASCII<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Pour les handle <code>0x0003<\/code>, <code>0x0012<\/code>, <code>0x0014<\/code>, <code>0x001b<\/code>, il suffit d&rsquo;utiliser une table ASCII pour convertir les <code>Hex<\/code> en <code>Char<\/code><\/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.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><figcaption>Wikimedia Foundation<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>0x0003<\/strong> &#8211; <strong><em>Device Name<\/em> :<\/strong> 4c 59 57 53 44 30 33 4d 4d 43<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><tbody><tr><td class=\"has-text-align-center\" data-align=\"center\">4c<\/td><td class=\"has-text-align-center\" data-align=\"center\">59<\/td><td class=\"has-text-align-center\" data-align=\"center\">57<\/td><td class=\"has-text-align-center\" data-align=\"center\">53<\/td><td class=\"has-text-align-center\" data-align=\"center\">44<\/td><td class=\"has-text-align-center\" data-align=\"center\">30<\/td><td class=\"has-text-align-center\" data-align=\"center\">33<\/td><td class=\"has-text-align-center\" data-align=\"center\">4d<\/td><td class=\"has-text-align-center\" data-align=\"center\">4d<\/td><td class=\"has-text-align-center\" data-align=\"center\">43<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">L<\/td><td class=\"has-text-align-center\" data-align=\"center\">Y<\/td><td class=\"has-text-align-center\" data-align=\"center\">W<\/td><td class=\"has-text-align-center\" data-align=\"center\">S<\/td><td class=\"has-text-align-center\" data-align=\"center\">D<\/td><td class=\"has-text-align-center\" data-align=\"center\">0<\/td><td class=\"has-text-align-center\" data-align=\"center\">3<\/td><td class=\"has-text-align-center\" data-align=\"center\">M<\/td><td class=\"has-text-align-center\" data-align=\"center\">M<\/td><td class=\"has-text-align-center\" data-align=\"center\">C<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Il s&rsquo;agit du nom qui appara\u00eet lorsqu&rsquo;on liste les p\u00e9riph\u00e9riques BT avec la commande <code>hcitool lescan<\/code> vue au d\u00e9but.<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>0x0012<\/strong> &#8211; <strong><em>Firmware Revision String<\/em> :<\/strong> 31 2e 30 2e 30 5f 30 31 30 36<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><tbody><tr><td class=\"has-text-align-center\" data-align=\"center\">31<\/td><td class=\"has-text-align-center\" data-align=\"center\">2e<\/td><td class=\"has-text-align-center\" data-align=\"center\">30<\/td><td class=\"has-text-align-center\" data-align=\"center\">2e<\/td><td class=\"has-text-align-center\" data-align=\"center\">30<\/td><td class=\"has-text-align-center\" data-align=\"center\">5f<\/td><td class=\"has-text-align-center\" data-align=\"center\">30<\/td><td class=\"has-text-align-center\" data-align=\"center\">31<\/td><td class=\"has-text-align-center\" data-align=\"center\">30<\/td><td class=\"has-text-align-center\" data-align=\"center\">36<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">1<\/td><td class=\"has-text-align-center\" data-align=\"center\">.<\/td><td class=\"has-text-align-center\" data-align=\"center\">0<\/td><td class=\"has-text-align-center\" data-align=\"center\">.<\/td><td class=\"has-text-align-center\" data-align=\"center\">0<\/td><td class=\"has-text-align-center\" data-align=\"center\">_<\/td><td class=\"has-text-align-center\" data-align=\"center\">0<\/td><td class=\"has-text-align-center\" data-align=\"center\">1<\/td><td class=\"has-text-align-center\" data-align=\"center\">0<\/td><td class=\"has-text-align-center\" data-align=\"center\">6<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>0x0014<\/strong> &#8211; <strong><em>Hardware Revision String<\/em> :<\/strong> 42 31 2e 34<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><tbody><tr><td class=\"has-text-align-center\" data-align=\"center\">42<\/td><td class=\"has-text-align-center\" data-align=\"center\">31<\/td><td class=\"has-text-align-center\" data-align=\"center\">2e<\/td><td class=\"has-text-align-center\" data-align=\"center\">34<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">B<\/td><td class=\"has-text-align-center\" data-align=\"center\">1<\/td><td class=\"has-text-align-center\" data-align=\"center\">.<\/td><td class=\"has-text-align-center\" data-align=\"center\">4<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">On peut le v\u00e9rifier dans l&rsquo;App <em><strong>Xiaomi Home<\/strong><\/em> :<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"620\" height=\"419\" data-attachment-id=\"3969\" data-permalink=\"https:\/\/www.fanjoe.be\/?attachment_id=3969\" data-orig-file=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-10.png\" data-orig-size=\"828,560\" data-comments-opened=\"1\" data-image-title=\"gatttool-mijia-10\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-10-620x419.png\" src=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-10-620x419.png\" alt=\"\" class=\"wp-image-3969\" srcset=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-10-620x419.png 620w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-10-300x203.png 300w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-10-175x118.png 175w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-10.png 828w\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" \/><\/figure>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>0x001b<\/strong> &#8211; <strong><em>Battery Level<\/em> :<\/strong> 63<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><tbody><tr><td class=\"has-text-align-center\" data-align=\"center\">63<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">99<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Ici, on va prendre la valeur d\u00e9cimale de celle en hexad\u00e9cimale : <code>63<\/code>. C&rsquo;est un pourcentage.<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><em>Little endian<\/em><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Dans le handle de notification 0x0036, lorsque les nombres entiers sont cod\u00e9s sur plusieurs octets, il sont pr\u00e9sent\u00e9s en <em>Little endian<\/em>. C.-\u00e0-d. avec l\u2019octet de poids le plus faible en premier.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Pour comprendre la repr\u00e9sentation des nombres entiers sur plusieurs octets, vous pouvez consulter cette page Wikipedia : <a rel=\"noreferrer noopener\" href=\"https:\/\/fr.wikipedia.org\/wiki\/Endianness\" target=\"_blank\">https:\/\/fr.wikipedia.org\/wiki\/Endianness<\/a><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Notification handle = 0x0036 value: <span class=\"has-inline-color has-vivid-red-color\">fa 08<\/span> <span class=\"has-inline-color has-vivid-green-cyan-color\">2c<\/span> <span class=\"has-inline-color has-vivid-cyan-blue-color\">05<\/span> <span class=\"has-inline-color has-vivid-cyan-blue-color\">0c<\/span><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\n<table id=\"tablepress-7\" class=\"tablepress tablepress-id-7 tbody-has-connected-cells\">\n<tbody>\n<tr class=\"row-1\">\n\t<td class=\"column-1\">fa<\/td><td class=\"column-2\">08<\/td><td class=\"column-3\">2c<\/td><td class=\"column-4\">05<\/td><td class=\"column-5\">0c<\/td>\n<\/tr>\n<tr class=\"row-2\">\n\t<td colspan=\"2\" class=\"column-1\">2298<\/td><td class=\"column-3\">44<\/td><td colspan=\"2\" class=\"column-4\">3077<\/td>\n<\/tr>\n<tr class=\"row-3\">\n\t<td colspan=\"2\" class=\"column-1\">Temp\u00e9rature * 100 (\u00b0C)<\/td><td class=\"column-3\">Hygrom\u00e9trie (%)<\/td><td colspan=\"2\" class=\"column-4\">Tension de batterie * 1000 (Volts)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<!-- #tablepress-7 from cache --><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Bytes 1 &amp; 2 : Temp\u00e9rature : Hex <span class=\"has-inline-color has-vivid-red-color\">08 fa<\/span> : 2298 = 22,98 \u00b0C<\/li><\/ul>\n\n\n\n<p class=\"has-ek-indent wp-block-paragraph\" style=\"--ek-indent:60px\"><strong>Attention !<\/strong><br>Lorsque la temp\u00e9rature est n\u00e9gative, les 2 premiers bytes affichent :<br>FF FF pour -0.1 \u00b0C \/ F6 FF pour -1.0 \u00b0C \/ 9C FF pour -10.0 \u00b0C<br>Soit la formule : Temp\u00e9rature = -65536 + Temp\u00e9rature<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Byte 3 : Hygrom\u00e9trie : Hex <span class=\"has-inline-color has-vivid-green-cyan-color\">2c<\/span> : 44 = 44 %<\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li>Bytes 4 et 5 : Tension de la batterie en Volts : Hex <span class=\"has-inline-color has-vivid-cyan-blue-color\">0c 05<\/span> : 3077 = 3,077 V<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Concernant le niveau de la batterie, voici ce qu&rsquo;indique <strong><em>jaggil<\/em><\/strong> sur le forum GitHub : <a href=\"https:\/\/github.com\/JsBergbau\/MiTemperature2\/issues\/1\" target=\"_blank\" aria-label=\"https:\/\/github.com\/JsBergbau\/MiTemperature2\/issues\/1 (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"ek-link\">https:\/\/github.com\/JsBergbau\/MiTemperature2\/issues\/1<\/a><\/p>\n\n\n\n<blockquote class=\"wp-block-quote has-ek-indent is-layout-flow wp-block-quote-is-layout-flow\" style=\"--ek-indent:20px\"><p>Dans mes tests de batterie, j&rsquo;ai utilis\u00e9 une alimentation \u00e9lectrique r\u00e9glable, et le r\u00e9sum\u00e9 est le suivant :<\/p><p>1. La plage de fonctionnement est comprise entre 2,1v et 3v.<\/p><p>2. Lorsque 2,1 v est atteint, l&rsquo;ic\u00f4ne de la batterie vide est activ\u00e9e sur l&rsquo;\u00e9cran LCD.<\/p><p>3. Lorsqu&rsquo;il atteint 2,09v, le capteur s&rsquo;\u00e9teint.<\/p><p>Ma conclusion est que la plage de 0 \u00e0 100% de la batterie correspond \u00e0 2,1v \u00e0 3v<\/p><cite><a href=\"https:\/\/github.com\/JsBergbau\/MiTemperature2\/issues\/1\" target=\"_blank\" aria-label=\"https:\/\/github.com\/JsBergbau\/MiTemperature2\/issues\/1 (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"ek-link\">https:\/\/github.com\/JsBergbau\/MiTemperature2\/issues\/1<\/a><\/cite><\/blockquote>\n\n\n\n<h1 class=\"wp-block-heading\">Script<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\">En ligne de commande<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><span style=\"text-decoration: underline;\">Update 24\/10\/2020&nbsp;:<\/span><\/strong><br>Mise \u00e0 jour du script suite au commentaire de David Auvr\u00e9 afin d&rsquo;\u00e9viter l&rsquo;erreur : \u00ab\u00a0linux avertissement : substitution de commande: octet nul ignor\u00e9 en entr\u00e9e\u00a0\u00bb.<br>Lignes 52, 60 et 68.<\/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;A4:C1:38:9D:D1:8F&quot;\n\n\nhciconfig hci0 down\nhciconfig hci0 up\n\nhnd38=$(timeout 15 gatttool -b $MACadd --char-write-req --handle=&#039;0x0038&#039; --value=&quot;0100&quot; --listen | grep --max-count=1 &quot;Notification handle&quot;)\n# Notification handle = 0x0036 value: 7c 08 2a 97 0c\n\n\nif !(&#x5B; -z &quot;$hnd38&quot; ])\nthen\n\n\ttemperature=${hnd38:39:2}${hnd38:36:2}\n\ttemperature=$((16#$temperature))\n\tif &#x5B; &quot;$temperature&quot; -gt &quot;10000&quot; ];\n\tthen\n\t\ttemperature=$((-65536 + $temperature))\n\tfi\t\n\ttemperature=$(echo &quot;scale=2;$temperature\/100&quot; | bc)\n\n\thumidity=${hnd38:42:2}\n\thumidity=$((16#$humidity))\n\n\tvoltage=${hnd38:48:2}${hnd38:45:2}\n\tvoltage=$((16#$voltage))\n\tvoltage=$(echo &quot;scale=3;$voltage\/1000&quot; | bc)\n\n\n\t# Battery Level : 0x2A19\n\t# handle = 0x001b, uuid = 00002a19-0000-1000-8000-00805f9b34fb\n\n\t\thnd1b=$(gatttool --device=$MACadd --char-read -a 0x1b)\n\t\t# Characteristic value\/descriptor: 63\n\t\tbattery=${hnd1b:33:2}\n\t\tbattery=$((16#$battery))\n\n\t# Firmware Revision String : 0x2A26\n\t# handle = 0x0012, uuid = 00002a26-0000-1000-8000-00805f9b34fb\n\n\t\thnd12=$(gatttool --device=$MACadd --char-read -a 0x12)\n\t\t# Characteristic value\/descriptor: 31 2e 30 2e 30 5f 30 31 30 36 00\n\t\tfirmware=$(echo &quot;&#039;$hnd12&#039;&quot; | cut -c34-65 | xxd -r -p)\n\n\n\t# Device Name : 0x2A00\n\t# handle = 0x0003, uuid = 00002a00-0000-1000-8000-00805f9b34fb\n\n\t\thnd03=$(gatttool --device=$MACadd --char-read -a 0x03)\n\t\t# Characteristic value\/descriptor: 4c 59 57 53 44 30 33 4d 4d 43 00\n\t\tname=$(echo &quot;&#039;$hnd03&#039;&quot; | cut -c34-65 | xxd -r -p)\n\n\n\t# Hardware Revision String : 0x2A27\n\t# handle = 0x0014, uuid = 00002a27-0000-1000-8000-00805f9b34fb\n\n\t\thnd14=$(gatttool --device=$MACadd --char-read -a 0x14)\n\t\t# Characteristic value\/descriptor: 42 31 2e 34\n\t\trevision=$(echo &quot;&#039;$hnd14&#039;&quot; | cut -c34-45 | xxd -r -p)\n\n\t# Affichage des donn\u00e9es\n\n\t\techo &quot;Reading Mijia...&quot;\n\t\techo &quot;Hardware: {Firmware Version:$firmware \/ Hardware Revision:$revision \/ BT Name:$name \/ Battery Level:$battery}&quot;\n\t\techo &quot;Sensors: {Temperature:$temperature \/ Humidity:$humidity \/ Voltage:$voltage}&quot;\n\nelse\n\n\techo &quot;Mijia error&quot;\n\nfi\n\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Voici ce que ce script devrait retourner :<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Reading Mijia\u2026\nHardware: {Firmware Version:1.0.0_0106 \/ Hardware Revision:B1.4 \/ BT Name:LYWSD03MMC \/ Battery Level:99}\nSensors: {Temperature:22.00 \/ Humidity:47 \/ Voltage:3.060}<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Domoticz<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><span style=\"text-decoration: underline;\" class=\"ek-underline\">\u00c9dit\u00e9 le 07 juillet 2020 :<\/span><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u00c0 la demande d&rsquo;un lecteur de ce blog, j&rsquo;ai demand\u00e9 \u00e0 Pierre, qui a indiqu\u00e9 dans les commentaires avoir adapt\u00e9 ce script \u00e0 Domoticz, de me l&rsquo;envoyer pour le publier ci-dessous.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Le voici tel qu&rsquo;il me l&rsquo;a transmis :<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n#!\/bin\/bash\n#chcp 65001 &gt; nul\n# r\u00e9cup\u00e9ration de la date et l&#039;heure du jour ; on obtient ici une valeur telle que &quot;mercredi 31 d\u00e9cembre 2014, 00:15:01&quot;\nDATE=`date +&quot;%A %d %B %Y, %H:%M:%S&quot;`\n \n# r\u00e9cup\u00e9ration de la date et l&#039;heure du jour sous un autre format ; on obtient ici un r\u00e9sultat sous la forme suivante : XX-YY-ZZZZ (ex: 31-12-2014)\nDATE2=`date +&quot;%d-%m-%Y&quot;`\n \n# d\u00e9finition du chemin du r\u00e9pertoire \u00e0 cr\u00e9er ; ce chemin sera \/home\/pi\/Script\/Capteur_Salon\/\nREP=\/home\/pi\/Script\/Capteur_Salon\/\n \n# d\u00e9finition du chemin du r\u00e9pertoire \u00e0 cr\u00e9er ; ce chemin sera \/media\/Capteur_Salon\/XX-YY-ZZ\nREP1=$REP\/$DATE2\n \n# le fichier \u00e0 cr\u00e9er dans ce r\u00e9pertoire est &quot;Capteur_Salon_??_??_????&quot;\nFICHIER=$REP1\/Capteur_Salon_$DATE2.xlsx\n \n# Si le REP n&#039;existe pas on le cr\u00e9e\nif &#x5B; ! -d $REP ];then\nmkdir $REP\nfi\n \n# Si le REP1 n&#039;existe pas on le cr\u00e9e\nif &#x5B; ! -d $REP1 ];then\nmkdir $REP1\nfi\n \n# Si le fichier n&#039;existe pas on le cr\u00e9e et on y injecte le l&#039;ent\u00eate\nif &#x5B; ! -f $FICHIER ];then\ntouch $FICHIER\n# echo &quot;Mode Date Heure temperature temperature_haute&quot; &gt; $FICHIER\necho &quot;Date Heure temperature Date Heure Humidity Date Heure voltage&quot; &gt; $FICHIER\nfi\n\ndate=&quot;$(date &quot;+%d-%m-%Y&quot;)&quot;\nheure=&quot;$(date &quot;+%H:%M:%S&quot;)&quot;\n# V\u00e9rifie que l&#039;on est en Root\nif &#x5B;&#x5B; $EUID -ne 0 ]];\nthen\n    echo &quot;Ce script doit \u00eatre ex\u00e9cut\u00e9 avec les privil\u00e8ges administrateur&quot;\n    exit 1\nfi\nMACadd=&quot;A4:C1:38:61:9B:41&quot;\n \nhciconfig hci0 down\nhciconfig hci0 up\nhnd38=$(timeout 15 gatttool -b $MACadd --char-write-req --handle=&#039;0x0038&#039; --value=&quot;0100&quot; --listen | grep --max-count=1 &quot;Notification handle&quot;)\n# Notification handle = 0x0036 value: 7c 08 2a 97 0c\n \nif !(&#x5B; -z &quot;$hnd38&quot; ])\nthen\n    temperature=${hnd38:39:2}${hnd38:36:2}\n    temperature=$((16#$temperature))\n    if &#x5B; &quot;$temperature&quot; -gt &quot;10000&quot; ];\n    then\n        temperature=$((-65536 + $temperature))\n    fi\n    temperature=$(echo &quot;scale=2;$temperature\/100&quot; | bc)\n   \n    humidity=${hnd38:42:2}\n    humidity=$((16#$humidity))\n    voltage=${hnd38:48:2}${hnd38:45:2}\n    voltage=$((16#$voltage))\n    voltage=$(echo &quot;scale=3;$voltage\/1000&quot; | bc)\n   \n    # Battery Level : 0x2A19\n    # handle = 0x001b, uuid = 00002a19-0000-1000-8000-00805f9b34fb\n        hnd1b=$(gatttool --device=$MACadd --char-read -a 0x1b)\n        # Characteristic value\/descriptor: 63\n        battery=${hnd1b:33:2}\n        battery=$((16#$battery))\n    # Firmware Revision String : 0x2A26\n    # handle = 0x0012, uuid = 00002a26-0000-1000-8000-00805f9b34fb\n        hnd12=$(gatttool --device=$MACadd --char-read -a 0x12)\n        # Characteristic value\/descriptor: 31 2e 30 2e 30 5f 30 31 30 36 00\n        firmware=$(echo &quot;$hnd12&quot; | cut -c34-65 | xxd -r -p)\n \n    # Device Name : 0x2A00\n    # handle = 0x0003, uuid = 00002a00-0000-1000-8000-00805f9b34fb\n        hnd03=$(gatttool --device=$MACadd --char-read -a 0x03)\n        # Characteristic value\/descriptor: 4c 59 57 53 44 30 33 4d 4d 43 00\n        name=$(echo &quot;$hnd03&quot; | cut -c34-65 | xxd -r -p)\n \n    # Hardware Revision String : 0x2A27\n    # handle = 0x0014, uuid = 00002a27-0000-1000-8000-00805f9b34fb\n        hnd14=$(gatttool --device=$MACadd --char-read -a 0x14)\n        # Characteristic value\/descriptor: 42 31 2e 34\n        revision=$(echo &quot;$hnd14&quot; | cut -c34-45 | xxd -r -p)\n    # Affichage des donn\u00e9es\n        echo &quot;Reading Mijia...&quot;\n        echo &quot;Hardware: {Firmware Version:$firmware \/ Hardware Revision:$revision \/ BT Name:$name \/ Battery Level:$battery}&quot;\n        echo &quot;Sensors: {Temperature:$temperature \/ Humidity:$humidity \/ Voltage:$voltage}&quot;\n        echo &quot;$date $heure $temperature $date $heure $humidity $date $heure $voltage&quot; &gt;&gt; \/home\/pi\/Script\/Capteur_Salon\/$DATE2\/Capteur_Salon_$DATE2.xlsx\n \n#humidity=80\n \nif &#x5B; $humidity -ge 0 ]&amp;&amp;&#x5B; $humidity -le 39 ]\nthen\n         HUM=2\nelif &#x5B; $humidity -ge 60 ]&amp;&amp;&#x5B; $humidity -le 79 ]\nthen\n         HUM=1\nelif &#x5B; $humidity -ge 40 ]&amp;&amp;&#x5B; $humidity -le 59 ]\nthen\n         HUM=0\nelif &#x5B; $humidity -ge 80 ]&amp;&amp;&#x5B; $humidity -le 100 ]\nthen\n         HUM=3\nfi  \n \necho $HUM \n \n#Cr\u00e9ation d&#039;une variable contenant url en y incluant la valeur de la temp\u00e9rature\nurl1=&quot;http:\/\/192.168.1.69:8087\/json.htm?type=command&amp;param=udevice&amp;idx=11&amp;nvalue=0&amp;svalue=$temperature&quot;\nurl2=&quot;http:\/\/192.168.1.69:8087\/json.htm?type=command&amp;param=udevice&amp;idx=11&amp;nvalue=$humidity&quot;\nurl3=&quot;http:\/\/192.168.1.69:8087\/json.htm?type=command&amp;param=udevice&amp;idx=9&amp;svalue=$temperature;$humidity;$HUM&quot;\n \n \n#Requ\u00eate vers domoticz pour mise \u00e0 jour  de la temp\u00e9rature en mode silencieux\ncurl -s  $url1 &gt; \/dev\/null\ncurl -s  $url2 &gt; \/dev\/null\ncurl -s  $url3 &gt; \/dev\/null\n \nelse\n    echo &quot;Mijia error&quot;\nfi\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Grand merci \u00e0 Pierre pour ce partage.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><span style=\"text-decoration: underline;\" class=\"ek-underline\">Edit : 01 octobre 2020 :<\/span><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Suite au commentaire de <strong>fp<\/strong>, la d\u00e9claration de l&rsquo;interpr\u00e9teur a \u00e9t\u00e9 corrig\u00e9e (premi\u00e8re ligne du script de <strong>Pierre<\/strong>) pour r\u00e9soudre le probl\u00e8me de \u00ab\u00a0Bad substitution\u00a0\u00bb. La ligne 35 a \u00e9t\u00e9 supprim\u00e9e car redondante.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><span style=\"text-decoration: underline;\" class=\"ek-underline\">Edit : 24 janvier 2021 :<\/span><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Un lecteur, David Smhosy, a adapt\u00e9 ce script pour remplir une base de donn\u00e9es SQLITE3 : <a href=\"https:\/\/smhosy.blogspot.com\/2021\/01\/quelle-temperature-et-hydrometrie-dans.html\" target=\"_blank\" aria-label=\" (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"ek-link\">https:\/\/smhosy.blogspot.com\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction <\/p>\n<p class=\"wp-block-paragraph\">Depuis quelques temps, j&rsquo;utilise diff\u00e9rents types de capteurs Bluetooth pour effectuer des mesures de temp\u00e9rature, d&rsquo;humidit\u00e9, d&rsquo;\u00e9clairement, de&#8230;<\/p>\n","protected":false},"author":1,"featured_media":3914,"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":[13,287,288,359,358,280],"class_list":["post-3911","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-domotique","category-geek","category-informatique","category-linux","category-raspberrypi","tag-bluetooth","tag-gatttool","tag-hcitool","tag-lywsd03mmc","tag-mijia","tag-xiaomi","end"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2020\/04\/gatttool-mijia-00.png","_links":{"self":[{"href":"https:\/\/www.fanjoe.be\/index.php?rest_route=\/wp\/v2\/posts\/3911","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=3911"}],"version-history":[{"count":0,"href":"https:\/\/www.fanjoe.be\/index.php?rest_route=\/wp\/v2\/posts\/3911\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.fanjoe.be\/index.php?rest_route=\/wp\/v2\/media\/3914"}],"wp:attachment":[{"href":"https:\/\/www.fanjoe.be\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3911"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fanjoe.be\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3911"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fanjoe.be\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3911"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}