Pass2PHP

Moderator: leecollings

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

Re: Pass2PHP

Post by ropske »

got a stupid question, i need to install something more?

is mysqli standard included in php? or do i need to install this extra?
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

Correct, 4th is name of database.

Think you'll need a extra package like php-mysql or something. Google 'enable mysqli php' ;)
ropske
Posts: 483
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi / ODroid
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: Pass2PHP

Post by ropske »

ok, will search for this.

so Domitica is your databank and temperature is a tabel?l?
ropske
Posts: 483
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi / ODroid
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: Pass2PHP

Post by ropske »

strange, mysqli is installed now on my raspberry pi when i check phpinfo()

my mysql server is running on my nas 192.168.1.163
and when i make a php file on my raspberry pi with this:

Code: Select all

<?php
$con = mysqli_connect("192.168.1.163","username","password","tabel");
// Check connection
if (mysqli_connect_errno())
{
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
then i get this error:
Failed to connect to MySQL: Can't connect to MySQL server on '192.168.1.163' (111)
ropske
Posts: 483
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi / ODroid
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: Pass2PHP

Post by ropske »

i have also added a new user in my phpmyadmin configuration as you caan see in picture attached
and it has my raspberry pi as machine configured

don't know why it's not working to access my mysql database on my nas from a 'remote' computer inside my own network :roll:
Attachments
Naamloos.jpg
Naamloos.jpg (151.38 KiB) Viewed 2924 times
PatrickL
Posts: 2
Joined: Thursday 16 June 2016 22:31
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Pass2PHP

Post by PatrickL »

Look at your NAS ( I have a QNAP) if "activate TCP/IP networking" is enabled with port 3306 by your SQL server settings.
ropske
Posts: 483
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi / ODroid
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: Pass2PHP

Post by ropske »

Hi, thank you for your response.

You mean in 'phpMyAdmin setup' at my nas ?
or somewhere in nas settings?

Thank you
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

Leave the machine empty/open for testing, first get it working, then secure it.
PatrickL
Posts: 2
Joined: Thursday 16 June 2016 22:31
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Pass2PHP

Post by PatrickL »

Somewhere in NAS setting like PHP Server.
MyPhpAdmin is only a tool for databases and has nothing to do with setup and accessing databases, because phpmyadmin uses localhost.
ropske
Posts: 483
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi / ODroid
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: Pass2PHP

Post by ropske »

:lol: Finally got it working, pheww

needed to find the 'configuration' file where i can comment the bind 127.0.0.1

but didn't know where to begin searching this 'configuration file' on my nas as Zyxell nas540 is sooo documented (not!)

for other people wo are also interested, it's located here:
/i-data/0e4bb2e1/.PKG/PHP-MySQL-phpMyAdmin/etc/init.d/PHP-MySQL-phpMyAdmin

and when you open this file, you will find somewhere this:


#nice -n ${NICE_VALUE} ./bin/mysqld_safe --user=mysql --bind-address=127.0.0.1 &
nice -n ${NICE_VALUE} ./bin/mysqld_safe --user=mysql &


just comment the first one and add it again and delete the --bind-address=127.0.0.1

then reboot your nas540 and all is working ;)
ropske
Posts: 483
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi / ODroid
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: Pass2PHP

Post by ropske »

@Egregius: you are using this temperature data and state of 'brander' to chech the heating script?

Are you putting this data is some kind of a chart to have a better visual of the heating script?
Can this be found somewhere?

Thank you.
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

Should be this file: https://github.com/Egregius/PHP-Custom- ... r/temp.php

Temps are stored in 1 table every minute, each temp sensor is a column. Temps are stored with my cron script.
User avatar
sincze
Posts: 1299
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: Pass2PHP

Post by sincze »

Hi @Robske and @Egregius.

Just created 2 new functions for kodi integration :D
Maybe you can use them as well.
The first will send a notification to a Kodi machine. (notify_kodi)
The second will start a specific plugin in Kodi. In my case securitycam :D (kodi_addon)

Code: Select all

function notify_kodi($destination,$port,$subject,$msg)
{
    //EXAMPLE:     kodi_notify("192.168.1.10","8080","dit is het onderwerp","dit is het bericht");
    $params = array ('title'=> $subject, 'message'=> $msg);
    $string = array ('jsonrpc'=> "2.0",'method' => 'GUI.ShowNotification','params' => $params,'id' => "1");
    $params = json_encode($string);
    curl('http://'.$destination.':'.$port.'/jsonrpc?request='.urlencode($params));
}

function kodi_addon($destination,$port,$addon)
{
    //EXAMPLE:  kodi_addon("192.168.1.10","8080","script.securitycam");
    $params = array ('addonid' => $addon);
    $string = array ('jsonrpc'=> "2.0",'method' => 'Addons.ExecuteAddon','params' => $params,'id' => "1");
    $params = json_encode($string);
    curl('http://'.$destination.':'.$port.'/jsonrpc?request='.urlencode($params));    
}
I had to use the curl function because file_get_contents was waiting for an answer or so from kodi... Executed fine however did take a long time to complete. I used your old curl function and that was spot on.

I also bought some zwave powerplugs so I can monitor some power usage. @robske, tnx for inspiration. Now let's see what @Egregius already has in place for zwave in pass2php.

My girlriend uses NMA..

Code: Select all

function nma($event,$description)
{
    $postdata = http_build_query(
    array(
        'apikey'        => 'your_api_key_here',
        'application'   => 'Pass2PHP',
        'event'         => $event,
        'description'   => $description
        )
    );

    $opts = array('http' =>
        array(
            'method'  => 'POST',
            'header'  => 'Content-type: application/x-www-form-urlencoded',
            'content' => $postdata
        )
    );

    $context  = stream_context_create($opts);
    $result = file_get_contents('https://www.notifymyandroid.com/publicapi/notify?', false, $context);
    lg('NMA Notification'.$result);
}
A well as you can see this is still work in progress. :) :D
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

Nice to see new functions! Thanks for sharing them here ;)

What do you mean by 'let's see what Egregius has in place for zwave'?

My newest addition is Smappee wich gives me realtime (every 5 sec) total power usage and solar radiation:

Code: Select all

$data_array = json_decode(file_get_contents('http://smappee.local/gateway/apipublic/reportInstantaneousValues'));
    $unformatted = $data_array->report;
    preg_match_all("/ activePower=(\\d*.\\d*)/", $unformatted, $matches);
    if(!empty($matches[1][1])){
        $zon=round($matches[1][1],0);
        apcu_store('zon',$zon);
        if(!empty($matches[1][2])){
            $consumption=round($matches[1][2],0);
            apcu_store('consumption',$consumption);
            $timestamp=strftime("%Y-%m-%d %H:%M:%S",time);
            $query="INSERT INTO `smappee` (`timestamp`,`consumption`,`solar`) VALUES ('$timestamp','$consumption','$zon');";
            $db=new mysqli('localhost','kodi','kodi','domotica');if($db->connect_errno>0)die('Unable to connect to database [' . $db->connect_error . ']');if(!$result=$db->query($query))die('There was an error running the query ['.$query .' - ' . $db->error . ']');$db->close();
        }
    }
For some reason the notify_kodi works fine with file_get_contents here, you could simplify the code to a one liner:

Code: Select all

function notify_kodi($subject,$msg){file_get_contents('http://192.168.2.7:1597/jsonrpc?request='.urlencode(json_encode(array('jsonrpc'=>"2.0",'method'=>'GUI.ShowNotification','params'=>array('title'=>$subject,'message'=>$msg),'id'=>"1"))));}
 
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

Another variation of the notify_kodi could be this:

Code: Select all

function notify_kodi($msg){
    if(strlen($msg)>28){
        $chunks=explode('\n',wordwrap($msg,28,'\n',true));
        $length=strlen($chunks[0]);
        $subject=$chunks[0];
        $message=trim(substr($msg,$length));
    }else{
        $subject=$msg;
    }
    file_get_contents('http://192.168.2.7:1597/jsonrpc?request='.urlencode(json_encode(array('jsonrpc'=>"2.0",'method'=>'GUI.ShowNotification','params'=>array('title'=>$subject,'message'=>$message,'displaytime'=>60000),'id'=>"1"))));
}
Function only needs 1 argument, the message. When the message is longer than 28 characters (maximum for subject without scrolling) the string is split into subject/message using wordwrap.
User avatar
sincze
Posts: 1299
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: Pass2PHP

Post by sincze »

