<p>Having some troubles to recover a "Volkszähler" system (server doesn't exists any more), I decided to build my own Smart Meter system,&nbsp; user friendly and simple to maintenance.</p>
<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&nbsp;Round Robin Database (RRD) file. The graph function of RRDtool is used to present this data to a human viewer via Web-Browser.</p>
<p><img class="alignnone size-full wp-image-754" src="https://johann.langhofer.net/wp-content/uploads/2021/04/Screenshot-2021-04-03-232926.jpg" alt="" width="1109" height="458"></p>
<p><strong>The hardware configuration: </strong>ESP32 -&gt;(WLAN)-&gt;RPI2</p>
<p>Software requirements (RPI): apache2, RRDtool, php7.3, php7.3-gd</p>

<!-- wp:paragraph -->
<p>Skipping the microcontroller part (data is sent with a simple http-request http://&lt;address-of-rpi&gt;/s0.php?data=&lt;counter1&gt;:&lt;counter2&gt;:&lt;counter3&gt;)  here are the software parts of the smartmeter:</p>
<!-- /wp:paragraph -->

<p><!--StartFragment--></p>

<!-- wp:paragraph -->
<p><strong>STEP 1:</strong> Defining the database (RRD):</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":767} -->
<figure class="wp-block-image"><img src="https://johann.langhofer.net/wp-content/uploads/2021/04/Screenshot-2021-04-04-002715.jpg" alt="" class="wp-image-767"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Each minute the powerline counter values are written into the database, Format: 'R:S:T'<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>
<!-- /wp:paragraph -->

<p><!--EndFragment--><strong>Step 2</strong>: Script to permanently update the database:</p>

<!-- wp:html -->
<?php
    shell_exec("rrdtool update power.rrd N:".$_GET['data']);
 ?>

<!-- /wp:html -->

<!-- wp:image {"id":765} -->
<figure class="wp-block-image"><img src="https://johann.langhofer.net/wp-content/uploads/2021/04/Screenshot-2021-04-04-002610.jpg" alt="" class="wp-image-765"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<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>
<!-- /wp:paragraph -->

<!-- wp:image {"id":763} -->
<figure class="wp-block-image"><img src="https://johann.langhofer.net/wp-content/uploads/2021/04/Screenshot-2021-04-04-002239.jpg" alt="" class="wp-image-763"/></figure>
<!-- /wp:image -->