{"id":401,"date":"2018-02-28T15:18:04","date_gmt":"2018-02-28T15:18:04","guid":{"rendered":"http:\/\/www.igfasouza.com\/blog\/?p=401"},"modified":"2021-04-27T10:48:48","modified_gmt":"2021-04-27T09:48:48","slug":"raspberry-pi-with-influxdb-and-grafana","status":"publish","type":"post","link":"http:\/\/www.igfasouza.com\/blog\/raspberry-pi-with-influxdb-and-grafana\/","title":{"rendered":"Raspberry Pi with InfluxDB and Grafana"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.igfasouza.com\/blog\/wp-content\/uploads\/2018\/02\/influxdb_grafana.jpg\" alt=\"\" width=\"487\" height=\"338\" class=\"alignnone size-full wp-image-827\" srcset=\"http:\/\/www.igfasouza.com\/blog\/wp-content\/uploads\/2018\/02\/influxdb_grafana.jpg 487w, http:\/\/www.igfasouza.com\/blog\/wp-content\/uploads\/2018\/02\/influxdb_grafana-300x208.jpg 300w\" sizes=\"auto, (max-width: 487px) 100vw, 487px\" \/><\/p>\n<p><b>Alright, boss?<\/b><\/p>\n<p><strong>Grafana<\/strong> is an open source metric analytics &#038; visualization suite. It is most commonly used for visualizing time series data for infrastructure and application analytics but many use it in other domains including industrial sensors, home automation, weather, and process control.<\/p>\n<p><a href=\"https:\/\/grafana.com\/\" rel=\"noopener\" target=\"_blank\">https:\/\/grafana.com\/<\/a><br \/>\n<a href=\"http:\/\/docs.grafana.org\/guides\/getting_started\/\" rel=\"noopener\" target=\"_blank\">http:\/\/docs.grafana.org\/guides\/getting_started\/<\/a><\/p>\n<p><strong>InfluxDB<\/strong> is an open-source time series database developed by InfluxData.<br \/>\nit is written in Go and optimized for fast, high-availability storage and retrieval of time series data in fields such as operations monitoring, application metrics, Internet of Things sensor data, and real-time analytics. <\/p>\n<p><a href=\"https:\/\/www.influxdata.com\/\" rel=\"noopener\" target=\"_blank\">https:\/\/www.influxdata.com\/<\/a><\/p>\n<p>Install InfluxDB on Raspberry Pi<br \/>\n<a href=\"https:\/\/gist.github.com\/boseji\/bb71910d43283a1b84ab200bcce43c26\" rel=\"noopener\" target=\"_blank\">https:\/\/gist.github.com\/boseji\/bb71910d43283a1b84ab200bcce43c26<\/a><\/p>\n<p>You can follow the link for more details but basically, I just run this:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"overflow:auto;white-space:nowrap;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/><\/div><\/td><td><div class=\"bash codecolorer\"><span class=\"kw2\">sudo<\/span> <span class=\"kw2\">apt-get update<\/span> <span class=\"sy0\">&amp;&amp;<\/span> <span class=\"kw2\">sudo<\/span> apt <span class=\"kw2\">install<\/span> apt-transport-https curl<br \/>\n<br \/>\ncurl <span class=\"re5\">-sL<\/span> https:<span class=\"sy0\">\/\/<\/span>repos.influxdata.com<span class=\"sy0\">\/<\/span>influxdb.key <span class=\"sy0\">|<\/span> <span class=\"kw2\">sudo<\/span> <span class=\"kw2\">apt-key add<\/span> -<br \/>\n<br \/>\n<span class=\"kw3\">echo<\/span> <span class=\"st0\">&quot;deb https:\/\/repos.influxdata.com\/debian jessie stable&quot;<\/span> <span class=\"sy0\">|<\/span> <span class=\"kw2\">sudo<\/span> <span class=\"kw2\">tee<\/span> <span class=\"sy0\">\/<\/span>etc<span class=\"sy0\">\/<\/span>apt<span class=\"sy0\">\/<\/span>sources.list.d<span class=\"sy0\">\/<\/span>influxdb.list<br \/>\n<br \/>\n<span class=\"kw2\">sudo<\/span> <span class=\"kw2\">apt-get update<\/span> <span class=\"sy0\">&amp;&amp;<\/span> <span class=\"kw2\">sudo<\/span> <span class=\"kw2\">apt-get install<\/span> influxdb<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>For this example we don\u2019t care about the web-based Admin user interface.<\/p>\n<p>To start the server<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"overflow:auto;white-space:nowrap;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/><\/div><\/td><td><div class=\"bash codecolorer\"><span class=\"kw2\">sudo<\/span> service influxdb start<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>Install Grafana on Raspberry Pi<br \/>\n<a href=\"https:\/\/github.com\/fg2it\/grafana-on-raspberry\/wiki\" rel=\"noopener\" target=\"_blank\">https:\/\/github.com\/fg2it\/grafana-on-raspberry\/wiki<\/a><\/p>\n<p>You can follow the link for more details but basically, I just run this:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"overflow:auto;white-space:nowrap;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/><\/div><\/td><td><div class=\"bash codecolorer\"><span class=\"kw2\">sudo<\/span> <span class=\"kw2\">apt-get install<\/span> apt-transport-https curl<br \/>\n<br \/>\ncurl https:<span class=\"sy0\">\/\/<\/span>bintray.com<span class=\"sy0\">\/<\/span>user<span class=\"sy0\">\/<\/span>downloadSubjectPublicKey?<span class=\"re2\">username<\/span>=bintray <span class=\"sy0\">|<\/span> <span class=\"kw2\">sudo<\/span> <span class=\"kw2\">apt-key add<\/span> -<br \/>\n<br \/>\n<span class=\"kw3\">echo<\/span> <span class=\"st0\">&quot;deb https:\/\/dl.bintray.com\/fg2it\/deb jessie main&quot;<\/span> <span class=\"sy0\">|<\/span> <span class=\"kw2\">sudo<\/span> <span class=\"kw2\">tee<\/span> <span class=\"re5\">-a<\/span> <span class=\"sy0\">\/<\/span>etc<span class=\"sy0\">\/<\/span>apt<span class=\"sy0\">\/<\/span>sources.list.d<span class=\"sy0\">\/<\/span>grafana.list<br \/>\n<br \/>\n<span class=\"kw2\">sudo<\/span> <span class=\"kw2\">apt-get update<\/span><br \/>\n<br \/>\n<span class=\"kw2\">sudo<\/span> <span class=\"kw2\">apt-get install<\/span> grafana<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>To start the  server<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"overflow:auto;white-space:nowrap;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/><\/div><\/td><td><div class=\"bash codecolorer\"><span class=\"kw2\">sudo<\/span> service grafana-server start<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>With everything installed you are ready to start doing some awesome things.<\/p>\n<p>I going to show two examples here:<br \/>\nOne using <a href=\"http:\/\/www.igfasouza.com\/blog\/sense-hat\/\" rel=\"noopener\" target=\"_blank\">sense-hat<\/a> to get the temperature, pressure and humidity value<br \/>\nand other using <a href=\"http:\/\/www.igfasouza.com\/blog\/smart-plug-tp-link\/\" rel=\"noopener\" target=\"_blank\">HS110<\/a> to get the energy consumption <\/p>\n<p>Here is a good InfluxDB getting started<br \/>\n<a href=\"https:\/\/docs.influxdata.com\/influxdb\/v0.8\/introduction\/getting_started\/\" rel=\"noopener\" target=\"_blank\">https:\/\/docs.influxdata.com\/influxdb\/v0.8\/introduction\/getting_started\/<\/a><\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"overflow:auto;white-space:nowrap;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/><\/div><\/td><td><div class=\"bash codecolorer\">influx <span class=\"re5\">-precision<\/span> rfc3339<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<div class=\"codecolorer-container sql blackboard\" style=\"overflow:auto;white-space:nowrap;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/><\/div><\/td><td><div class=\"sql codecolorer\"><span class=\"kw1\">CREATE<\/span> <span class=\"kw1\">DATABASE<\/span> logger<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>You can test with<\/p>\n<div class=\"codecolorer-container sql blackboard\" style=\"overflow:auto;white-space:nowrap;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/><\/div><\/td><td><div class=\"sql codecolorer\"><span class=\"kw1\">SHOW<\/span> <span class=\"kw1\">DATABASES<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>To run the code you need Install the python package first<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"overflow:auto;white-space:nowrap;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/><\/div><\/td><td><div class=\"bash codecolorer\"><span class=\"kw2\">sudo<\/span> pip <span class=\"kw2\">install<\/span> influxdb<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>Both examples are quite similar. Just change what I write on the table.<br \/>\nThis code is a hack from some Google examples.<\/p>\n<div class=\"codecolorer-container python blackboard\" style=\"overflow:auto;white-space:nowrap;height:300px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/>11<br \/>12<br \/>13<br \/>14<br \/>15<br \/>16<br \/>17<br \/>18<br \/>19<br \/>20<br \/>21<br \/>22<br \/>23<br \/>24<br \/>25<br \/>26<br \/>27<br \/>28<br \/>29<br \/>30<br \/>31<br \/>32<br \/>33<br \/>34<br \/>35<br \/>36<br \/>37<br \/>38<br \/>39<br \/>40<br \/>41<br \/>42<br \/>43<br \/>44<br \/>45<br \/>46<br \/>47<br \/>48<br \/>49<br \/>50<br \/>51<br \/>52<br \/>53<br \/>54<br \/>55<br \/>56<br \/>57<br \/>58<br \/>59<br \/>60<br \/>61<br \/>62<br \/>63<br \/>64<br \/>65<br \/>66<br \/>67<br \/>68<br \/>69<br \/>70<br \/>71<br \/>72<br \/>73<br \/>74<br \/>75<br \/>76<br \/>77<br \/>78<br \/>79<br \/>80<br \/>81<br \/>82<br \/>83<br \/>84<br \/>85<br \/>86<br \/>87<br \/>88<br \/>89<br \/><\/div><\/td><td><div class=\"python codecolorer\"><span class=\"kw1\">import<\/span> argparse<br \/>\n<span class=\"kw1\">import<\/span> <span class=\"kw3\">time<\/span><br \/>\n<span class=\"kw1\">import<\/span> <span class=\"kw3\">datetime<\/span><br \/>\n<span class=\"kw1\">import<\/span> <span class=\"kw3\">sys<\/span><br \/>\n<span class=\"kw1\">from<\/span> influxdb <span class=\"kw1\">import<\/span> InfluxDBClient<br \/>\n<span class=\"kw1\">from<\/span> sense_hat <span class=\"kw1\">import<\/span> SenseHat<br \/>\n<br \/>\nsense<span class=\"sy0\">=<\/span>SenseHat<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><br \/>\n&nbsp;<br \/>\n<span class=\"co1\"># Set required InfluxDB parameters.<\/span><br \/>\nhost <span class=\"sy0\">=<\/span> <span class=\"st0\">&quot;localhost&quot;<\/span> <span class=\"co1\">#Could also set local ip address<\/span><br \/>\nport <span class=\"sy0\">=<\/span> <span class=\"nu0\">8086<\/span><br \/>\n<span class=\"kw3\">user<\/span> <span class=\"sy0\">=<\/span> <span class=\"st0\">&quot;root&quot;<\/span><br \/>\npassword <span class=\"sy0\">=<\/span> <span class=\"st0\">&quot;root&quot;<\/span><br \/>\n&nbsp;<br \/>\n<span class=\"co1\"># How frequently we will write sensor data from SenseHat to the database.<\/span><br \/>\nsampling_period <span class=\"sy0\">=<\/span> <span class=\"nu0\">5<\/span><br \/>\n<br \/>\n<span class=\"kw1\">def<\/span> get_args<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span>:<br \/>\n&nbsp; &nbsp; <span class=\"st0\">'''This function parses and returns arguments passed in'''<\/span><br \/>\n&nbsp; &nbsp; <span class=\"co1\"># Assign description to the help doc<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw3\">parser<\/span> <span class=\"sy0\">=<\/span> argparse.<span class=\"me1\">ArgumentParser<\/span><span class=\"br0\">&#40;<\/span>description<span class=\"sy0\">=<\/span><span class=\"st0\">'Program writes measurements data from SenseHat to specified influx db.'<\/span><span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"co1\"># Add arguments<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw3\">parser<\/span>.<span class=\"me1\">add_argument<\/span><span class=\"br0\">&#40;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"st0\">'-db'<\/span><span class=\"sy0\">,<\/span><span class=\"st0\">'--database'<\/span><span class=\"sy0\">,<\/span> <span class=\"kw2\">type<\/span><span class=\"sy0\">=<\/span><span class=\"kw2\">str<\/span><span class=\"sy0\">,<\/span> <span class=\"kw2\">help<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">'Database name'<\/span><span class=\"sy0\">,<\/span> required<span class=\"sy0\">=<\/span><span class=\"kw2\">True<\/span><span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw3\">parser<\/span>.<span class=\"me1\">add_argument<\/span><span class=\"br0\">&#40;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"st0\">'-sn'<\/span><span class=\"sy0\">,<\/span><span class=\"st0\">'--session'<\/span><span class=\"sy0\">,<\/span> <span class=\"kw2\">type<\/span><span class=\"sy0\">=<\/span><span class=\"kw2\">str<\/span><span class=\"sy0\">,<\/span> <span class=\"kw2\">help<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">'Session'<\/span><span class=\"sy0\">,<\/span> required<span class=\"sy0\">=<\/span><span class=\"kw2\">True<\/span><span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; now <span class=\"sy0\">=<\/span> <span class=\"kw3\">datetime<\/span>.<span class=\"kw3\">datetime<\/span>.<span class=\"me1\">now<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw3\">parser<\/span>.<span class=\"me1\">add_argument<\/span><span class=\"br0\">&#40;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"st0\">'-rn'<\/span><span class=\"sy0\">,<\/span><span class=\"st0\">'--run'<\/span><span class=\"sy0\">,<\/span> <span class=\"kw2\">type<\/span><span class=\"sy0\">=<\/span><span class=\"kw2\">str<\/span><span class=\"sy0\">,<\/span> <span class=\"kw2\">help<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">'Run number'<\/span><span class=\"sy0\">,<\/span> required<span class=\"sy0\">=<\/span><span class=\"kw2\">False<\/span><span class=\"sy0\">,<\/span>default<span class=\"sy0\">=<\/span>now.<span class=\"me1\">strftime<\/span><span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;%Y%m%d%H%M&quot;<\/span><span class=\"br0\">&#41;<\/span><span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; <span class=\"co1\"># Array of all arguments passed to script<\/span><br \/>\n&nbsp; &nbsp; args<span class=\"sy0\">=<\/span><span class=\"kw3\">parser<\/span>.<span class=\"me1\">parse_args<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"co1\"># Assign args to variables<\/span><br \/>\n&nbsp; &nbsp; dbname<span class=\"sy0\">=<\/span>args.<span class=\"me1\">database<\/span><br \/>\n&nbsp; &nbsp; runNo<span class=\"sy0\">=<\/span>args.<span class=\"me1\">run<\/span><br \/>\n&nbsp; &nbsp; session<span class=\"sy0\">=<\/span>args.<span class=\"me1\">session<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">return<\/span> dbname<span class=\"sy0\">,<\/span> session<span class=\"sy0\">,<\/span>runNo<br \/>\n&nbsp; &nbsp; <br \/>\n<span class=\"kw1\">def<\/span> get_data_points<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span>:<br \/>\n&nbsp; &nbsp; <span class=\"co1\"># Get the three measurement values from the SenseHat sensors<\/span><br \/>\n&nbsp; &nbsp; temperature <span class=\"sy0\">=<\/span> sense.<span class=\"me1\">get_temperature<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; pressure <span class=\"sy0\">=<\/span> sense.<span class=\"me1\">get_pressure<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; humidity <span class=\"sy0\">=<\/span> sense.<span class=\"me1\">get_humidity<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"co1\"># Get a local timestamp<\/span><br \/>\n&nbsp; &nbsp; timestamp<span class=\"sy0\">=<\/span><span class=\"kw3\">datetime<\/span>.<span class=\"kw3\">datetime<\/span>.<span class=\"me1\">utcnow<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span>.<span class=\"me1\">isoformat<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">print<\/span> <span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;{0} {1} Temperature: {2}{3}C Pressure: {4}mb Humidity: {5}%&quot;<\/span> .<span class=\"me1\">format<\/span><span class=\"br0\">&#40;<\/span>session<span class=\"sy0\">,<\/span>runNo<span class=\"sy0\">,<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw2\">round<\/span><span class=\"br0\">&#40;<\/span>temperature<span class=\"sy0\">,<\/span><span class=\"nu0\">1<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">,<\/span>u<span class=\"st0\">'u00b0'<\/span>.<span class=\"me1\">encode<\/span><span class=\"br0\">&#40;<\/span><span class=\"st0\">'utf8'<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">,<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw2\">round<\/span><span class=\"br0\">&#40;<\/span>pressure<span class=\"sy0\">,<\/span><span class=\"nu0\">3<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">,<\/span><span class=\"kw2\">round<\/span><span class=\"br0\">&#40;<\/span>humidity<span class=\"sy0\">,<\/span><span class=\"nu0\">1<\/span><span class=\"br0\">&#41;<\/span><span class=\"br0\">&#41;<\/span><span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; <span class=\"co1\"># Create Influxdb datapoints (using lineprotocol as of Influxdb &gt;1.1)<\/span><br \/>\n&nbsp; &nbsp; datapoints <span class=\"sy0\">=<\/span> <span class=\"br0\">&#91;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"st0\">&quot;measurement&quot;<\/span>: session<span class=\"sy0\">,<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"st0\">&quot;tags&quot;<\/span>: <span class=\"br0\">&#123;<\/span><span class=\"st0\">&quot;runNum&quot;<\/span>: runNo<span class=\"sy0\">,<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><span class=\"sy0\">,<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"st0\">&quot;time&quot;<\/span>: timestamp<span class=\"sy0\">,<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"st0\">&quot;fields&quot;<\/span>: <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"st0\">&quot;temperaturevalue&quot;<\/span>:temperature<span class=\"sy0\">,<\/span><span class=\"st0\">&quot;pressurevalue&quot;<\/span>:pressure<span class=\"sy0\">,<\/span><span class=\"st0\">&quot;humidityvalue&quot;<\/span>:humidity<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#93;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">return<\/span> datapoints<br \/>\n<br \/>\n<span class=\"co1\"># Match return values from get_arguments()<\/span><br \/>\n<span class=\"co1\"># and assign to their respective variables<\/span><br \/>\ndbname<span class=\"sy0\">,<\/span> session<span class=\"sy0\">,<\/span> runNo <span class=\"sy0\">=<\/span>get_args<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span> &nbsp; <br \/>\n<span class=\"kw1\">print<\/span> <span class=\"st0\">&quot;Session: &quot;<\/span><span class=\"sy0\">,<\/span> session<br \/>\n<span class=\"kw1\">print<\/span> <span class=\"st0\">&quot;Run No: &quot;<\/span><span class=\"sy0\">,<\/span> runNo<br \/>\n<span class=\"kw1\">print<\/span> <span class=\"st0\">&quot;DB name: &quot;<\/span><span class=\"sy0\">,<\/span> dbname<br \/>\n<br \/>\n<span class=\"co1\"># Initialize the Influxdb client<\/span><br \/>\nclient <span class=\"sy0\">=<\/span> InfluxDBClient<span class=\"br0\">&#40;<\/span>host<span class=\"sy0\">,<\/span> port<span class=\"sy0\">,<\/span> <span class=\"kw3\">user<\/span><span class=\"sy0\">,<\/span> password<span class=\"sy0\">,<\/span> dbname<span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <br \/>\n<span class=\"kw1\">try<\/span>:<br \/>\n&nbsp; &nbsp; &nbsp;<span class=\"kw1\">while<\/span> <span class=\"kw2\">True<\/span>:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"co1\"># Write datapoints to InfluxDB<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; datapoints<span class=\"sy0\">=<\/span>get_data_points<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; bResult<span class=\"sy0\">=<\/span>client.<span class=\"me1\">write_points<\/span><span class=\"br0\">&#40;<\/span>datapoints<span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">print<\/span><span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;Write points {0} Bresult:{1}&quot;<\/span>.<span class=\"me1\">format<\/span><span class=\"br0\">&#40;<\/span>datapoints<span class=\"sy0\">,<\/span>bResult<span class=\"br0\">&#41;<\/span><span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; sense.<span class=\"me1\">show_message<\/span><span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;OK&quot;<\/span><span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"co1\"># Wait for next sample<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw3\">time<\/span>.<span class=\"me1\">sleep<\/span><span class=\"br0\">&#40;<\/span>sampling_period<span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"co1\"># Run until keyboard ctrl-c<\/span><br \/>\n<span class=\"kw1\">except<\/span> <span class=\"kw2\">KeyboardInterrupt<\/span>:<br \/>\n&nbsp; &nbsp; <span class=\"kw1\">print<\/span> <span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;Program stopped by keyboard interrupt [CTRL_C] by user. &quot;<\/span><span class=\"br0\">&#41;<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>The HS110 example I just change some lines:<\/p>\n<div class=\"codecolorer-container python blackboard\" style=\"overflow:auto;white-space:nowrap;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/>11<br \/>12<br \/>13<br \/>14<br \/><\/div><\/td><td><div class=\"python codecolorer\">consumption <span class=\"sy0\">=<\/span> plug.<span class=\"me1\">get_emeter_realtime<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><span class=\"br0\">&#91;<\/span>\u201cpower\u201d<span class=\"br0\">&#93;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"co1\"># Create Influxdb datapoints (using lineprotocol as of Influxdb &gt;1.1)<\/span><br \/>\n&nbsp; &nbsp; datapoints <span class=\"sy0\">=<\/span> <span class=\"br0\">&#91;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"st0\">&quot;measurement&quot;<\/span>: session<span class=\"sy0\">,<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"st0\">&quot;tags&quot;<\/span>: <span class=\"br0\">&#123;<\/span><span class=\"st0\">&quot;runNum&quot;<\/span>: runNo<span class=\"sy0\">,<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><span class=\"sy0\">,<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"st0\">&quot;time&quot;<\/span>: timestamp<span class=\"sy0\">,<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"st0\">&quot;fields&quot;<\/span>: <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"st0\">&quot;consumption&quot;<\/span>:consumption<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#93;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">return<\/span> datapoints<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>To run:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"overflow:auto;white-space:nowrap;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/><\/div><\/td><td><div class=\"bash codecolorer\">python igor.py <span class=\"re5\">-db<\/span>=logger <span class=\"re5\">-sn<\/span>=test1<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>To setup Grafana:<br \/>\nhttp:\/\/localhost:3000<\/p>\n<p>Go to Datasource->Add New and fill in with your database details<br \/>\nUser and psw should be: \u201croot\u201d and \u201croot\u201d by default<\/p>\n<p><a href=\"http:\/\/www.igfasouza.com\/blog\/wp-content\/uploads\/2018\/02\/Grafana01.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.igfasouza.com\/blog\/wp-content\/uploads\/2018\/02\/Grafana01-300x284.png\" alt=\"\" width=\"300\" height=\"284\" class=\"alignnone size-medium wp-image-405\" srcset=\"http:\/\/www.igfasouza.com\/blog\/wp-content\/uploads\/2018\/02\/Grafana01-300x284.png 300w, http:\/\/www.igfasouza.com\/blog\/wp-content\/uploads\/2018\/02\/Grafana01-768x727.png 768w, http:\/\/www.igfasouza.com\/blog\/wp-content\/uploads\/2018\/02\/Grafana01-624x590.png 624w, http:\/\/www.igfasouza.com\/blog\/wp-content\/uploads\/2018\/02\/Grafana01.png 856w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Create a new dashboard, choose your database and on the tab matrics configure your query.<br \/>\n<a href=\"http:\/\/www.igfasouza.com\/blog\/wp-content\/uploads\/2018\/02\/Grafana02.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.igfasouza.com\/blog\/wp-content\/uploads\/2018\/02\/Grafana02-300x121.png\" alt=\"\" width=\"300\" height=\"121\" class=\"alignnone size-medium wp-image-406\" srcset=\"http:\/\/www.igfasouza.com\/blog\/wp-content\/uploads\/2018\/02\/Grafana02-300x121.png 300w, http:\/\/www.igfasouza.com\/blog\/wp-content\/uploads\/2018\/02\/Grafana02-768x311.png 768w, http:\/\/www.igfasouza.com\/blog\/wp-content\/uploads\/2018\/02\/Grafana02-1024x414.png 1024w, http:\/\/www.igfasouza.com\/blog\/wp-content\/uploads\/2018\/02\/Grafana02-624x252.png 624w, http:\/\/www.igfasouza.com\/blog\/wp-content\/uploads\/2018\/02\/Grafana02.png 1132w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Edit the dashboard and go to metrics.<\/p>\n<p><a href=\"http:\/\/www.igfasouza.com\/blog\/wp-content\/uploads\/2018\/02\/Grafana03.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.igfasouza.com\/blog\/wp-content\/uploads\/2018\/02\/Grafana03-300x132.png\" alt=\"\" width=\"300\" height=\"132\" class=\"alignnone size-medium wp-image-407\" srcset=\"http:\/\/www.igfasouza.com\/blog\/wp-content\/uploads\/2018\/02\/Grafana03-300x132.png 300w, http:\/\/www.igfasouza.com\/blog\/wp-content\/uploads\/2018\/02\/Grafana03-768x337.png 768w, http:\/\/www.igfasouza.com\/blog\/wp-content\/uploads\/2018\/02\/Grafana03-624x274.png 624w, http:\/\/www.igfasouza.com\/blog\/wp-content\/uploads\/2018\/02\/Grafana03.png 938w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Choose the database and then configure the query.<\/p>\n<p><a href=\"http:\/\/www.igfasouza.com\/blog\/wp-content\/uploads\/2018\/02\/Grafana04.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.igfasouza.com\/blog\/wp-content\/uploads\/2018\/02\/Grafana04-300x167.png\" alt=\"\" width=\"300\" height=\"167\" class=\"alignnone size-medium wp-image-408\" srcset=\"http:\/\/www.igfasouza.com\/blog\/wp-content\/uploads\/2018\/02\/Grafana04-300x167.png 300w, http:\/\/www.igfasouza.com\/blog\/wp-content\/uploads\/2018\/02\/Grafana04-768x428.png 768w, http:\/\/www.igfasouza.com\/blog\/wp-content\/uploads\/2018\/02\/Grafana04-624x348.png 624w, http:\/\/www.igfasouza.com\/blog\/wp-content\/uploads\/2018\/02\/Grafana04.png 996w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<div class=\"twitter-tweet\">\n<blockquote class=\"twitter-tweet\" data-lang=\"en\">\n<p lang=\"en\" dir=\"ltr\">Sense hat + Grafana = on fly himidity, temperature and pressure dashboard <a href=\"https:\/\/t.co\/bp0d8jTXXZ\">pic.twitter.com\/bp0d8jTXXZ<\/a><\/p>\n<p>&mdash; Igor Souza (@Igfasouza) <a href=\"https:\/\/twitter.com\/Igfasouza\/status\/968081927050801152?ref_src=twsrc%5Etfw\">February 26, 2018<\/a><\/p><\/blockquote>\n<\/div>\n<p>If you succeed in create your dashboard let a comment below about what are you doing.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Alright, boss? Grafana is an open source metric analytics &#038; visualization suite. It is most commonly used for visualizing time series data for infrastructure and application analytics but many use it in other domains including industrial sensors, home automation, weather,&hellip; <a href=\"http:\/\/www.igfasouza.com\/blog\/raspberry-pi-with-influxdb-and-grafana\/\" class=\"more-link\">Continue Reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":827,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24],"tags":[13],"class_list":["post-401","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-raspberry-pi","tag-raspberry-pi"],"_links":{"self":[{"href":"http:\/\/www.igfasouza.com\/blog\/wp-json\/wp\/v2\/posts\/401","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.igfasouza.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.igfasouza.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.igfasouza.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.igfasouza.com\/blog\/wp-json\/wp\/v2\/comments?post=401"}],"version-history":[{"count":15,"href":"http:\/\/www.igfasouza.com\/blog\/wp-json\/wp\/v2\/posts\/401\/revisions"}],"predecessor-version":[{"id":1192,"href":"http:\/\/www.igfasouza.com\/blog\/wp-json\/wp\/v2\/posts\/401\/revisions\/1192"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.igfasouza.com\/blog\/wp-json\/wp\/v2\/media\/827"}],"wp:attachment":[{"href":"http:\/\/www.igfasouza.com\/blog\/wp-json\/wp\/v2\/media?parent=401"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.igfasouza.com\/blog\/wp-json\/wp\/v2\/categories?post=401"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.igfasouza.com\/blog\/wp-json\/wp\/v2\/tags?post=401"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}