Getting water data via http

NevD
Posts: 153
Joined: Tue Mar 11, 2014 12:22 am

Getting water data via http

Post by NevD » Sun Apr 26, 2020 9:15 am

jeanmarc

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 poolmeters.py as follows
import urllib2
then

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("http://192.168.0.81/rwater").read()
print(water)
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 water.py
water(0.00*l)

I get the same return info If I use Chrome and 192.168.0.81/rwater

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....

jeanmarc
Posts: 2130
Joined: Thu Aug 29, 2013 7:16 am

Re: Getting water data via http

Post by jeanmarc » Sun Apr 26, 2020 10:20 am

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.

NevD
Posts: 153
Joined: Tue Mar 11, 2014 12:22 am

Re: Getting water data via http

Post by NevD » Sun Apr 26, 2020 11:39 am

Hi
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..

jeanmarc
Posts: 2130
Joined: Thu Aug 29, 2013 7:16 am

Re: Getting water data via http

Post by jeanmarc » Sun Apr 26, 2020 12:43 pm

poolmeters.py fetch the counting data during the 5' sample, then reset.
pooler.php call poolmeters.py 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

jeanmarc
Posts: 2130
Joined: Thu Aug 29, 2013 7:16 am

Re: Getting water data via http

Post by jeanmarc » Sun Apr 26, 2020 12:53 pm

oh i rather see, it say (0*) :shock:
try this simple test.php

Code: Select all

<?php
$COMMAND = 'water.py';
$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 poolmeters.py 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/poolmeters.py /usr/bin/poolmeters
Do you use php >=7.4 ?

NevD
Posts: 153
Joined: Tue Mar 11, 2014 12:22 am

Re: Getting water data via http

Post by NevD » Sun Apr 26, 2020 10:43 pm

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.

Regards

Neville

jeanmarc
Posts: 2130
Joined: Thu Aug 29, 2013 7:16 am

Re: Getting water data via http

Post by jeanmarc » Mon Apr 27, 2020 6:23 am

No worries, the more important is to learn from mistakes :)
Tell me if you still have issue and take care

NevD
Posts: 153
Joined: Tue Mar 11, 2014 12:22 am

Re: Getting water data via http

Post by NevD » Mon Apr 27, 2020 7:20 am

jeanmarc
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 water.py 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 guessing...is 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.

Neville

jeanmarc
Posts: 2130
Joined: Thu Aug 29, 2013 7:16 am

Re: Getting water data via http

Post by jeanmarc » Mon Apr 27, 2020 8:06 am

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 water.py 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.

NevD
Posts: 153
Joined: Tue Mar 11, 2014 12:22 am

Re: Getting water data via http

Post by NevD » Mon Apr 27, 2020 8:21 am

Thanks very much I will investigate further and get the correct meter going.

Neville

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest