{"id":2537,"date":"2017-06-06T00:23:30","date_gmt":"2017-06-05T22:23:30","guid":{"rendered":"https:\/\/www.fanjoe.be\/?p=2537"},"modified":"2018-01-29T21:25:37","modified_gmt":"2018-01-29T20:25:37","slug":"rpi-monitor-importer-les-donnees-depuis-un-capteur-xiaomi-flower-care-miflora-en-bluetooth","status":"publish","type":"post","link":"https:\/\/www.fanjoe.be\/?p=2537","title":{"rendered":"RPi-Monitor : Importer les donn\u00e9es depuis un capteur Xiaomi Flower Care \/ MiFlora en Bluetooth"},"content":{"rendered":"<h1>Introduction<\/h1>\n<p>Il y a quelques jours, j&rsquo;ai publi\u00e9 un article qui expliquait comment <a href=\"https:\/\/www.fanjoe.be\/?p=2454\" target=\"_blank\" rel=\"noopener noreferrer\">importer les donn\u00e9es d&rsquo;un capteur Xiaomi Flower Care \/ MiFlora en Bluetooth<\/a> sur un Raspberry Pi. Ce capteur est disponible pour un peu plus de 20\u20ac sur <a href=\"http:\/\/amzn.to\/2EW3CwC\" target=\"_blank\" rel=\"noopener\">Amazon<\/a>.<\/p>\n<p>Nous allons voir comment utiliser ces donn\u00e9es dans <a href=\"https:\/\/github.com\/XavierBerger\/RPi-Monitor\" target=\"_blank\" rel=\"noopener noreferrer\">RPi-Monitor<\/a>.<\/p>\n<h1>Importer les donn\u00e9es dans RPi-Monitor<\/h1>\n<h2>Rapatrier les donn\u00e9es<\/h2>\n<p>Tout d&rsquo;abord, nous allons appliquer tout ce qui est indiqu\u00e9 dans cet article :<\/p>\n<p><a href=\"https:\/\/www.fanjoe.be\/?p=2454\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/www.fanjoe.be\/?p=2454<\/a><\/p>\n<p>Nous devrions avoir une App ex\u00e9cutable nomm\u00e9e \u00ab\u00a0miflora\u00a0\u00bb dans le dossier <code>\/home\/pi\/scripts\/miflora\/<\/code><\/p>\n<p>Nous allons nous placer dans ce dossier :<\/p>\n<pre>$ cd \/home\/pi\/scripts\/miflora\/<\/pre>\n<p>Et ex\u00e9cuter la commande (<code>C4:7C:8D:<span style=\"color: #ff0000;\">XX:XX:XX<\/span><\/code> \u00e9tant la Mac Address du Flower Care) :<\/p>\n<pre>$ .\/miflora C4:7C:8D:<span style=\"color: #ff0000;\">XX:XX:XX<\/span> hci0 &gt; data.txt<\/pre>\n<p>Nous obtiendrons un fichier <code>data.txt<\/code> contenant quelque chose comme \u00e7a :<\/p>\n<pre>Reading miflora...\r\nFirmware: {Version:2.7.0 Battery:100}\r\nSensors: {Temperature:20.3 Moisture:35 Light:14 Conductivity:411}<\/pre>\n<h2>Fichier de configuration RPi-Monitor<\/h2>\n<p>On va cr\u00e9er un fichier <code>miflora.conf<\/code> dans le dossier <code>\/etc\/rpimonitor\/template<\/code><\/p>\n<pre>$ sudo nano \/etc\/rpimonitor\/template\/miflora.conf<\/pre>\n<p>Et on va y copier ceci :<\/p>\n<pre>########################################################################\r\n# Extract temperature and humidity from Xiaomi miflora\r\n# Page: 2\r\n# Information Status Statistics\r\n# - tempetature    - yes - yes\r\n# - moisture       - yes - yes\r\n# - light          - yes - yes\r\n# - conductivity   - yes - yes\r\n# - battery        - yes - yes\r\n#######################################################################\r\n# Add new pages (number 2)\r\nweb.status.2.name=Plantes\r\nweb.statistics.2.name=Plantes\r\n \r\n# Get dynamic data\r\ndynamic.1.name=miflora_temp\r\ndynamic.1.source=\/home\/pi\/scripts\/miflora\/data.txt\r\ndynamic.1.regexp=Temperature:(\\S+)\r\ndynamic.1.rrd=GAUGE\r\n\r\ndynamic.2.name=miflora_moisture\r\ndynamic.2.source=\/home\/pi\/scripts\/miflora\/data.txt\r\ndynamic.2.regexp=Moisture:(\\S+)\r\ndynamic.2.rrd=GAUGE\r\n\r\ndynamic.3.name=miflora_light\r\ndynamic.3.source=\/home\/pi\/scripts\/miflora\/data.txt\r\ndynamic.3.regexp=Light:(\\S+)\r\ndynamic.3.rrd=GAUGE\r\n\r\ndynamic.4.name=miflora_conduct\r\ndynamic.4.source=\/home\/pi\/scripts\/miflora\/data.txt\r\ndynamic.4.regexp=Conductivity:(\\d+)\r\ndynamic.4.rrd=GAUGE\r\n\r\ndynamic.5.name=miflora_battery\r\ndynamic.5.source=\/home\/pi\/scripts\/miflora\/data.txt\r\ndynamic.5.regexp=Battery:(\\d+)\r\ndynamic.5.rrd=GAUGE\r\n\r\n\r\n# Add a line of status in page number 3\r\nweb.status.2.content.1.name=Flower Care\r\nweb.status.2.content.1.icon=miflora.png\r\nweb.status.2.content.1.line.1=\"Temp\u00e9rature Ambiante : &lt;b&gt;\"+data.miflora_temp+\"&amp;deg;C&lt;\/b&gt;\"\r\nweb.status.2.content.1.line.2=\"Ensoleillement : &lt;b&gt;\"+data.miflora_light+\" lux&lt;\/b&gt;\"\r\nweb.status.2.content.1.line.3=\"Humidit\u00e9 du sol : &lt;b&gt;\"+data.miflora_moisture+\" %&lt;\/b&gt;\"\r\nweb.status.2.content.1.line.4=ProgressBar(data.miflora_moisture,100)\r\nweb.status.2.content.1.line.5=\"Engrais : &lt;b&gt;\"+data.miflora_conduct+\" uS\/cm&lt;\/b&gt;\"\r\nweb.status.2.content.1.line.6=ProgressBar(data.miflora_conduct,1500)\r\nweb.status.2.content.1.line.7=\"Batterie : &lt;b&gt;\"+data.miflora_battery+\" %&lt;\/b&gt;\"\r\nweb.status.2.content.1.line.8=ProgressBar(data.miflora_battery,100)\r\n\r\n\r\n# Add a statistic graph in page number 3\r\nweb.statistics.2.content.1.name=Temp\u00e9rature\r\nweb.statistics.2.content.1.graph.1=miflora_temp\r\nweb.statistics.2.content.1.ds_graph_options.miflora_temp.label=Temp\u00e9rature ambiante (deg C)\r\nweb.statistics.2.content.1.graph_options.y2axis={ position: \"right\", min: 0, max: 40 }\r\n\r\nweb.statistics.2.content.2.name=Humidit\u00e9\r\nweb.statistics.2.content.2.graph.1=miflora_moisture\r\nweb.statistics.2.content.2.ds_graph_options.miflora_moisture.label=Humidit\u00e9 du sol (%)\r\nweb.statistics.2.content.2.graph_options.y2axis={ position: \"right\", min: 0, max: 100 }\r\n\r\nweb.statistics.2.content.3.name=Ensoleillement\r\nweb.statistics.2.content.3.graph.1=miflora_light\r\nweb.statistics.2.content.3.ds_graph_options.miflora_light.label=Ensoleillement (lux)\r\nweb.statistics.2.content.3.graph_options.y2axis={ position: \"right\", min: 0, max: 3000 }\r\n\r\nweb.statistics.2.content.4.name=Engrais\r\nweb.statistics.2.content.4.graph.1=miflora_conduct\r\nweb.statistics.2.content.4.ds_graph_options.miflora_conduct.label=Engrais (uS\/cm)\r\nweb.statistics.2.content.4.graph_options.y2axis={ position: \"right\", min: 0, max: 2000 }\r\n\r\nweb.statistics.2.content.5.name=Batterie\r\nweb.statistics.2.content.5.graph.1=miflora_battery\r\nweb.statistics.2.content.5.ds_graph_options.miflora_battery.label=Batterie (%)\r\nweb.statistics.2.content.5.graph_options.y2axis={ position: \"right\", min: 0, max: 100 }<\/pre>\n<p>On quitte nano en enregistrant.<\/p>\n<p>Vous pouvez \u00e9galement t\u00e9l\u00e9charger directement le fichier <a href=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2017\/06\/miflora.conf\" target=\"_blank\" rel=\"noopener noreferrer\">miflora.conf<\/a><\/p>\n<p>On attribue les droits du fichier qui vont bien :<\/p>\n<pre>$ sudo chmod 664 \/etc\/rpimonitor\/template\/miflora.conf<\/pre>\n<p>On utilise une ic\u00f4ne <code>miflora.png<\/code> qui n&rsquo;est pas pr\u00e9sente par d\u00e9faut dans RPi-Monitor.<\/p>\n<p><a href=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2017\/06\/miflora.png\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2541\" data-permalink=\"https:\/\/www.fanjoe.be\/?attachment_id=2541\" data-orig-file=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2017\/06\/miflora.png\" data-orig-size=\"64,64\" data-comments-opened=\"1\" data-image-title=\"miflora\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2017\/06\/miflora.png\" class=\"alignnone size-full wp-image-2541\" src=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2017\/06\/miflora.png\" alt=\"\" width=\"64\" height=\"64\" \/><\/a><\/p>\n<p>On va la copier dans le dossier <code>\/usr\/share\/rpimonitor\/web\/img<\/code> avec un utilitaire comme <a href=\"https:\/\/cyberduck.io\/\" target=\"_blank\" rel=\"noopener noreferrer\">CyberDuck<\/a> et y appliquer les droits corrects :<\/p>\n<pre>$ sudo chmod 664 \/usr\/share\/rpimonitor\/web\/img\/miflora.png<\/pre>\n<p>Pour terminer, on va \u00e9diter le fichier data.conf (c&rsquo;est un raccourci) :<\/p>\n<pre>$ sudo nano \/etc\/rpimonitor\/data.conf<\/pre>\n<p>Et y ajouter cette ligne tout \u00e0 la fin :<\/p>\n<pre>include=\/etc\/rpimonitor\/template\/miflora.conf<\/pre>\n<p>Et pour terminer, on red\u00e9marre RPi-Monitor :<\/p>\n<pre>$ sudo service rpimonitor restart<\/pre>\n<h2>Automatiser le relev\u00e9 du capteur<\/h2>\n<p>Si on s&rsquo;arr\u00eate ici, les donn\u00e9es affich\u00e9es dans RPi-Monitor seraient celle qui ont \u00e9t\u00e9 relev\u00e9es une seule fois manuellement avec la commande <code>$ .\/miflora C4:7C:8D:<span style=\"color: #ff0000;\">XX:XX:XX<\/span> hci0 &gt; data.txt<\/code> vue au d\u00e9but de cet article.<\/p>\n<p>On va automatiser ce relev\u00e9 avec un <code>Cron<\/code> toutes les minutes :<\/p>\n<pre>$ sudo crontab -e<\/pre>\n<p>Et on ajoute cette ligne \u00e0 la fin du fichier (attention \u00e0 bien remplacer les <span style=\"color: #ff0000;\"><code>XX<\/code><\/span> de la Mac Address) :<\/p>\n<pre># Boucle pour actualiser les donn\u00e9es RPi-Monitor avec le Xiaomi Flower Care (miflora)\r\n*\/1 * * * * sudo \/home\/pi\/scripts\/miflora\/miflora C4:7C:8D:<span style=\"color: #ff0000;\">XX:XX:XX<\/span> hci0 &gt; \/home\/pi\/scripts\/miflora\/data.txt 2&gt;&amp;1<\/pre>\n<p>Et on quitte en vauvegardant.<\/p>\n<p>Dor\u00e9navant, les donn\u00e9es seront lues toutes les minutes et vous pourrez voir le Flower Care s&rsquo;allumer durant l&rsquo;op\u00e9ration.<\/p>\n<h1>R\u00e9sultat<\/h1>\n<p>Vous devriez voir les valeurs import\u00e9es et le graphique se dessiner au fur et \u00e0 mesure du temps :<\/p>\n<p><a href=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2017\/06\/FlowerCare-RPiMonitor-02.png\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2544\" data-permalink=\"https:\/\/www.fanjoe.be\/?attachment_id=2544\" data-orig-file=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2017\/06\/FlowerCare-RPiMonitor-02.png\" data-orig-size=\"929,682\" data-comments-opened=\"1\" data-image-title=\"FlowerCare-RPiMonitor-02\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2017\/06\/FlowerCare-RPiMonitor-02-620x455.png\" class=\"alignnone wp-image-2544 size-large\" src=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2017\/06\/FlowerCare-RPiMonitor-02-620x455.png\" alt=\"\" width=\"620\" height=\"455\" srcset=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2017\/06\/FlowerCare-RPiMonitor-02-620x455.png 620w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2017\/06\/FlowerCare-RPiMonitor-02-175x128.png 175w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2017\/06\/FlowerCare-RPiMonitor-02-300x220.png 300w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2017\/06\/FlowerCare-RPiMonitor-02.png 929w\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" \/><\/a><a href=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2017\/06\/FlowerCare-RPiMonitor-01.png\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2543\" data-permalink=\"https:\/\/www.fanjoe.be\/?attachment_id=2543\" data-orig-file=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2017\/06\/FlowerCare-RPiMonitor-01.png\" data-orig-size=\"929,682\" data-comments-opened=\"1\" data-image-title=\"FlowerCare-RPiMonitor-01\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2017\/06\/FlowerCare-RPiMonitor-01-620x455.png\" class=\"alignnone size-large wp-image-2543\" src=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2017\/06\/FlowerCare-RPiMonitor-01-620x455.png\" alt=\"\" width=\"620\" height=\"455\" srcset=\"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2017\/06\/FlowerCare-RPiMonitor-01-620x455.png 620w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2017\/06\/FlowerCare-RPiMonitor-01-175x128.png 175w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2017\/06\/FlowerCare-RPiMonitor-01-300x220.png 300w, https:\/\/www.fanjoe.be\/wp-content\/uploads\/2017\/06\/FlowerCare-RPiMonitor-01.png 929w\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction <\/p>\n<p>Il y a quelques jours, j&rsquo;ai publi\u00e9 un article qui expliquait comment <a href=\"https:\/\/www.fanjoe.be\/?p=2454\" target=\"_blank\" rel=\"noopener noreferrer\">importer les donn\u00e9es&#8230;<\/p>\n","protected":false},"author":1,"featured_media":2540,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","jetpack_post_was_ever_published":false},"categories":[179,10,3,12],"tags":[13,17,279,281,16,22,282,280],"class_list":["post-2537","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-domotique","category-geek","category-informatique","category-raspberrypi","tag-bluetooth","tag-domotique","tag-flower-care","tag-miflora","tag-plantes","tag-raspberry-pi","tag-rpi-monitor","tag-xiaomi","end"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/www.fanjoe.be\/wp-content\/uploads\/2017\/06\/FlowerCare-RPiMonitor-00.jpg","_links":{"self":[{"href":"https:\/\/www.fanjoe.be\/index.php?rest_route=\/wp\/v2\/posts\/2537","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=2537"}],"version-history":[{"count":0,"href":"https:\/\/www.fanjoe.be\/index.php?rest_route=\/wp\/v2\/posts\/2537\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.fanjoe.be\/index.php?rest_route=\/wp\/v2\/media\/2540"}],"wp:attachment":[{"href":"https:\/\/www.fanjoe.be\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2537"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fanjoe.be\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2537"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fanjoe.be\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2537"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}