{"id":35,"date":"2022-11-06T13:23:11","date_gmt":"2022-11-06T12:23:11","guid":{"rendered":"https:\/\/www.zecevic-ninja.com\/?p=35"},"modified":"2022-11-06T13:25:12","modified_gmt":"2022-11-06T12:25:12","slug":"storing-opendtu-data-in-influx-db","status":"publish","type":"post","link":"https:\/\/www.zecevic-ninja.com\/?p=35","title":{"rendered":"Storing OpenDTU data in Influx DB"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\">Motivation<\/h1>\n\n\n\n<p>I just bought Solar panel set. And i wanted to monitor everything, but looking at prices of monitoring equipment costs 150 or more \u20ac i decided to look up for cheaper solution. So everything i needed costed me around 20\u20ac.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">How to connect everything<\/h1>\n\n\n\n<p>To star this i would like to say that I am using my infrastructure, and everything is self hosted in my network. So there are maybe some security issues and some similar things, but to be honest there are only inside network, and as it is not available from outside, and guests uses other network that can not communicate with my own network i have decided to ignore this for now.<\/p>\n\n\n\n<p>My network is based on Mikrotik Routers and APs, configured with CAPsMAN. And server is inside network, connected with cable. Basic hardware is Celeron J1900 with 4 GB RAM. There are more stuff running on that machine. CPU is around 0.20 and Ram about 1.5 GB used. So hardware requirements are really small. And everything is running on Docker Containers.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">OpenDTU<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Introduction<\/h3>\n\n\n\n<p>I am using Firmware Version \/ Git Hash: 13b22de<\/p>\n\n\n\n<p>I will not write here much. You can read here everything: <a href=\"https:\/\/github.com\/tbnobody\/OpenDTU\">https:\/\/github.com\/tbnobody\/OpenDTU<\/a><\/p>\n\n\n\n<p>Basically i build the hardware, purchased ESP32 board and NRF24L01+ radio board from links on GitHub. Wired everything and flashed ESP32, had some issues, had to change some board config. In My case i had to change IRQ pin to 2. You can see this directly on board.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;env:generic]\nboard = esp32dev\nbuild_flags = ${env.build_flags}\n    -DHOYMILES_PIN_MISO=19\n    -DHOYMILES_PIN_MOSI=23\n    -DHOYMILES_PIN_SCLK=18\n    -DHOYMILES_PIN_IRQ=2\n    -DHOYMILES_PIN_CE=4\n    -DHOYMILES_PIN_CS=5\n<\/code><\/pre>\n\n\n\n<p>After that I was able to connect to Inverter and i got data.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Configuration to send data to mosquitto<\/h3>\n\n\n\n<p>This can work after you have installed and configured mosquitto<\/p>\n\n\n\n<p>You have to enable MqTT<\/p>\n\n\n\n<p>You need to enter hostname where the data is send to, and port.<\/p>\n\n\n\n<p>Should look something like this:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"783\" src=\"https:\/\/www.zecevic-ninja.com\/wp-content\/uploads\/2022\/11\/image-1024x783.png\" alt=\"\" class=\"wp-image-37\" srcset=\"https:\/\/www.zecevic-ninja.com\/wp-content\/uploads\/2022\/11\/image-1024x783.png 1024w, https:\/\/www.zecevic-ninja.com\/wp-content\/uploads\/2022\/11\/image-300x229.png 300w, https:\/\/www.zecevic-ninja.com\/wp-content\/uploads\/2022\/11\/image-768x587.png 768w, https:\/\/www.zecevic-ninja.com\/wp-content\/uploads\/2022\/11\/image-920x704.png 920w, https:\/\/www.zecevic-ninja.com\/wp-content\/uploads\/2022\/11\/image-230x176.png 230w, https:\/\/www.zecevic-ninja.com\/wp-content\/uploads\/2022\/11\/image-350x268.png 350w, https:\/\/www.zecevic-ninja.com\/wp-content\/uploads\/2022\/11\/image-480x367.png 480w, https:\/\/www.zecevic-ninja.com\/wp-content\/uploads\/2022\/11\/image.png 1480w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">mosquitto<\/h2>\n\n\n\n<p>I used mosquitto as MQTT broker. In my case i used it as container. As i like to use containers i configured evertything using contaners on my server. <\/p>\n\n\n\n<p>I used version 2.0.15<\/p>\n\n\n\n<p>Path i have used are:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\/data\/mosquitto\/data<\/li>\n\n\n\n<li>\/data\/mosquitto\/log<\/li>\n\n\n\n<li>\/data\/mosquitto\/config<\/li>\n<\/ul>\n\n\n\n<p>You have to create your own paths.<\/p>\n\n\n\n<p>After you have created paths in config directory you have create config file mosquitto.conf<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>persistence true\npersistence_location \/mosquitto\/data\/\nlog_dest file \/mosquitto\/log\/mosquitto.log\nlistener 1883 0.0.0.0\nlistener 9001 0.0.0.0\nallow_anonymous true<\/code><\/pre>\n\n\n\n<p>now you can start container<\/p>\n\n\n\n<p>To start the container:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker run \\\n  -v \/data\/mosquitto\/data:\/mosquitto\/data \\\n  -v \/data\/mosquitto\/log:\/mosquitto\/log \\\n  -v \/data\/mosquitto\/config:\/mosquitto\/config \\\n  -p 1883:1884 \\\n  -p 9001:9002 \\\n  eclipse-mosquitto:2.0.15<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">InfluxDB<\/h2>\n\n\n\n<p>InfluxDB is used to store all the data and get good looking graphs.<\/p>\n\n\n\n<p>I am using version 2.4.0<\/p>\n\n\n\n<p>Path i have used are:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\/data\/influxdb<\/li>\n\n\n\n<li>\/data\/influxdb\/config<\/li>\n<\/ul>\n\n\n\n<p>To start the container<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker run \\\n  -v \/data\/influxdb:\/var\/lib\/influxdb2 \\\n  -v \/data\/influxdb\/config \/etc\/influxdb2 \\\n  -p 8086:8086 \\\n  influxdb:2.4.0<\/code><\/pre>\n\n\n\n<p>After you start InfluxDB you have to configure bucket where the data should be going, and token for for telegraf. Plese refer to official documentation how to do that. Here is documentation: <a href=\"https:\/\/docs.influxdata.com\/influxdb\/v2.4\/get-started\/\">https:\/\/docs.influxdata.com\/influxdb\/v2.4\/get-started\/<\/a><\/p>\n\n\n\n<p>In short you have to go to UI and there in buckets create a new bucket. The you have to API Token and create a token there.<\/p>\n\n\n\n<p>InfluxDB UI is avalaible on port 8086<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">telegraf<\/h2>\n\n\n\n<p>Telegraf is used to transport data from mosqutto to influx db<\/p>\n\n\n\n<p>I used version 1.24.2<\/p>\n\n\n\n<p>This has the most complicated configuration of all<\/p>\n\n\n\n<p>Path i have used are:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\/data\/telegraph<\/li>\n<\/ul>\n\n\n\n<p>At that path you have to put your configuration file telegraf.conf<\/p>\n\n\n\n<p>First you have to configure output plugin. Change values to fit your system<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;&#91;outputs.influxdb_v2]]\nhttp:&#47;&#47;InfluxDB_URL:8086\ntoken = \"TOKEN_FOR_INFLUX_DB\"\norganization = \"YOUR_ORGANIZATION\"\nbucket = \"YOUR_BUCKET\"<\/code><\/pre>\n\n\n\n<p>Then you have to configure input plugin<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;&#91;inputs.mqtt_consumer]]\n        servers = &#91;\"tcp:\/\/MOSQUITTO_URL:1883\"]\n        topics = &#91; \"solar\/#\" ]\n        qos = 0\n        connection_timeout = \"30s\"\n        data_format = \"value\"\n        data_type = \"float\"<\/code><\/pre>\n\n\n\n<p>after this you can start telegraf container with<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker run \\\n  -v \/data\/telegraph:\/etc\/telegraf \\\n  -p 8094:8094 \\\n  -p 8125:8125 \\\n  -p 8092:8092\/udp \\\n  telegraf:1.24.2<\/code><\/pre>\n\n\n\n<p>After this telegraf should start and send data to influxdb. And in some time you can configure nice grafs<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Dashboard creation<\/h2>\n\n\n\n<p>You can to DataExplorer. There you have to select bucket that you created, in my case solar, then mqqt_consumer and everything else and data should be there. Take a look at screenshot.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Conclusion<\/h1>\n\n\n\n<p>After this is completed, you have a decent system where you can monitor and store data about you Solar Power Plant.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"612\" src=\"https:\/\/www.zecevic-ninja.com\/wp-content\/uploads\/2022\/11\/image-1-1024x612-1.png\" alt=\"\" class=\"wp-image-40\" srcset=\"https:\/\/www.zecevic-ninja.com\/wp-content\/uploads\/2022\/11\/image-1-1024x612-1.png 1024w, https:\/\/www.zecevic-ninja.com\/wp-content\/uploads\/2022\/11\/image-1-1024x612-1-300x179.png 300w, https:\/\/www.zecevic-ninja.com\/wp-content\/uploads\/2022\/11\/image-1-1024x612-1-768x459.png 768w, https:\/\/www.zecevic-ninja.com\/wp-content\/uploads\/2022\/11\/image-1-1024x612-1-920x550.png 920w, https:\/\/www.zecevic-ninja.com\/wp-content\/uploads\/2022\/11\/image-1-1024x612-1-230x137.png 230w, https:\/\/www.zecevic-ninja.com\/wp-content\/uploads\/2022\/11\/image-1-1024x612-1-350x209.png 350w, https:\/\/www.zecevic-ninja.com\/wp-content\/uploads\/2022\/11\/image-1-1024x612-1-480x287.png 480w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>I have here developed nothing i have just put all pieces together and connected everything to get everything working.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Motivation I just bought Solar panel set. And i wanted to monitor everything, but looking at prices of monitoring equipment costs 150 [&hellip;]<\/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-35","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.zecevic-ninja.com\/index.php?rest_route=\/wp\/v2\/posts\/35","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zecevic-ninja.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zecevic-ninja.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zecevic-ninja.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zecevic-ninja.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=35"}],"version-history":[{"count":2,"href":"https:\/\/www.zecevic-ninja.com\/index.php?rest_route=\/wp\/v2\/posts\/35\/revisions"}],"predecessor-version":[{"id":41,"href":"https:\/\/www.zecevic-ninja.com\/index.php?rest_route=\/wp\/v2\/posts\/35\/revisions\/41"}],"wp:attachment":[{"href":"https:\/\/www.zecevic-ninja.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=35"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zecevic-ninja.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=35"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zecevic-ninja.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=35"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}