{"id":58,"date":"2021-06-25T09:34:48","date_gmt":"2021-06-25T07:34:48","guid":{"rendered":"https:\/\/www.servo-server.net\/?p=58"},"modified":"2021-06-28T08:10:42","modified_gmt":"2021-06-28T06:10:42","slug":"mi-band-steps-on-node-red-dashboard","status":"publish","type":"post","link":"https:\/\/www.servo-server.net\/?p=58","title":{"rendered":"Mi-Band steps on node-RED Dashboard"},"content":{"rendered":"\n<p>Mi-Band 5<br>Smartphone: Nokia 5.3<br>OS on smartphone: Android 10<br>Apps on smartphone required: Gadgetbridge, FolderSync<br>Server: Raspberry Pi 4<br>OS: Raspbian GNU\/Linux 10 (buster)<br>ioBroker: 4.0.10<br>node-red Adapter: 2.3.0<br>node-red version: 1.3.5<\/p>\n\n\n\n<p>The idea was to display the steps recorded by the Mi-Band 5 on the node-RED Dashboard. The Mi-Band comes with a closed source App for the Smartphone that cant export data. Step one is to find an alternative to it. The App being used is <a href=\"https:\/\/gadgetbridge.org\/\">gadgetbridge<\/a> for Android. The App is not available on the PlayStore. To install it requires either the <a href=\"https:\/\/f-droid.org\/\">F-Droid <\/a>&#8220;store&#8221; or it can be installed using the apk.<\/p>\n\n\n\n<p>Step 2 to get the MiBand connected to the gadgetbridge requires a bit of effort, but is well documented <a href=\"https:\/\/codeberg.org\/Freeyourgadget\/Gadgetbridge\/wiki\/Huami-Server-Pairing\" data-type=\"URL\" data-id=\"https:\/\/codeberg.org\/Freeyourgadget\/Gadgetbridge\/wiki\/Huami-Server-Pairing\">here<\/a>. This is essential to move on.<\/p>\n\n\n\n<p>The result will be, that the MiBand is now connected to the gadgetbridge App.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"461\" height=\"1024\" src=\"https:\/\/www.servo-server.net\/wp-content\/uploads\/2021\/06\/Screenshot_20210625-082722-461x1024.png\" alt=\"\" class=\"wp-image-60\" srcset=\"https:\/\/www.servo-server.net\/wp-content\/uploads\/2021\/06\/Screenshot_20210625-082722-461x1024.png 461w, https:\/\/www.servo-server.net\/wp-content\/uploads\/2021\/06\/Screenshot_20210625-082722-135x300.png 135w, https:\/\/www.servo-server.net\/wp-content\/uploads\/2021\/06\/Screenshot_20210625-082722-691x1536.png 691w, https:\/\/www.servo-server.net\/wp-content\/uploads\/2021\/06\/Screenshot_20210625-082722.png 720w\" sizes=\"auto, (max-width: 461px) 100vw, 461px\" \/><\/figure>\n\n\n\n<p><br><\/p>\n\n\n\n<p>2 settings on the gadgetbridge app are required:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Auto fetch activity data including a setting of the Minimum time between fetches<\/li><li>Auto export enabled including an export location and the &#8220;Export interval&#8221;<\/li><\/ol>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"461\" height=\"1024\" src=\"https:\/\/www.servo-server.net\/wp-content\/uploads\/2021\/06\/Screenshot_20210625-082809-461x1024.png\" alt=\"\" class=\"wp-image-61\" srcset=\"https:\/\/www.servo-server.net\/wp-content\/uploads\/2021\/06\/Screenshot_20210625-082809-461x1024.png 461w, https:\/\/www.servo-server.net\/wp-content\/uploads\/2021\/06\/Screenshot_20210625-082809-135x300.png 135w, https:\/\/www.servo-server.net\/wp-content\/uploads\/2021\/06\/Screenshot_20210625-082809-691x1536.png 691w, https:\/\/www.servo-server.net\/wp-content\/uploads\/2021\/06\/Screenshot_20210625-082809.png 720w\" sizes=\"auto, (max-width: 461px) 100vw, 461px\" \/><\/figure>\n\n\n\n<p>This set in motion will fetch the data from the device, and export to a sqlite Database.<\/p>\n\n\n\n<p>Using the folder-sync app for Android the Database file can be copied over to a local PC\/Server in regular intervals.<\/p>\n\n\n\n<p>The initial idea was to use the sqlite Database file directly via a sqlite node on Node-RED. This failed due to the fact that the DB-file name never changes and Node-RED always uses the inital version of the DB-file.<\/p>\n\n\n\n<p>Plan B required to first of all export the Data on the database to a csv file.<\/p>\n\n\n\n<p>To do this an SQL-statement needs to be stored and excecuted on a regular basis. This sql code was stored in a file called steps_q.sql. It gets the steps recorded for the last 7 days.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SELECT  \nDatum \n,sum(schritte) as Schritte  \nFROM  \n(  \nSELECT  \n\n\ndate(MB.TIMESTAMP, 'unixepoch') as Datum \n,sum(MB.STEPS) as Schritte  \n\nfrom  MI_BAND_ACTIVITY_SAMPLE MB\n\ngroup by MB.TIMESTAMP   \n\n) \n\ngroup by Datum  \norder by Datum DESC  \nLIMIT 7<\/pre>\n\n\n\n<p> To export this to a csv file the following sqlite3 statement can be used:<\/p>\n\n\n\n<p>sqlite3 -header -csv \/mnt\/1TBTOSHIBA\/files\/transfer\/miband\/db &lt; \/mnt\/1TBTOSHIBA\/files\/transfer\/miband\/steps_q.sql &gt; \/mnt\/1TBTOSHIBA\/files\/transfer\/miband\/steps.csv<\/p>\n\n\n\n<p>sqlite3 -header -csv is the command<br>\/mnt\/1TBTOSHIBA\/files\/transfer\/miband\/db is the sqlite Database<br>&lt; \/mnt\/1TBTOSHIBA\/files\/transfer\/miband\/steps_q.sql is the SQL code stored in a file<br>&gt;\/mnt\/1TBTOSHIBA\/files\/transfer\/miband\/steps.csv is the destination csv-file<\/p>\n\n\n\n<p>The excecution of this file was set up as a cron job:<\/p>\n\n\n\n<p>45 * * * * pi sqlite3 -header -csv \/mnt\/1TBTOSHIBA\/files\/transfer\/miband\/db &lt; \/mnt\/1TBTOSHIBA\/files\/transfer\/miband\/steps_q.sql &gt; \/mnt\/1TBTOSHIBA\/files\/transfer\/miband\/steps.csv<\/p>\n\n\n\n<p>Every hour at the 45th minute the user &#8220;pi&#8221; exectues the statement and updates the csv file with the latest amount of steps.<\/p>\n\n\n\n<p>The Node-RED flow after this is very simple: An inject that runs on an interval, the csv-file, the csv-node and the UI table export.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1013\" height=\"425\" src=\"https:\/\/www.servo-server.net\/wp-content\/uploads\/2021\/06\/miband_sql_node_red.png\" alt=\"\" class=\"wp-image-67\" srcset=\"https:\/\/www.servo-server.net\/wp-content\/uploads\/2021\/06\/miband_sql_node_red.png 1013w, https:\/\/www.servo-server.net\/wp-content\/uploads\/2021\/06\/miband_sql_node_red-300x126.png 300w, https:\/\/www.servo-server.net\/wp-content\/uploads\/2021\/06\/miband_sql_node_red-768x322.png 768w\" sizes=\"auto, (max-width: 1013px) 100vw, 1013px\" \/><\/figure>\n\n\n\n<p>Result on the Node-RED Dashboard:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"386\" height=\"354\" src=\"https:\/\/www.servo-server.net\/wp-content\/uploads\/2021\/06\/mi_band_ui.png\" alt=\"\" class=\"wp-image-68\" srcset=\"https:\/\/www.servo-server.net\/wp-content\/uploads\/2021\/06\/mi_band_ui.png 386w, https:\/\/www.servo-server.net\/wp-content\/uploads\/2021\/06\/mi_band_ui-300x275.png 300w\" sizes=\"auto, (max-width: 386px) 100vw, 386px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Mi-Band 5Smartphone: Nokia 5.3OS on smartphone: Android 10Apps on smartphone required: Gadgetbridge, FolderSyncServer: Raspberry Pi 4OS: Raspbian GNU\/Linux 10 (buster)ioBroker: 4.0.10node-red Adapter: 2.3.0node-red version: 1.3.5 The idea was to display the steps recorded by the Mi-Band 5 on the node-RED Dashboard. The Mi-Band comes with a closed source App for the Smartphone that cant export&hellip;&nbsp;<a href=\"https:\/\/www.servo-server.net\/?p=58\" rel=\"bookmark\">Read More &raquo;<span class=\"screen-reader-text\">Mi-Band steps on node-RED Dashboard<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","footnotes":""},"categories":[13],"tags":[],"class_list":["post-58","post","type-post","status-publish","format-standard","hentry","category-node-red"],"_links":{"self":[{"href":"https:\/\/www.servo-server.net\/index.php?rest_route=\/wp\/v2\/posts\/58","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.servo-server.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.servo-server.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.servo-server.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.servo-server.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=58"}],"version-history":[{"count":8,"href":"https:\/\/www.servo-server.net\/index.php?rest_route=\/wp\/v2\/posts\/58\/revisions"}],"predecessor-version":[{"id":70,"href":"https:\/\/www.servo-server.net\/index.php?rest_route=\/wp\/v2\/posts\/58\/revisions\/70"}],"wp:attachment":[{"href":"https:\/\/www.servo-server.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=58"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.servo-server.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=58"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.servo-server.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=58"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}