{"id":40,"date":"2021-02-28T06:57:10","date_gmt":"2021-02-28T06:57:10","guid":{"rendered":"http:\/\/tel-zur.net\/blog\/?p=40"},"modified":"2022-07-01T09:31:26","modified_gmt":"2022-07-01T06:31:26","slug":"iot-project-temperature-measuremnts-using-arduino-raspberrypi-mqtt-python-influxdb-and-grafana","status":"publish","type":"post","link":"https:\/\/tel-zur.net\/blog\/2021\/02\/28\/iot-project-temperature-measuremnts-using-arduino-raspberrypi-mqtt-python-influxdb-and-grafana\/","title":{"rendered":"IoT Project: Temperature measuremnts using Arduino, Raspberrypi, MQTT, Python, Influxdb and Grafana"},"content":{"rendered":"\n<p>Goal: <strong>Practice the model of IoT (Edge) data streaming and its remote analysis (Cloud).<\/strong><\/p>\n\n\n\n<p>This work was inspired by works of others, in particular [1] and [2].<\/p>\n\n\n\n<p>The system schematic diagram is as follows:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"444\" src=\"https:\/\/tel-zur.net\/blog\/wp-content\/uploads\/2021\/02\/Diagram1-1024x444.png\" alt=\"\" class=\"wp-image-67\" srcset=\"https:\/\/tel-zur.net\/blog\/wp-content\/uploads\/2021\/02\/Diagram1-1024x444.png 1024w, https:\/\/tel-zur.net\/blog\/wp-content\/uploads\/2021\/02\/Diagram1-300x130.png 300w, https:\/\/tel-zur.net\/blog\/wp-content\/uploads\/2021\/02\/Diagram1-768x333.png 768w, https:\/\/tel-zur.net\/blog\/wp-content\/uploads\/2021\/02\/Diagram1.png 1424w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Equipment:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li><a rel=\"noreferrer noopener\" href=\"https:\/\/store.arduino.cc\/arduino-uno-rev3\" target=\"_blank\">Arduino Uno<\/a>.<\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/store.arduino.cc\/arduino-ethernet-shield-2\" target=\"_blank\">Arduino EthernetSheild<\/a>.<\/li><li>LM35 temperature sensor (<a rel=\"noreferrer noopener\" href=\"https:\/\/www.ti.com\/lit\/ds\/symlink\/lm35.pdf\" target=\"_blank\">datasheet<\/a>).<\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/www.amazon.com\/Raspberry-Pi-MS-004-00000024-Model-Board\/dp\/B01LPLPBS8\" target=\"_blank\">Raspberrypi-3<\/a>, serving as an MQTT broker.<\/li><li>Another computer (my laptop) for visualization.<\/li><li>Ethernet network to interconnect all the devices (make sure that MQTT port, 1883 by default, is open, &#8220;port forwarding&#8221;).<\/li><\/ol>\n\n\n\n<p>Parts can be purchased in many stores including Aliexpress and alike.<\/p>\n\n\n\n<p>Software:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Data acquisition code for the Arduino is developed, compiled, and uploaded to the device from the <a rel=\"noreferrer noopener\" href=\"https:\/\/www.arduino.cc\/en\/Main.Software\" target=\"_blank\">Arduino IDE<\/a>.<\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/www.python.org\/\" target=\"_blank\">Python<\/a> code for obtaining the data on the Raspberrypi.<\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/www.influxdata.com\/\" target=\"_blank\">Influxdb<\/a> for a database on the Raspberrypi.<\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/grafana.com\/\" target=\"_blank\">Grafana<\/a> for visualization (operated on the Raspebbeypi but also can be installed on another computer as well).<\/li><\/ol>\n\n\n\n<p>The codes I wrote are not perfect in terms of software quality, efficiency and security! So these code should not be used in any real application and their purpose is for educational use only.<\/p>\n\n\n\n<p>The code is available on <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/gtelzur\/IoT_study\" target=\"_blank\">my github<\/a>.<\/p>\n\n\n\n<p>How to learn and understand this project. I would like to suggest a gradual approach:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>First, learn MQTT basics and publish from the device a simple &#8220;Hello World&#8221; string which can be read (&#8220;subscribed&#8221;) by another computer on the same network.<\/li><li>Then, connect the temperature sensor, check that you can correctly read it, and then replace the &#8220;Hello World&#8221; string with the temperature reading.<img loading=\"lazy\" decoding=\"async\" width=\"650\" height=\"366\" class=\"wp-image-55\" style=\"width: 650px;\" src=\"https:\/\/tel-zur.net\/blog\/wp-content\/uploads\/2021\/02\/arduino_LM35.png\" alt=\"Arduino Uno and LM35 temperature sensor\" srcset=\"https:\/\/tel-zur.net\/blog\/wp-content\/uploads\/2021\/02\/arduino_LM35.png 1058w, https:\/\/tel-zur.net\/blog\/wp-content\/uploads\/2021\/02\/arduino_LM35-300x169.png 300w, https:\/\/tel-zur.net\/blog\/wp-content\/uploads\/2021\/02\/arduino_LM35-1024x576.png 1024w, https:\/\/tel-zur.net\/blog\/wp-content\/uploads\/2021\/02\/arduino_LM35-768x432.png 768w\" sizes=\"auto, (max-width: 650px) 100vw, 650px\" \/><\/li><li>Install the software on the Raspberrypi. You need to know how to create a new Influxdb database and have to master a few SQL elementary commands.<\/li><li>Install Grafana and connect it with Influxdb using a built-in module.       <img loading=\"lazy\" decoding=\"async\" width=\"450\" height=\"338\" class=\"wp-image-49\" style=\"width: 450px;\" src=\"https:\/\/tel-zur.net\/blog\/wp-content\/uploads\/2021\/02\/20210214_174122-scaled.jpg\" alt=\"Grafana\" srcset=\"https:\/\/tel-zur.net\/blog\/wp-content\/uploads\/2021\/02\/20210214_174122-scaled.jpg 2560w, https:\/\/tel-zur.net\/blog\/wp-content\/uploads\/2021\/02\/20210214_174122-300x225.jpg 300w, https:\/\/tel-zur.net\/blog\/wp-content\/uploads\/2021\/02\/20210214_174122-1024x768.jpg 1024w, https:\/\/tel-zur.net\/blog\/wp-content\/uploads\/2021\/02\/20210214_174122-768x576.jpg 768w, https:\/\/tel-zur.net\/blog\/wp-content\/uploads\/2021\/02\/20210214_174122-1536x1152.jpg 1536w, https:\/\/tel-zur.net\/blog\/wp-content\/uploads\/2021\/02\/20210214_174122-2048x1536.jpg 2048w, https:\/\/tel-zur.net\/blog\/wp-content\/uploads\/2021\/02\/20210214_174122-1568x1176.jpg 1568w\" sizes=\"auto, (max-width: 450px) 100vw, 450px\" \/><\/li><\/ol>\n\n\n\n<p>More ideas to go from here:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>You can install an MQTT client on your mobile phone and after a short setup you can view the temperature from there:<img loading=\"lazy\" decoding=\"async\" width=\"450\" height=\"700\" class=\"wp-image-58\" style=\"width: 450px;\" src=\"https:\/\/tel-zur.net\/blog\/wp-content\/uploads\/2021\/02\/mobile_phone.jpg\" alt=\"MQTT client mobile app.\" srcset=\"https:\/\/tel-zur.net\/blog\/wp-content\/uploads\/2021\/02\/mobile_phone.jpg 1080w, https:\/\/tel-zur.net\/blog\/wp-content\/uploads\/2021\/02\/mobile_phone-193x300.jpg 193w, https:\/\/tel-zur.net\/blog\/wp-content\/uploads\/2021\/02\/mobile_phone-658x1024.jpg 658w, https:\/\/tel-zur.net\/blog\/wp-content\/uploads\/2021\/02\/mobile_phone-768x1195.jpg 768w, https:\/\/tel-zur.net\/blog\/wp-content\/uploads\/2021\/02\/mobile_phone-987x1536.jpg 987w\" sizes=\"auto, (max-width: 450px) 100vw, 450px\" \/><\/li><\/ol>\n\n\n\n<p>2) You can upload the temperature reading to the cloud. It makes more sense to install the database on a big machine and not on the Raspberrypi since the data volume is expected to grow with time. In order to be as much as possible vendor-neutral, I decided not to use IoT-ready solutions by the cloud providers and therefore I installed a fresh Ubuntu (&#8220;ubuntu-focal-20.04&#8221; image) node in the AWS cloud (IaaS). After installing the needed software tools (in a similar way to the Raspberrypi) the node became ready to  accept the temperature data:<img loading=\"lazy\" decoding=\"async\" width=\"650\" height=\"398\" class=\"wp-image-65\" style=\"width: 650px;\" src=\"https:\/\/tel-zur.net\/blog\/wp-content\/uploads\/2021\/02\/aws_01.png\" alt=\"\"><\/p>\n\n\n\n<p>It is then possible to install Grafana on a local computer and to connect it to the Influxdb in the cloud or to install Grafana also on the cloud and then to view it using tools such as VNCserver\/client.<\/p>\n\n\n\n<p><strong>References:<\/strong><\/p>\n\n\n\n<p>[1] Maker.io, &#8220;<a rel=\"noreferrer noopener\" href=\"https:\/\/www.digikey.com\/en\/maker\/blogs\/2018\/how-to-use-basic-mqtt-on-arduino\" target=\"_blank\">How To Use Basic MQTT on Arduino<\/a>&#8220;.<\/p>\n\n\n\n<p>[2] DiyIOt, &#8220;<a href=\"https:\/\/diyi0t.com\/visualize-mqtt-data-with-influxdb-and-grafana\/\" target=\"_blank\" rel=\"noreferrer noopener\">Visualize MQTT Data with InfluxDB and Grafana<\/a>&#8220;.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Goal: Practice the model of IoT (Edge) data streaming and its remote analysis (Cloud). This work was inspired by works of others, in particular [1] and [2]. The system schematic diagram is as follows: Equipment: Arduino Uno. Arduino EthernetSheild. LM35 temperature sensor (datasheet). Raspberrypi-3, serving as an MQTT broker. Another computer (my laptop) for visualization. &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/tel-zur.net\/blog\/2021\/02\/28\/iot-project-temperature-measuremnts-using-arduino-raspberrypi-mqtt-python-influxdb-and-grafana\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;IoT Project: Temperature measuremnts using Arduino, Raspberrypi, MQTT, Python, Influxdb and Grafana&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-40","post","type-post","status-publish","format-standard","hentry","category-uncategorized","entry"],"_links":{"self":[{"href":"https:\/\/tel-zur.net\/blog\/wp-json\/wp\/v2\/posts\/40","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tel-zur.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tel-zur.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tel-zur.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tel-zur.net\/blog\/wp-json\/wp\/v2\/comments?post=40"}],"version-history":[{"count":16,"href":"https:\/\/tel-zur.net\/blog\/wp-json\/wp\/v2\/posts\/40\/revisions"}],"predecessor-version":[{"id":70,"href":"https:\/\/tel-zur.net\/blog\/wp-json\/wp\/v2\/posts\/40\/revisions\/70"}],"wp:attachment":[{"href":"https:\/\/tel-zur.net\/blog\/wp-json\/wp\/v2\/media?parent=40"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tel-zur.net\/blog\/wp-json\/wp\/v2\/categories?post=40"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tel-zur.net\/blog\/wp-json\/wp\/v2\/tags?post=40"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}