Water tank level (from other webserver)
Moderator: leecollings
-
- Posts: 60
- Joined: Friday 01 June 2018 20:32
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Water tank level (from other webserver)
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??
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??
- Attachments
-
- picture of tank level
- tanklevel.png (81.18 KiB) Viewed 3967 times
- Egregius
- Posts: 2592
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Water tank level (from other webserver)
Can’t be that hard. Can you post the source code of the page?
-
- Posts: 60
- Joined: Friday 01 June 2018 20:32
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Water tank level (from other webserver)
<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?
is this what you need?
- Egregius
- Posts: 2592
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Water tank level (from other webserver)
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));
}
?>

-
- Posts: 60
- Joined: Friday 01 June 2018 20:32
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Water tank level (from other webserver)
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?
As I wrote before, I'm new to this and not a programmer,
Where shall I place the code?
- Egregius
- Posts: 2592
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Water tank level (from other webserver)
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
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
-
- Posts: 60
- Joined: Friday 01 June 2018 20:32
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Water tank level (from other webserver)
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...
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...
- Egregius
- Posts: 2592
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Water tank level (from other webserver)
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"
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"
-
- Posts: 60
- Joined: Friday 01 June 2018 20:32
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Water tank level (from other webserver)
ok..
i don´t think i have all information
i need to install php first i think? apache? that runs the tanklevel?
i don´t think i have all information
i need to install php first i think? apache? that runs the tanklevel?
- Egregius
- Posts: 2592
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Water tank level (from other webserver)
You can just install php without webserver
-
- Posts: 60
- Joined: Friday 01 June 2018 20:32
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Water tank level (from other webserver)
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!
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!
- Attachments
-
- Screenshot (5).png (175.57 KiB) Viewed 3795 times
- Egregius
- Posts: 2592
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Water tank level (from other webserver)
I think you screwed line 7.
You're running domoticz on Windows?
You're running domoticz on Windows?
-
- Posts: 60
- Joined: Friday 01 June 2018 20:32
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Water tank level (from other webserver)
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.
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.
- Egregius
- Posts: 2592
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Water tank level (from other webserver)
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.
That would be the best option.
And it's much better to post code in code blocks on the forum.
-
- Posts: 60
- Joined: Friday 01 June 2018 20:32
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Water tank level (from other webserver)
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?
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?
- Egregius
- Posts: 2592
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Water tank level (from other webserver)
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.
Please post your complete code in a code block and how you execute it together with the output.
-
- Posts: 60
- Joined: Friday 01 June 2018 20:32
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Water tank level (from other webserver)
i get more confused, do i have to deal with ipv6 addresses?
what and where shall i correct
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
- Egregius
- Posts: 2592
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Water tank level (from other webserver)
No, just adjust line 7:
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://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));
}
?>
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));
}
?>
-
- Posts: 60
- Joined: Friday 01 June 2018 20:32
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Water tank level (from other webserver)
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
i know it is reading because when tanklevel was offline i got error on line 2
- Attachments
-
- Screenshot (7).png (173.27 KiB) Viewed 3688 times
- Egregius
- Posts: 2592
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Water tank level (from other webserver)
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));
}
?>
Who is online
Users browsing this forum: No registered users and 1 guest