Egregius wrote:Another variation of the notify_kodi could be this:

Code: Select all

function notify_kodi($msg){
    if(strlen($msg)>28){
        $chunks=explode('\n',wordwrap($msg,28,'\n',true));
        $length=strlen($chunks[0]);
        $subject=$chunks[0];
        $message=trim(substr($msg,$length));
    }else{
        $subject=$msg;
    }
    file_get_contents('http://192.168.2.7:1597/jsonrpc?request='.urlencode(json_encode(array('jsonrpc'=>"2.0",'method'=>'GUI.ShowNotification','params'=>array('title'=>$subject,'message'=>$message,'displaytime'=>60000),'id'=>"1"))));
} 
Function only needs 1 argument, the message. When the message is longer than 28 characters (maximum for subject without scrolling) the string is split into subject/message using wordwrap.
Aha really nice indeed. Thanks for sharing.
I have to modify mine or yours a bit so it will send messages to all kodi machines that are switched on in the house.
So maybe something with

Code: Select all

Items = Array('woonkamer','keuken','slaapkamer','studeerkamer'');
for each item = items[...]..
I've seen that in your examples before. :D .
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
User avatar
sincze
Posts: 1299
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: Pass2PHP

Post by sincze »

Egregius wrote:Nice to see new functions! Thanks for sharing them here ;)

What do you mean by 'let's see what Egregius has in place for zwave'?
If I remember correctly there were some zwave functions in the original pass2php. I commented them out as I did not have zwave.
When helping @Robske setup pass2php he showed me nice features of notifications if for example the washingmachine was ready (using zwave and smart plugs.) So I thought... why not give it a try and buy some.

Now I have to uncomment the zwave functions and see what they can do for me. :D

Smappee.. ?? that is a new oen, well Some more googling for me I think. :shock:

Still looking for the possibility to insert data into influxdb using pass2php.
Now it it done from within domoticz (http-link). Works pretty okay.
Last edited by sincze on Monday 27 February 2017 9:28, edited 1 time in total.
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
ropske
Posts: 483
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi / ODroid
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: Pass2PHP

Post by ropske »

Code: Select all

#region Wasmachine Script
	$wasmachine_status_var = cget('swasmachine_status_var');
	$wasmachine_counter_var = cget('swasmachine_counter_var');
	$wasmachine_manuallyEnd_var = cget('swasmachine_manuallyEnd_uservar');
	$wasmachine_energy_consumption = cget('sVerbruik_Wasmachine');
	$idle_minutes = 5;
	$consumption_upper = 20;
	$consumption_lower = 3;
	$consumption_standby = 1;
	$wasmachinecurrentPowerUsage = cget('sVerbruik_Wasmachine');
	
	//Virtual switch is off, but consumption is higher than configured level, so washing has started
	if(($wasmachinecurrentPowerUsage>$consumption_upper)&&($wasmachine_status_var==0)){
		cset('swasmachine_status_var',1);
		cset('twasmachine_status_var',time);
		cset('swasmachine_manuallyEnd_uservar',0);
		lg('Huidig verbruik wasmachine ('.$wasmachinecurrentPowerUsage.'W) is boven ingestelde waarde ('.$consumption_upper.'W), dus wasmachine is gestart!');
		cset('swasmachine_counter_var',$idle_minutes);
		sw(cget('iStatus_Wasmachine'),'Set%20Level&level=10','Set Status wasmachine on Werkend');
	}
	//Washing machine is not using a lot of energy, check the counter
	if(($wasmachinecurrentPowerUsage<$consumption_lower)&&($wasmachine_status_var==1)){
		cset('swasmachine_counter_var',$wasmachine_counter_var-1);
		$wasmachine_counter_var = cget('swasmachine_counter_var');
		lg('Huidig verbruik wasmachine ('.$wasmachinecurrentPowerUsage.'W) is lager dan idle waarde ('.$consumption_lower.'W), wasmachine is klaar of bijna klaar');
		lg('Herbereken teller, oude waarde: '.$wasmachine_counter_var.' minuten');
	}
	else{
		if(($wasmachine_counter_var!=$idle_minutes)&&$wasmachine_status_var==1){
			cset('swasmachine_counter_var',$idle_minutes);
			lg('Resetting wasmachine timer');
		}
	}
	//Washingmachine is done
	if($wasmachine_status_var==1&&$wasmachine_counter_var==0){
		//lg('wasmachine is klaar');
		//lg('Huidig verbruik wasmachine '.$wasmachine_energy_consumption.'W');
		$wasmachine_tijdsduur=(time-cget('twasmachine_status_var'));
		lg('Wasmachine is klaar, gelieve deze te ledigen!  Tijdsduur bedraagt: '.($wasmachine_tijdsduur/60).' minuten');
		cset('swasmachine_status_var',0);
		sw(cget('iStatus_Wasmachine'),'Set%20Level&level=20','Set Status wasmachine on klaar');
		$msg='Wasmachine is klaar met werken!  Tijdsduur bedraagt: '.($wasmachine_tijdsduur/60).' minuten';
		telegram($msg,true);
	}
	//wasmachine is switched off (manually)
	if(($wasmachinecurrentPowerUsage<$consumption_standby)&&($wasmachine_status_var==0)&&($wasmachine_manuallyEnd_var==0)){
		sw(cget('iStatus_Wasmachine'),'Set%20Level&level=0','Set Status wasmachine on Off');
		cset('swasmachine_manuallyEnd_uservar',1);
	}
	
	#end
