Telegram Notification IF LAN IP CHANGED

ropske
Posts: 311
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: Telegram Notification IF LAN IP CHANGED

Post by ropske » Monday 26 December 2016 0:35

i have made a php file called version.php

Code: Select all

<?php

phpinfo();

?>
and this works, so php is working

ropske
Posts: 311
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: Telegram Notification IF LAN IP CHANGED

Post by ropske » Monday 26 December 2016 1:26

my token is correctly and userid also, because when i enter this
https://api.telegram.org/123456789/send ... 9&text=wie ben jij

then i'm receiving this on my telegram bot

can someone show me maybe how to use this telegram.php ?

thanks

User avatar
sincze
Posts: 940
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi
Domoticz version: 4.9700
Location: Netherlands
Contact:

Re: Telegram Notification IF LAN IP CHANGED

Post by sincze » Monday 26 December 2016 2:49

ropske wrote:will it also work with:
PHP Version
5.5.22

?
i have this one installed in my nas and if i want to run the telegram.php
i'm getting this error:

HTTP 500-fout
Dat is vreemd... deze pagina kan niet worden weergegeven door de website
seems something is wrong with your .php file, you might want to check the source vice php checker??
to see if you might have a typo.
http://phpcodechecker.com/
Using Pass2php since 2016-12
LAN: RFLink, P1-Port, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266, Xiaomi Gateway
Solar: Omnik Inverter, PVOutput
Video: Kodi clients with Harmony HUB
Sensors: You name it I probably got 1.

ropske
Posts: 311
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: Telegram Notification IF LAN IP CHANGED

Post by ropske » Monday 26 December 2016 11:38

i just copied the code from you:

Code: Select all

#!/usr/bin/php
<?php error_reporting(E_ALL);ini_set("display_errors","on");
$silent=true;$type=NULL;$to=NULL;
if(isset($_REQUEST['silent']))$silent=$_REQUEST['silent'];
if(isset($_REQUEST['text'])){$type='text';$content=$_REQUEST['text'];}
if(isset($_REQUEST['photo'])){$type='photo';$content=$_REQUEST['photo'];}
if(isset($_REQUEST['video'])){$type='video';$content=$_REQUEST['video'];$silent=true;}
if(isset($_REQUEST['to']))$to=$_REQUEST['to'];
if($to=='Wife')$telegramchatid=12345678;
elseif($to=='channel')$telegramchatid=-1234567890123;
else $telegramchatid=87654321;
if(!empty($argv[1])&&!empty($argv[2])){$type=$argv[1];$content=$argv[2];}
if(!empty($argv[1])&&$argv[1]=="snapshot") {$type='photo';$content = "/run/pikrellcam/mjpeg.jpg";$silent=true;}
if(isset($type)&&isset($content)){
    $bot_url="https://api.telegram.org/bot123592115:A2EZ-xCRhO-RBf2qICiJs8q2A_2YIr1irxI/";
    if($type=="text"){$url=$bot_url."sendMessage?chat_id=".$telegramchatid;$post_fields=array('chat_id'=>$telegramchatid,'text'=>$content,'disable_notification'=>$silent);}
    elseif($type=="photo"){$url=$bot_url."sendPhoto?chat_id=".$telegramchatid;$post_fields=array('chat_id'=>$telegramchatid,'photo'=>new CURLFile(realpath($content)),'disable_notification'=>true);}
    elseif($type=="video"){$url=$bot_url."sendVideo?chat_id=".$telegramchatid;$post_fields=array('chat_id'=>$telegramchatid,'video'=>new CURLFile(realpath($content)),'disable_notification'=>true);}
    $ch=curl_init();curl_setopt($ch,CURLOPT_HTTPHEADER,array("Content-Type:multipart/form-data"));curl_setopt($ch,CURLOPT_URL,$url);curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);curl_setopt($ch,CURLOPT_POSTFIELDS,$post_fields);
    for($x=1;$x<=100;$x++){
        $result=json_decode(curl_exec($ch),true);
        if($result['ok']===true)break;
        sleep($x*3);
    }
}
 
but when i enter this in http://phpcodechecker.com/ i'm getting indeed some errors.

PHP Syntax Check: Parse error: syntax error, unexpected '$telegramchatid' (T_VARIABLE) in your code on line 10
else $telegramchatid=123456789;
PHP Syntax Check: Errors parsing your code

when i change to this:
else ($telegramchatid=123456789);
it's ok, but then the next error comes...

User avatar
sincze
Posts: 940
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi
Domoticz version: 4.9700
Location: Netherlands
Contact:

Re: Telegram Notification IF LAN IP CHANGED

Post by sincze » Monday 26 December 2016 12:05

ropske wrote:i just copied the code from you:

but when i enter this in http://phpcodechecker.com/ i'm getting indeed some errors.

PHP Syntax Check: Parse error: syntax error, unexpected '$telegramchatid' (T_VARIABLE) in your code on line 10
else $telegramchatid=123456789;
PHP Syntax Check: Errors parsing your code

when i change to this:
else ($telegramchatid=123456789);
it's ok, but then the next error comes...
A well I had to modify that code a bit as well to have it work without any problems on my setup. This is my telegram.php. Credits ofcourse go to the original writer :D

