Page 1 of 3
Water tank level (from other webserver)
Posted: Friday 01 June 2018 22:14
by Tarzan737
Hello, im new to domoticz,
i have built an irrigation system with denkovi hardware and a tanklevel measuring with arduino.
the tanklevel have a kind of simple webserver that i can reach from ip or dynamic dns (no ip) when not at home. i will try to upload picture.
is it possible to show this in domoticz as well??
Re: Water tank level (from other webserver)
Posted: Friday 01 June 2018 22:57
by Egregius
Can’t be that hard. Can you post the source code of the page?
Re: Water tank level (from other webserver)
Posted: Friday 01 June 2018 23:20
by Tarzan737
<html><body><head><meta http-equiv="refresh" content="60"></head><table cellspacing="0" cellpadding="0" width=100% border="0" style="color:#00979d;font-size:30px;font-family:Verdana"><td><img src="data:image/gif;base64,R0lGODlhRAABAKEAAAAAAACXnv///wAAACH+EUNyZWF0ZWQgd2l0aCBHSU1QACwAAAAARAABAAACCJSPqQfr/GIqADs=" width="102" height="10"></td></tr><td><img src="data:image/gif;base64,R0lGODlhRAACAKECAAAAAACXnv///////ywAAAAARAACAAACERSOqXviD2NklBqJs968P1AAADs=" width="102" height="4"></td></tr><td><img src="data:image/gif;base64,R0lGODdhRgACAIABAAAAAP///ywAAAAARgACAAACDUSOqcvtDw8wsdpbQQEAOw==" width="102" height="60"></td></tr><td><img src="data:image/gif;base64,R0lGODdhRgACAKECAAAAAACXnv///////ywAAAAARgACAAACHIR+gbmi+1BksE1nswAghi+BieiQn2em6BoqQAEAOw=="width="102" height="3"></td></tr><td><img src="data:image/gif;base64,R0lGODdhRgACAIACAAAAAACXniwAAAAARgACAAACDUSOqcvtDw8wsdpbQQEAOw==" width="102" height="60"></td></tr><td><img src="data:image/gif;base64,R0lGODdhRAACAKECAAAAAACXnv///////ywAAAAARAACAAACEESOqcvtD4EAtNqLs968iwIAOw==" width="102" height="4"></td></tr><td><span style="color:#000000;font-size:15px">CONTAINER 1 </span><br>50 %<td></tr></body></html>
is this what you need?
Re: Water tank level (from other webserver)
Posted: Saturday 02 June 2018 8:43
by Egregius
Code: Select all
<?php
$data=file_get_contents('http://192.168.0.12/tanklevl1');
$data=strbefore($data,'%');
$idx=123;
$nvalue=0;
$svalue=$data;
file_get_contents('http://[::1]:8080/json.htm?type=command¶m=udevice&idx='.$idx.'&nvalue='.$nvalue.'&svalue='.$svalue);
function strafter($string,$substring){
$pos=strpos($string,$substring);
if($pos===false)return $string;
else return(substr($string,$pos+strlen($substring)));
}
function strbefore($string,$substring){
$pos=strpos($string,$substring);
if($pos===false)return $string;
else return(substr($string,0,$pos));
}
?>
the strafter and strbefore functions are pretty powerfull to work with sources from websites. I even grab movie details from IMDb with those

Re: Water tank level (from other webserver)
Posted: Saturday 02 June 2018 10:24
by Tarzan737
Hi! Thanks! Looks like you have written a code?
As I wrote before, I'm new to this and not a programmer,
Where shall I place the code?
Re: Water tank level (from other webserver)
Posted: Saturday 02 June 2018 13:26
by Egregius
You put the code in a file, for example /home/pi/scripts/watertank.php
As I think the level doesn't change that much execute the script from cron
*/10 * * * * * /usr/bin/php /home/pi/scripts/watertank.php
That would execute the script every 10 minutes. If that's to often you can use this for every hour:
0 * * * * /usr/bin/php /home/pi/scripts/watertank.php
Re: Water tank level (from other webserver)
Posted: Saturday 02 June 2018 19:24
by Tarzan737
thanks...
but i dont think it´s that easy that i thought, i just found a program to copy my file from windows to pi/domotics
in my case i think domoticz/scripts/watertank.php
i havent solved this cron thing yet, i think it´s just to run it automatically right?
is it any chance to try the script in domoticz manually first?
where will the tank level show up? what page? and do i have to set up a switch with script or something?
many questions i know,im not that smart...
Re: Water tank level (from other webserver)
Posted: Sunday 03 June 2018 8:13
by Egregius
You need to add a dummy device for it. I would think a percentage device, not sure. Note the idx of that device and change the script accordingly.
You also need to set the right ip address and port of domoticz.
Then you can test the script by running "/usr/bin/php /home/pi/scripts/watertank.php" in shell.
If it works you can add the cron line with "sudo crontab -e"
Re: Water tank level (from other webserver)
Posted: Sunday 03 June 2018 14:48
by Tarzan737
ok..
i don´t think i have all information
i need to install php first i think? apache? that runs the tanklevel?
Re: Water tank level (from other webserver)
Posted: Sunday 03 June 2018 17:47
by Egregius
You can just install php without webserver
Re: Water tank level (from other webserver)
Posted: Sunday 03 June 2018 20:41
by Tarzan737
Thank you for your help!
but i don´t think i can manage to make it work, i just don´t have the skills..
i gave it a try and installed xampp on my windows computer to try to run the script, but i get this message..
and then i know my waterlevel/arduino uses port 80 and i think xampp do the same, tried to change in xampp but it still says port 80
anyway thank you!
Re: Water tank level (from other webserver)
Posted: Sunday 03 June 2018 21:42
by Egregius
I think you screwed line 7.
You're running domoticz on Windows?
Re: Water tank level (from other webserver)
Posted: Sunday 03 June 2018 22:32
by Tarzan737
No domoticz are on Raspberry pi (can't I use PHP from Windows/another computer with webbserver just to run the script?) Anyways I tried domoticz on a win computer to! Yepp but I don't know what I screwed up, probably something with IP?
This is how I thought it should be
file_get_contents('
http://192.168.0.14:8080/json.htm?type= ... ='.$svalue);
My domoticz IP (pi) is 192.168.0.14
Arduino 192.168.0.12
And I changed idx to correct as you wrote.
Re: Water tank level (from other webserver)
Posted: Sunday 03 June 2018 22:48
by Egregius
Why didn't you just install php on the pi?
That would be the best option.
And it's much better to post code in code blocks on the forum.
Re: Water tank level (from other webserver)
Posted: Tuesday 05 June 2018 17:12
by Tarzan737
Hi, couldn give up,
i installed php on pi but still get this error in line 7, can you tell me how to write the line if i have ip 192.168.0.14:8080 ?
should this [::1] be together in line somewhere?
Re: Water tank level (from other webserver)
Posted: Tuesday 05 June 2018 22:09
by Egregius
No, ::1 is the ipv6 address for localhost.
Please post your complete code in a code block and how you execute it together with the output.
Re: Water tank level (from other webserver)
Posted: Wednesday 06 June 2018 9:17
by Tarzan737
i get more confused, do i have to deal with ipv6 addresses?
Code: Select all
<?php
$data=file_get_contents('http://192.168.0.12/tanklevl1');
$data=strbefore($data,'%');
$idx=33;
$nvalue=0;
$svalue=$data;
file_get_contents('http://[::1]192.168.0.14:8080/json.htm?type=command¶m=udevice&idx='.$idx.'&nvalue='.$nvalue.'&svalue='.$svalue);
function strafter($string,$substring){
$pos=strpos($string,$substring);
if($pos===false)return $string;
else return(substr($string,$pos+strlen($substring)));
}
function strbefore($string,$substring){
$pos=strpos($string,$substring);
if($pos===false)return $string;
else return(substr($string,0,$pos));
}
?>
what and where shall i correct
Re: Water tank level (from other webserver)
Posted: Wednesday 06 June 2018 12:27
by Egregius
No, just adjust line 7:
Code: Select all
<?php
$data=file_get_contents('http://192.168.0.12/tanklevl1');
$data=strbefore($data,'%');
$idx=33;
$nvalue=0;
$svalue=$data;
file_get_contents('http://192.168.0.14:8080/json.htm?type=command¶m=udevice&idx='.$idx.'&nvalue='.$nvalue.'&svalue='.$svalue);
function strafter($string,$substring){
$pos=strpos($string,$substring);
if($pos===false)return $string;
else return(substr($string,$pos+strlen($substring)));
}
function strbefore($string,$substring){
$pos=strpos($string,$substring);
if($pos===false)return $string;
else return(substr($string,0,$pos));
}
?>
But if you're running this on the same Pi as Domoticz is running it's better to use localhost:
Code: Select all
<?php
$data=file_get_contents('http://192.168.0.12/tanklevl1');
$data=strbefore($data,'%');
$idx=33;
$nvalue=0;
$svalue=$data;
file_get_contents('http://127.0.0.1:8080/json.htm?type=command¶m=udevice&idx='.$idx.'&nvalue='.$nvalue.'&svalue='.$svalue);
function strafter($string,$substring){
$pos=strpos($string,$substring);
if($pos===false)return $string;
else return(substr($string,$pos+strlen($substring)));
}
function strbefore($string,$substring){
$pos=strpos($string,$substring);
if($pos===false)return $string;
else return(substr($string,0,$pos));
}
?>
Re: Water tank level (from other webserver)
Posted: Wednesday 06 June 2018 18:17
by Tarzan737
But i get the same error as if i use the correct ip adress?
i know it is reading because when tanklevel was offline i got error on line 2
Re: Water tank level (from other webserver)
Posted: Wednesday 06 June 2018 22:25
by Egregius
OMG, somewhere the 3th line got lost
Code: Select all
<?php
$data=file_get_contents('http://192.168.0.12/tanklevl1');
$data=strafter($data,'</span><br>');
$data=strbefore($data,'%');
$idx=33;
$nvalue=0;
$svalue=$data;
file_get_contents('http://127.0.0.1:8080/json.htm?type=command¶m=udevice&idx='.$idx.'&nvalue='.$nvalue.'&svalue='.$svalue);
function strafter($string,$substring){
$pos=strpos($string,$substring);
if($pos===false)return $string;
else return(substr($string,$pos+strlen($substring)));
}
function strbefore($string,$substring){
$pos=strpos($string,$substring);
if($pos===false)return $string;
else return(substr($string,0,$pos));
}
?>