{"id":752,"date":"2021-04-03T23:28:35","date_gmt":"2021-04-03T21:28:35","guid":{"rendered":"https:\/\/johann.langhofer.net\/?p=752"},"modified":"2021-04-03T23:28:35","modified_gmt":"2021-04-03T21:28:35","slug":"simple-smart-meter-ssm-using-rapberry-pi-and-esp32","status":"publish","type":"post","link":"https:\/\/langhofer.org\/?p=752","title":{"rendered":"Simple Smart Meter (SSM) using Rapberry Pi and ESP32"},"content":{"rendered":"<p>Having some troubles to recover a &#8220;Volksz\u00e4hler&#8221; system (server doesn&#8217;t exists any more), I decided to build my own Smart Meter system,\u00a0 user friendly, small footprint and simple to maintenance.<\/p>\n<p><strong>The concept:<\/strong> S0 Impulses are counted via interrupt on a microcontroller (ESP32) and sent to a Web-server running on a Rasperry Pi. Every time, after 60 seconds, three counter values (for each phase of the power lines) are written into a\u00a0Round Robin Database (RRD) file. The graph function of RRDtool is used to present this data to a human viewer via Web-Browser.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-754\" src=\"https:\/\/langhofer.org\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-03-232926.jpg\" alt=\"\" width=\"1109\" height=\"458\" srcset=\"https:\/\/langhofer.org\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-03-232926.jpg 1109w, https:\/\/langhofer.org\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-03-232926-300x124.jpg 300w, https:\/\/langhofer.org\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-03-232926-1024x423.jpg 1024w, https:\/\/langhofer.org\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-03-232926-768x317.jpg 768w\" sizes=\"auto, (max-width: 1109px) 100vw, 1109px\" \/><\/p>\n<p><strong>The hardware configuration: <\/strong>ESP32 -&gt;(WLAN)-&gt;RPI2<\/p>\n<p><strong>Software requirements (RPI):<\/strong> apache2, RRDtool, php7.3, php7.3-gd<\/p>\n\n\n<p>Skipping the microcontroller part (data is sent with a simple http-request <em>http:\/\/&lt;address-of-rpi>\/s0.php?data=&lt;counter1>:&lt;counter2>:&lt;counter3><\/em>)  here are the steps and the software parts of the smart meter:<\/p>\n\n\n<p><!--StartFragment--><\/p>\n\n\n<p><strong>STEP 1:<\/strong> Defining the database (RRD):<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"280\" height=\"137\" src=\"https:\/\/langhofer.org\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-04-002715.jpg\" alt=\"\" class=\"wp-image-767\"\/><\/figure>\n\n\n\n<p>Each minute the power line counter values are written into the database, Format: &#8216;R:S:T&#8217;<br>There are three archives in this database: one for the original data (minutes)  holding the values for 10 days, one for reduced hour-values holding 18 months, and one for reduced daily-values holding 10 years.<\/p>\n\n\n<p><!--EndFragment--><strong>Step 2<\/strong>: Script to permanently update the database:<\/p>\n\n\n<?php\n    shell_exec(\"rrdtool update power.rrd N:\".$_GET['data']);\n ?>\n\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"546\" height=\"50\" src=\"https:\/\/langhofer.org\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-04-002610.jpg\" alt=\"\" class=\"wp-image-765\" srcset=\"https:\/\/langhofer.org\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-04-002610.jpg 546w, https:\/\/langhofer.org\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-04-002610-300x27.jpg 300w\" sizes=\"auto, (max-width: 546px) 100vw, 546px\" \/><\/figure>\n\n\n\n<p><strong>Step 3<\/strong>: Script to visualize the data: Call this script with three optional query parameters: start, end, step.  <strong>start<\/strong>: point where to begin viewing data i.e -1d -2M -4h, default 4h (4 hours).  <strong>end<\/strong>:  point where to stop viewing data (default now). <strong>step<\/strong>: resolution in seconds (default 60). <em>Example: http:\/\/&lt;rpi-address>\/data.php?start=-2d&amp;end=-1d<\/em><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"699\" height=\"347\" src=\"https:\/\/langhofer.org\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-04-002239.jpg\" alt=\"\" class=\"wp-image-763\" srcset=\"https:\/\/langhofer.org\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-04-002239.jpg 699w, https:\/\/langhofer.org\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-04-002239-300x149.jpg 300w\" sizes=\"auto, (max-width: 699px) 100vw, 699px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Having some troubles to recover a &#8220;Volksz\u00e4hler&#8221; system (server doesn&#8217;t exists any more), I decided to build my own Smart Meter system,\u00a0 user friendly, small footprint and simple to maintenance. The concept: S0 Impulses are counted via interrupt on a microcontroller (ESP32) and sent to a Web-server running on a Rasperry Pi. Every time, after &#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[19,50,56,57,59,71],"class_list":["post-752","post","type-post","status-publish","format-standard","hentry","category-allgemein","tag-esp32","tag-raspbarry-pi","tag-rpi2","tag-rrdtool","tag-smart-meter","tag-volkszahler"],"_links":{"self":[{"href":"https:\/\/langhofer.org\/index.php?rest_route=\/wp\/v2\/posts\/752","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/langhofer.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/langhofer.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/langhofer.org\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/langhofer.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=752"}],"version-history":[{"count":0,"href":"https:\/\/langhofer.org\/index.php?rest_route=\/wp\/v2\/posts\/752\/revisions"}],"wp:attachment":[{"href":"https:\/\/langhofer.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=752"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/langhofer.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=752"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/langhofer.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=752"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}