Water tank level (from other webserver)

Tarzan737
Posts: 25
Joined: Friday 01 June 2018 20:32
Target OS: Raspberry Pi
Domoticz version:
Contact:

Water tank level (from other webserver)

Post by Tarzan737 » Friday 01 June 2018 22:14

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??
Attachments
tanklevel.png
picture of tank level
tanklevel.png (81.18 KiB) Viewed 1097 times

User avatar
Egregius
Posts: 2669
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Water tank level (from other webserver)

Post by Egregius » Friday 01 June 2018 22:57

Can’t be that hard. Can you post the source code of the page?

Tarzan737
Posts: 25
Joined: Friday 01 June 2018 20:32
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Water tank level (from other webserver)

Post by Tarzan737 » Friday 01 June 2018 23:20

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

User avatar
Egregius
Posts: 2669
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Water tank level (from other webserver)

Post by Egregius » Saturday 02 June 2018 8:43

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&param=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 ;)

Tarzan737
Posts: 25
Joined: Friday 01 June 2018 20:32
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Water tank level (from other webserver)

Post by Tarzan737 » Saturday 02 June 2018 10:24

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?

User avatar
Egregius
Posts: 2669
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Water tank level (from other webserver)

Post by Egregius » Saturday 02 June 2018 13:26

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

Tarzan737
Posts: 25
Joined: Friday 01 June 2018 20:32
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Water tank level (from other webserver)

Post by Tarzan737 » Saturday 02 June 2018 19:24

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

User avatar
Egregius
Posts: 2669
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Water tank level (from other webserver)

Post by Egregius » Sunday 03 June 2018 8:13

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"

Tarzan737
Posts: 25
Joined: Friday 01 June 2018 20:32
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Water tank level (from other webserver)

Post by Tarzan737 » Sunday 03 June 2018 14:48

ok..

i don´t think i have all information

i need to install php first i think? apache? that runs the tanklevel?

User avatar
Egregius
Posts: 2669
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Water tank level (from other webserver)

Post by Egregius » Sunday 03 June 2018 17:47

You can just install php without webserver

Tarzan737
Posts: 25
Joined: Friday 01 June 2018 20:32
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Water tank level (from other webserver)

Post by Tarzan737 » Sunday 03 June 2018 20:41

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!
Attachments
Screenshot (5).png
Screenshot (5).png (175.57 KiB) Viewed 972 times

User avatar
Egregius
Posts: 2669
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Water tank level (from other webserver)

Post by Egregius » Sunday 03 June 2018 21:42

I think you screwed line 7.
You're running domoticz on Windows?

Tarzan737
Posts: 25
Joined: Friday 01 June 2018 20:32
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Water tank level (from other webserver)

Post by Tarzan737 » Sunday 03 June 2018 22:32

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.

User avatar
Egregius
Posts: 2669
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Water tank level (from other webserver)

Post by Egregius » Sunday 03 June 2018 22:48

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.

Tarzan737
Posts: 25
Joined: Friday 01 June 2018 20:32
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Water tank level (from other webserver)

Post by Tarzan737 » Tuesday 05 June 2018 17:12

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?

User avatar
Egregius
Posts: 2669
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Water tank level (from other webserver)

Post by Egregius » Tuesday 05 June 2018 22:09

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.

Tarzan737
Posts: 25
Joined: Friday 01 June 2018 20:32
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Water tank level (from other webserver)

Post by Tarzan737 » Wednesday 06 June 2018 9:17

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&param=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

User avatar
Egregius
Posts: 2669
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Water tank level (from other webserver)

Post by Egregius » Wednesday 06 June 2018 12:27

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&param=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&param=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));
}
?>

Tarzan737
Posts: 25
Joined: Friday 01 June 2018 20:32
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Water tank level (from other webserver)

Post by Tarzan737 » Wednesday 06 June 2018 18:17

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
Attachments
Screenshot (7).png
Screenshot (7).png (173.27 KiB) Viewed 865 times

User avatar
Egregius
Posts: 2669
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Water tank level (from other webserver)

Post by Egregius » Wednesday 06 June 2018 22:25

OMG, somewhere the 3th line got lost :o

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&param=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));
}
?>

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest