Web page to reset the counter
authorNirgal <contact_ampy@nirgal.com>
Sun, 13 Oct 2019 23:58:31 +0000 (23:58 +0000)
committerNirgal <contact_ampy@nirgal.com>
Sun, 13 Oct 2019 23:58:31 +0000 (23:58 +0000)
README.rst
countercron [deleted file]
html/ampy.inc.php
html/counterset.php [new file with mode: 0644]

index fd1f1c201c2ca3148e9e947bf0dc0f43d1a46166..52ef1dd6e4569edfbe01937391fe843d3a0ed613 100644 (file)
@@ -45,6 +45,7 @@ Ampy requires permission to use the sound card. It's recommanded to create a ded
 
    addgroup --system ampy  # create a dedicated group
    adduser --system --ingroup ampy --home /var/lib/ampy --disabled-password --disabled-login ampy
+   chmod g+ws /var/lib/ampy/  # group can write, sticky group
    adduser ampy audio  # ampy can use audio
    adduser www-data ampy  # httpd in group ampy
 
@@ -115,6 +116,10 @@ Calibration
 
 You'll need to adjust VOLUME_CONSTANT in run.py so that you get the correct voltage value.
 
+Starting and stoping a powerfull apliance you know the consuptium of, should give you a good start.
+
+Later on, you can adjust the value based on your legal counter. See bellow.
+
 Autostart
 ---------
 
@@ -149,10 +154,9 @@ Then add something like that in your apache configuration file::
 Counter initialization
 ----------------------
 
-If you have a regular electric meter::
+Point your browser to counterset.php.
 
-   echo "123456" > /var/lib/ampy/counter
-   chown ampy: /var/lib/ampy/counter
+You should do that from time to time. It will show you how off the system is. You can then adjust your VOLUME_CONSTANT in run.py.
 
 
 Copyright
diff --git a/countercron b/countercron
deleted file mode 100755 (executable)
index 635f011..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/usr/bin/php -f
-<?php
-/*
- * This scripts updates the "counter" file based on average consumption and
- * last known value.
- *
- * This should optimize computations.
- *
- * It is not used!
- */
-include("html/config.php");
-include("html/ampy.inc.php");
-
-ampy_flush_rrd_daemon();
-
-$new_counter = ampy_get_counter();
-ampy_set_counter($new_counter);
-?>
index 4c9828ffdbfb057ee4ae78be79bafeb77f4b7385..947fa665448c477fe44a53af1aca6b90854c2d03 100644 (file)
@@ -16,6 +16,7 @@ function ampy_flush_rrd_daemon() {
 function ampy_set_counter($newcounter) {
        file_put_contents(COUNTERFILE.'.new', $newcounter);
        rename(COUNTERFILE.'.new', COUNTERFILE);
+       trigger_error("Counter was reset to $newcounter", E_USER_WARNING);
 }
 
 /*
diff --git a/html/counterset.php b/html/counterset.php
new file mode 100644 (file)
index 0000000..b84fcfc
--- /dev/null
@@ -0,0 +1,60 @@
+<?php
+require_once("ampy.inc.php");
+
+if (!empty($_POST['counter'])) {
+       ampy_set_counter($_POST['counter']);
+       echo("New value recorded!");
+}
+
+$counter_mtime = ampy_get_old_counter_info();
+$counter = $counter_mtime[0];
+$mtime = $counter_mtime[1];
+$kwh_since = ampy_get_kwh_since($mtime);
+?>
+
+<script>
+timestamp=<?php echo($mtime); ?>*1000;
+counter=<?php echo($counter); ?>;
+kwh_since=<?php echo($kwh_since); ?>;
+
+function userchanged(value) {
+       value=parseFloat(value);
+       valuechange = value-counter;
+       document.getElementById('valuechange').innerHTML = valuechange;
+       errorvalue = (valuechange-kwh_since)/kwh_since;
+       errorvalue = (errorvalue*100).toFixed(2);
+       if (errorvalue > 0)
+               errorvalue = '+' + errorvalue;
+       document.getElementById('errorvalue').innerHTML = errorvalue + '%';
+}
+
+</script>
+
+<h1>Counter set</h1>
+<fieldset>
+       <legend>Last known value</legend>
+
+       Time: <script>document.write(new Date(timestamp));</script><br>
+       Value: <?php echo($counter); ?> kWh<br>
+</fieldset>
+
+<form method=post>
+<fieldset>
+       <legend>New value</legend>
+
+       <input name=counter oninput="userchanged(this.value);" value="<?php echo($counter+$kwh_since); ?>">
+       <input type=submit value=Save>
+</fieldset>
+</form>
+
+<fieldset>
+       <legend>Error correction</legend>
+
+       Expected value: <script>document.write(counter+kwh_since);</script> kWh<br>
+       Expected value since last update: <script>document.write(kwh_since);</script> kWh<br>
+       Value since laste update: <span id=valuechange>N/A</span><br>
+       Error: <span id=errorvalue>N/A</span>
+</fieldset>
+
+<script>
+</script>