@sincze: here's an example for my 'wasmachine' :p
got the same running for droogkast and vaatwas :p
User avatar
sincze
Posts: 1299
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: Pass2PHP

Post by sincze »

ropske wrote:

Code: Select all

#region Wasmachine Script
	$wasmachine_status_var = cget('swasmachine_status_var');
	$wasmachine_counter_var = cget('swasmachine_counter_var');
	$wasmachine_manuallyEnd_var = cget('swasmachine_manuallyEnd_uservar');
	$wasmachine_energy_consumption = cget('sVerbruik_Wasmachine');
	$idle_minutes = 5;
	$consumption_upper = 20;
	$consumption_lower = 3;
	$consumption_standby = 1;
	$wasmachinecurrentPowerUsage = cget('sVerbruik_Wasmachine');
	
	//Virtual switch is off, but consumption is higher than configured level, so washing has started
	if(($wasmachinecurrentPowerUsage>$consumption_upper)&&($wasmachine_status_var==0)){
		cset('swasmachine_status_var',1);
		cset('twasmachine_status_var',time);
		cset('swasmachine_manuallyEnd_uservar',0);
		lg('Huidig verbruik wasmachine ('.$wasmachinecurrentPowerUsage.'W) is boven ingestelde waarde ('.$consumption_upper.'W), dus wasmachine is gestart!');
		cset('swasmachine_counter_var',$idle_minutes);
		sw(cget('iStatus_Wasmachine'),'Set%20Level&level=10','Set Status wasmachine on Werkend');
	}
	//Washing machine is not using a lot of energy, check the counter
	if(($wasmachinecurrentPowerUsage<$consumption_lower)&&($wasmachine_status_var==1)){
		cset('swasmachine_counter_var',$wasmachine_counter_var-1);
		$wasmachine_counter_var = cget('swasmachine_counter_var');
		lg('Huidig verbruik wasmachine ('.$wasmachinecurrentPowerUsage.'W) is lager dan idle waarde ('.$consumption_lower.'W), wasmachine is klaar of bijna klaar');
		lg('Herbereken teller, oude waarde: '.$wasmachine_counter_var.' minuten');
	}
	else{
		if(($wasmachine_counter_var!=$idle_minutes)&&$wasmachine_status_var==1){
			cset('swasmachine_counter_var',$idle_minutes);
			lg('Resetting wasmachine timer');
		}
	}
	//Washingmachine is done
	if($wasmachine_status_var==1&&$wasmachine_counter_var==0){
		//lg('wasmachine is klaar');
		//lg('Huidig verbruik wasmachine '.$wasmachine_energy_consumption.'W');
		$wasmachine_tijdsduur=(time-cget('twasmachine_status_var'));
		lg('Wasmachine is klaar, gelieve deze te ledigen!  Tijdsduur bedraagt: '.($wasmachine_tijdsduur/60).' minuten');
		cset('swasmachine_status_var',0);
		sw(cget('iStatus_Wasmachine'),'Set%20Level&level=20','Set Status wasmachine on klaar');
		$msg='Wasmachine is klaar met werken!  Tijdsduur bedraagt: '.($wasmachine_tijdsduur/60).' minuten';
		telegram($msg,true);
	}
	//wasmachine is switched off (manually)
	if(($wasmachinecurrentPowerUsage<$consumption_standby)&&($wasmachine_status_var==0)&&($wasmachine_manuallyEnd_var==0)){
		sw(cget('iStatus_Wasmachine'),'Set%20Level&level=0','Set Status wasmachine on Off');
		cset('swasmachine_manuallyEnd_uservar',1);
	}
	
	#end