Code: Select all

#!/usr/bin/php
<?php
error_reporting(E_ALL);ini_set("display_errors", "on");
$silent=false;$type='';
if(isset($_REQUEST['silent'])) $silent = $_REQUEST['silent'];
if(isset($_REQUEST['text'])) {$type='text';$content = $_REQUEST['text'];}
if(isset($_REQUEST['photo'])) {$type='photo';$content = $_REQUEST['photo'];}
if(isset($_REQUEST['video'])) {$type='video';$content = $_REQUEST['video'];$silent=true;}
if(!empty($argv[1])&&!empty($argv[2])) {$type=$argv[1];$content = $argv[2];}
//if(!empty($argv[1])&&$argv[1]=="snapshot") {$type='photo';$content = "/var/tmp/snapshot1.jpg";$silent=true;}
echo '<pre>REQUEST=';print_r($_REQUEST);echo '</pre>';

if(isset($type)&&isset($content)) {

	echo 'Type = '.$type.'<br/>Content = '.$content.'<br/>';
	
	$telegrambot='123456789:AA_______________________________poQ';
	$telegramchatid=-1111222233334;
	
	$bot_url    = "https://api.telegram.org/bot$telegrambot/";
	
	if($type=="text") {
		$url        = $bot_url . "sendMessage?chat_id=" . $telegramchatid ;
		$post_fields = array('chat_id'   => $telegramchatid,
			'text'     => $content,
			'disable_notification' => $silent
		);
	}
	else if($type=="photo") {
		$url        = $bot_url . "sendPhoto?chat_id=" . $telegramchatid ;
		$post_fields = array('chat_id'   => $telegramchatid,
			'photo'     => new CURLFile(realpath($content)),
			'disable_notification' => true
		);
	}
	else if($type=="video") {
		$url        = $bot_url . "sendVideo?chat_id=" . $telegramchatid ;
		$post_fields = array('chat_id'   => $telegramchatid,
			'video'     => new CURLFile(realpath($content)),
			'disable_notification' => true
		);
	}
	//echo 'URL = '.$url.'<br/>';
	//echo '<pre>post_fields=';print_r($post_fields);echo '</pre>';
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_HTTPHEADER, array(
			"Content-Type:multipart/form-data"
		));
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
		$output = json_decode(curl_exec($ch),true);
		
	//echo '<pre>Output=';print_r($output);echo '</pre>';



}
The problem I had was with line

Code: Select all

//if(!empty($argv[1])&&$argv[1]=="snapshot") {$type='photo';$content = "/var/tmp/snapshot1.jpg";$silent=true;}
Had to comment that out of the way. This code will compile without errors on PHP Code Checker.
Using Pass2php since 2016-12
LAN: RFLink, P1-Port, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266, Xiaomi Gateway
Solar: Omnik Inverter, PVOutput
Video: Kodi clients with Harmony HUB
Sensors: You name it I probably got 1.

ropske
Posts: 311
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: Telegram Notification IF LAN IP CHANGED

Post by ropske » Monday 26 December 2016 12:13


ropske
Posts: 311
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: Telegram Notification IF LAN IP CHANGED

Post by ropske » Monday 26 December 2016 12:25

because it's still not working :(

User avatar
sincze
Posts: 940
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi
Domoticz version: 4.9700
Location: Netherlands
Contact:

Re: Telegram Notification IF LAN IP CHANGED

Post by sincze » Monday 26 December 2016 13:09

ropske wrote:because it's still not working :(
assuming you configured your webserver correctly (mine is running on default port 80 not 5000) the command would be:

Code: Select all

http://192.168.2.10/php/telegram.php?text=Reboot_MQX
as you can see my telegram.php is not located in the root of the www directory of the webserver, but in sub directory called php.
good luck. you now have all the pieces :D
Using Pass2php since 2016-12
LAN: RFLink, P1-Port, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266, Xiaomi Gateway
Solar: Omnik Inverter, PVOutput
Video: Kodi clients with Harmony HUB
Sensors: You name it I probably got 1.

ropske
Posts: 311
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: Telegram Notification IF LAN IP CHANGED

Post by ropske » Monday 26 December 2016 13:27

i cannot change my port :(
i have a zyxell nas 540
maybe it is something at my nas-server i need to setup.
i better bought a synology it seems

User avatar
sincze
Posts: 940
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi
Domoticz version: 4.9700
Location: Netherlands
Contact:

Re: Telegram Notification IF LAN IP CHANGED

Post by sincze » Monday 26 December 2016 13:31

ropske wrote:i cannot change my port :(
i have a zyxell nas 540
maybe it is something at my nas-server i need to setup.
i better bought a synology it seems
I don't use synology for this.
Any webserver will do. APACHE / NGINX.
Using Pass2php since 2016-12
LAN: RFLink, P1-Port, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266, Xiaomi Gateway
Solar: Omnik Inverter, PVOutput
Video: Kodi clients with Harmony HUB
Sensors: You name it I probably got 1.

ropske
Posts: 311
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: Telegram Notification IF LAN IP CHANGED

Post by ropske » Monday 26 December 2016 19:14

lol, seems this 'section' on my nas is not supporting php
need to check how to activate it on published sites

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest