Page 1 of 2

Getting water data via http

Posted: Sun Apr 26, 2020 9:15 am
by NevD

I have built a arduino UNO and ESP8266 system monitoring our water consumption. I can get water info via Chrome and via a small python file but have been unable to import into meterN.
I have edited as follows
import urllib2

elif sys.argv[1] == 'rwater': # Water & reset counter
# ser.write("rwater\n".encode("utf-8"))
# line = ser.readline(16).decode("utf-8")
water = urllib2.urlopen("").read()
My small python file on the meterN system uses exactly the same code to get "water" and returns
pi@raspberrypi /var/www/comapps $ sudo python

I get the same return info If I use Chrome and

It takes between 3 and 4 seconds to get the data
Using the test command "pooler water" I get it is configured wrong as (0*) is not valid, the correct format is 3(1234.5*)

I am at a loss as to the best way forward....

Re: Getting water data via http

Posted: Sun Apr 26, 2020 10:20 am
by jeanmarc
Hi Nev,
3-4" is pretty slow but i don't think it's a problem. Did you set a 'Unit' and correct 'Meter ID' for your meter ?
Also i think you should use pooler.php for your meter, since i guess your pulse counter reset after a surge.

Re: Getting water data via http

Posted: Sun Apr 26, 2020 11:39 am
by NevD
I am using your water/gas uno file ( with edits to configure and use the ESP8266-01 module). I have also a serial Arduino hard connected for Solar production and power consumption which I have had working since Nov 2013. My water sensor at 60ltrs/min outputs 288 pulses/min. I have accurate test measurements and get correct data when requested by my test python code to the same raspberry pi I have meterN on.
The uno script is outputing the format as I have noted before. I have tried putting this (in the UNO )my info = ("3(" + str_out + "*l/min)") to try and pick up what would be my meter No3 that didn't work either...and various other combinations :(
I was concerned about the time taken.... I will look at pooler, do I simply put my HTTP request at the $cmd line where "poolmeters rwater" is ?
Hope you are well where you are, here in Australia not so bad..

Re: Getting water data via http

Posted: Sun Apr 26, 2020 12:43 pm
by jeanmarc fetch the counting data during the 5' sample, then reset.
pooler.php call to make a vitual meter from that, so the total counting always increase. (see the README inside pooler)

Judging from mN output 3(1234.5*), it seem like you have set a 'Meter ID' of 3 and no 'Unit'. If your app return water(0.00*l) it should be water as ID and l as unit (even though you can set it to whatever, mN won't mind of the unit).

Maybe enable debug, restart mN and check about errors, also take a look on your webserver error log, that might be informative.

I'am from Belgium, it's ok for me and my relatives, our country will ease 'restrictions' so i guess i won't be too bad.. I hope we'll pass all over it

Re: Getting water data via http

Posted: Sun Apr 26, 2020 12:53 pm
by jeanmarc
oh i rather see, it say (0*) :shock:
try this simple test.php

Code: Select all

$COMMAND = '';
$ID = 'water';

function isvalid($id, $datareturn) //  IEC 62056 data set structure
	$regexp = "/^$id\(.+\*.+\)$/i"; //ID(VALUE*UNIT)
	if (preg_match($regexp, $datareturn)) {
		$datareturn = preg_replace("/^$id\(/i", '', $datareturn, 1); // VALUE*UNIT)
		$datareturn = preg_replace("/\*.+\)$/i", '', $datareturn, 1); // VALUE
	} else {
		$datareturn = null;
	return $datareturn;

exec($COMMAND, $datareturn);
echo "data are $datareturn";

$val    = isvalid($ID, $datareturn);
echo "valid $datareturn";
did you do ? again on the README
- Make sure they are both executable via (chmod a+x pooler.php)
- Allow access the com. port to http user (eg usermod -aG uucp http)

- Make them system wide available
ln -s /path to/pooler.php /usr/bin/pooler
ln -s /path to/ /usr/bin/poolmeters
Do you use php >=7.4 ?

Re: Getting water data via http

Posted: Sun Apr 26, 2020 10:43 pm
by NevD
Thanks very much for the reply, and glad all ok for you..we are also starting to reduce restrictions.

I will go through what you have supplied and find out where my stupid mistakes are :) and let you know this evening my time.



Re: Getting water data via http

Posted: Mon Apr 27, 2020 6:23 am
by jeanmarc
No worries, the more important is to learn from mistakes :)
Tell me if you still have issue and take care

Re: Getting water data via http

Posted: Mon Apr 27, 2020 7:20 am
by NevD
I ended up with two main problems one I found after reading the instructions :) AND noting what you said about the units....I had not configured the meter completely just tried the command. When corrected it reported format acceptable....but I could still not get the value into meterN.
As I reported before my test file and requests from mac and phone using chrome would return for example "water(10.02*l)" but if i ran "pooler water" as a test from the terminal prompt I would get 3(0*l) ( my meter number is 3), and when meterN called it I could see in my serial monitor the data being sent was OK but a value of 0 was entered into the csv file.
I could not get your php file to work..safari seemed to lock up chrome came back with a blank page...
Went for a walk......I then ran "poolmeters rwater" from the terminal prompt and it returned for example "water(10.02*l)", I then used this as the command in meterN and was promptly told wrong format need "3(etc)".
I formated the data sent from the arduino uno to the format "3(0.00*l)" and everything came to life :)
In config for my meter No3 if I select water as the type the graph has + and - values so I selected sensor and it displays from zero up. The title for the graph says "Water(0.00 ltrs") and is not accumulating for the day it displays the 5 min average I am this correct or is this a function of how I am getting the data.
To get the last 15 day display to show the accumulated water I had to say it was a water type tick I wanted it included, then reselect sensor type. Sensor type would not allow me to select it to be included.
I have been wanting to monitor our house water for a long time, we have tank water storage no mains water at our place and to purchase water it is quite expensive here so getting an idea of daily and weekly consumption is important.

Thanks very much for the work you have done on meterN and 123.


Re: Getting water data via http

Posted: Mon Apr 27, 2020 8:06 am
by jeanmarc
There was a typo in the test.php, you can try it by terminal using "php test.php" to get all errors outputs.
I guess your give counting then reset the counter to zero, you then need to make a virutal meter from that using pooler.php.

You can setup a sensor but that won't fit your need, a sensor is for a value that vary (temperature, humidity..) but it's not a meter.

Re: Getting water data via http

Posted: Mon Apr 27, 2020 8:21 am
by NevD
Thanks very much I will investigate further and get the correct meter going.