@sincze: here's an example for my 'wasmachine' :p
got the same running for droogkast and vaatwas :p
Tnx @Robske ;-) really appreciated. Completely migrated to pass2php ??? :D Once it is running it keeps on going.
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

sincze wrote:If I remember correctly there were some zwave functions in the original pass2php.
I have these functions specifically for zwave (these are all commands from OZWCP):
RefreshZwave: refreshes the status of a device, used for the wrong status of Qubino double relays.
Within the refreshZwave a check is made for dead nodes and tried to wake them up again.

ZwaveCommand:Sends a command to the controller
ControllerBusy:checks if the controller is busy with a previous command
Zwavecancelaction: cancels the current actions. Some action seems to never stop.

Smappee is a energy monitor that gets installed with a ampere meter on the fases of the counter and on those of the solar inverter. They claim to 'read the dna' of every device and can assign that so you know with one meter all appliances in the house.

About influxdb: can't you do anything with the MySQL examples? If a http poller can do it, it must be possible.

For your multiple kodi's:
You could try it simply by this:

Code: Select all

function notify_kodi($msg){
    if(strlen($msg)>28){
        $chunks=explode('\n',wordwrap($msg,28,'\n',true));
        $length=strlen($chunks[0]);
        $subject=trim(substr($msg,0,$length));
        $message=trim(substr($msg,$length));
    }else{
        $subject=$msg;
    }
    $ctx=stream_context_create(array('http'=>array('timeout'=>1)));
    file_get_contents('http://192.168.2.7:1597/jsonrpc?request='.urlencode(json_encode(array('jsonrpc'=>"2.0",'method'=>'GUI.ShowNotification','params'=>array('title'=>$subject,'message'=>$message,'displaytime'=>60000),'id'=>"1"))),false,$ctx);
    file_get_contents('http://192.168.2.8:1597/jsonrpc?request='.urlencode(json_encode(array('jsonrpc'=>"2.0",'method'=>'GUI.ShowNotification','params'=>array('title'=>$subject,'message'=>$message,'displaytime'=>60000),'id'=>"1"))),false,$ctx);
    file_get_contents('http://192.168.2.9:1597/jsonrpc?request='.urlencode(json_encode(array('jsonrpc'=>"2.0",'method'=>'GUI.ShowNotification','params'=>array('title'=>$subject,'message'=>$message,'displaytime'=>60000),'id'=>"1"))),false,$ctx);
    file_get_contents('http://192.168.2.10:1597/jsonrpc?request='.urlencode(json_encode(array('jsonrpc'=>"2.0",'method'=>'GUI.ShowNotification','params'=>array('title'=>$subject,'message'=>$message,'displaytime'=>60000),'id'=>"1"))),false,$ctx);
} 
the $ctx will give a 1 second timeout so shouldn't be a big delay.
Or with a array:

Code: Select all

function notify_kodi($msg){
    if(strlen($msg)>28){
        $chunks=explode('\n',wordwrap($msg,28,'\n',true));
        $length=strlen($chunks[0]);
        $subject=trim(substr($msg,0,$length));
        $message=trim(substr($msg,$length));
    }else{
        $subject=$msg;
    }
    $ctx=stream_context_create(array('http'=>array('timeout'=>3)));
    $kodis=array('kodi1'=>'192.168.2.7','kodi2'=>'192.168.2.8');
    foreach($kodis as $name=>$ip){
        if(apcu_fetch('s'.$name)=='On')file_get_contents('http://'.$ip.':1597/jsonrpc?request='.urlencode(json_encode(array('jsonrpc'=>"2.0",'method'=>'GUI.ShowNotification','params'=>array('title'=>$subject,'message'=>$message,'displaytime'=>60000),'id'=>"1"))),false,$ctx);
    }
} 
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest