Page 28 of 76
Re: Pass2PHP
Posted: Wednesday 17 January 2018 18:29
by sincze
Egregius wrote: ↑Tuesday 16 January 2018 22:09
Why is the second print not printed?
Can you combine them in one?
I combined everything in the domoticz.log for complete overview. I opened the front door 3 times and closed it three times. To get to the front door I have to use the Deur (Hal) first.
Code: Select all
2018-01-17 18:21:36.260 LUA: Printing values d=Deur (Hal) s=Open
2018-01-17 18:21:42.039 (ZWave) Light/Switch (Deur Voordeur)
2018-01-17 18:21:42.051 LUA: Printing values d=Deur Voordeur s=Open
2018-01-17 18:21:44.356 (ZWave) Light/Switch (Deur Voordeur)
2018-01-17 18:21:44.454 LUA: Printing values d=Deur Voordeur s=Closed
2018-01-17 18:21:45.034 --->> De voordeur is weer gesloten
2018-01-17 18:21:45.036 --->> Pass2php: Deur Voordeur = Closed
2018-01-17 18:21:47.247 (ZWave) Light/Switch (Deur Voordeur)
2018-01-17 18:21:47.263 LUA: Printing values d=Deur Voordeur s=Open
2018-01-17 18:21:47.491 --->> telegram sent to GSM: Voordeur is Geopend
2018-01-17 18:21:49.459 (ZWave) Light/Switch (Deur Voordeur)
2018-01-17 18:21:49.485 LUA: Printing values d=Deur Voordeur s=Closed
2018-01-17 18:21:50.043 --->> De voordeur is weer gesloten
2018-01-17 18:21:50.046 --->> Pass2php: Deur Voordeur = Closed
2018-01-17 18:21:51.860 (ZWave) Light/Switch (Deur Voordeur)
2018-01-17 18:21:51.965 LUA: Printing values d=Deur Voordeur s=Open
2018-01-17 18:21:52.201 --->> telegram sent to GSM: Voordeur is Geopend
2018-01-17 18:21:55.087 (ZWave) Light/Switch (Deur Voordeur)
2018-01-17 18:21:55.099 LUA: Printing values d=Deur Voordeur s=Closed
2018-01-17 18:21:55.136 --->> De voordeur is weer gesloten
2018-01-17 18:21:55.137 --->> Pass2php: Deur Voordeur = Closed
2018-01-17 18:22:00.128 (RFXCom) Lighting 2 (Deur (Hal))
2018-01-17 18:22:00.161 LUA: Printing values d=Deur (Hal) s=Closed
2018-01-17 18:22:02.271 (GW RFLink LAN) Light/Switch (Deur Hal)
2018-01-17 18:23:00.825 --->> Pass2php: Deur Voordeur = Open
2018-01-17 18:23:10.184 --->> Pass2php: Deur Voordeur = Open
At 18:23:00.825 suddenly pass2php reports Voordeur open, why ? I have no idea
As I don't think it is the nginx service... but just to be sure I enabled debug for nginx.
It creates a large file very fast.:
Code: Select all
2018/01/17 20:29:51 [debug] 8463#8463: *1046 reusable connection: 1
2018/01/17 20:29:51 [debug] 8463#8463: *1046 event timer add: 7: 100000:94036351
2018/01/17 20:29:51 [debug] 8463#8463: *1046 post event 020838B0
2018/01/17 20:29:51 [debug] 8463#8463: *1046 delete posted event 020838B0
2018/01/17 20:29:51 [debug] 8463#8463: *1046 http keepalive handler
2018/01/17 20:29:51 [debug] 8463#8463: *1046 malloc: 0205B7F8:1024
2018/01/17 20:29:51 [debug] 8463#8463: *1046 recv: fd:7 -1 of 1024
2018/01/17 20:29:51 [debug] 8463#8463: *1046 recv() not ready (11: Resource temporarily unavailable)
2018/01/17 20:29:51 [debug] 8463#8463: *1046 free: 0205B7F8
2018/01/17 20:29:51 [debug] 8463#8463: *1046 post event 020838B0
2018/01/17 20:29:51 [debug] 8463#8463: *1046 post event 0208C8B8
2018/01/17 20:29:51 [debug] 8463#8463: *1046 delete posted event 020838B0
2018/01/17 20:29:51 [debug] 8463#8463: *1046 http keepalive handler
2018/01/17 20:29:51 [debug] 8463#8463: *1046 malloc: 0205B7F8:1024
2018/01/17 20:29:51 [debug] 8463#8463: *1046 recv: fd:7 0 of 1024
2018/01/17 20:29:51 [info] 8463#8463: *1046 client 127.0.0.1 closed keepalive connection
2018/01/17 20:29:51 [debug] 8463#8463: *1046 close http connection: 7
2018/01/17 20:29:51 [debug] 8463#8463: *1046 event timer del: 7: 94036351
2018/01/17 20:29:51 [debug] 8463#8463: *1046 delete posted event 0208C8B8
2018/01/17 20:29:51 [debug] 8463#8463: *1046 reusable connection: 0
Re: Pass2PHP
Posted: Wednesday 17 January 2018 20:50
by Egregius
I really don't know what to say here. Something must be calling the pass2php script.
Re: Pass2PHP
Posted: Wednesday 17 January 2018 21:23
by sincze
Egregius wrote: ↑Wednesday 17 January 2018 20:50
I really don't know what to say here. Something must be calling the pass2php script.
I think it is within the "Deur Voordeur.php" file
I commented everything out and as a result:
Code: Select all
2018-01-17 21:12:51.467 --->> Pass2php: Deur Voordeur = Open
2018-01-17 21:12:52.877 (ZWave) Light/Switch (Deur Voordeur)
2018-01-17 21:12:52.937 --->> Pass2php: Deur Voordeur = Closed
2018-01-17 21:12:54.608 (ZWave) Light/Switch (Deur Voordeur)
2018-01-17 21:12:54.704 --->> Pass2php: Deur Voordeur = Open
2018-01-17 21:12:56.362 (ZWave) Light/Switch (Deur Voordeur)
2018-01-17 21:12:56.877 --->> Pass2php: Deur Voordeur = Closed
2018-01-17 21:12:58.673 (ZWave) Light/Switch (Deur Voordeur)
2018-01-17 21:12:58.723 --->> Pass2php: Deur Voordeur = Open
2018-01-17 21:13:00.348 (ZWave) Light/Switch (Deur Voordeur)
2018-01-17 21:13:00.448 --->> Pass2php: Deur Voordeur = Closed
2018-01-17 21:13:08.627 (RFXCom) Lighting 2 (Deur Hal)
2018-01-17 21:19:26.387 (RFXCom) Lighting 2 (Deur Hal)
That looks promissing.
I guess it maybe the functions:
// auto_notify_kodi('security');
// auto_notify_kodi("Voordeur: ","Voordeur is geopend.");
That keep a pass2php thread open for some reason.. Don't know for sure.
I do now, re-enabled these 2 functions and same strange thing happened.
Disabled the 2 functions and it is working as described.
Interesting. WIlling to have a look at these 2 functions with me?
Re: Pass2PHP
Posted: Wednesday 17 January 2018 21:40
by Egregius
Yes, if you post the code...
Re: Pass2PHP
Posted: Wednesday 17 January 2018 21:42
by sincze
Egregius wrote: ↑Wednesday 17 January 2018 21:40
Yes, if you post the code...
Code: Select all
function auto_notify_kodi($subject,$msg) // if ($subject=='security') do something different
{
//EXAMPLE: kodi_notify("192.168.1.10","8080","dit is het onderwerp","dit is het bericht");
if (cget('house_mode') == "Normal")
{
if ($subject=='security')
{
if(status('Keuken')!='Off') kodi_addon(keuken,port,"script.securitycam");
if(status('Woonkamer')!='Off') kodi_addon(woonkamer,port,"script.securitycam");
if(status('Studeerkamer')!='Off') kodi_addon(studeerkamer,port,"script.securitycam");
if(status('Slaapkamer')!='Off') kodi_addon(slaapkamer,port,"script.securitycam");
}
else
{
if(status('Keuken')!="Off") { notify_kodi(keuken,port,"$subject","$msg"); }
if(status('Woonkamer')!="Off") { notify_kodi(woonkamer,port,"$subject","$msg"); }
if(status('Studeerkamer')!="Off") { notify_kodi(studeerkamer,port,"$subject","$msg"); }
if(status('Slaapkamer')!="Off") { notify_kodi(slaapkamer,port,"$subject","$msg"); }
}
}
}
and
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");
// WORKING 100%
/*
$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));
*/
// WORKING 100%
//lg('Destination will be: '.'http://'.$destination.':'.$port.'/jsonrpc?request='.urlencode(json_encode(array('jsonrpc'=>"2.0",'method'=>'GUI.ShowNotification','params'=>array('title'=>$subject,'message'=>$msg),'id'=>"1"))) );
file_get_contents('http://'.$destination.':'.$port.'/jsonrpc?request='.urlencode(json_encode(array('jsonrpc'=>"2.0",'method'=>'GUI.ShowNotification','params'=>array('title'=>$subject,'message'=>$msg),'id'=>"1"))));
}
and
Code: Select all
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));
}
Re: Pass2PHP
Posted: Wednesday 17 January 2018 22:11
by sincze
Maybe it is because of a combination of the functions with the status of the devices.
The status is not Off... but maybe not defined and the process does something we don't expect.
After a time-out it returns and causes all the problems.
Code: Select all
2018-01-17 22:09:28.070 --->> Kodi Keuken: , Adele - Someone Like You
2018-01-17 22:09:28.071 --->> Kodi Woonkamer: Friends [S-1E-1] - Friends, 28%
2018-01-17 22:09:28.073 --->> Kodi Studeerkamer:
2018-01-17 22:09:28.074 --->> Kodi Slaapkamer:
And modify the function a bit like
Code: Select all
if (empty(status('Keuken'))) lg('Keuken the variable is empty'); else lg('Keuken the variable is set');
if (!empty(status('Keuken'))) lg('Keuken the variable is set'); else lg('Keuken the variable is empty');
if (empty(status('Slaapkamer'))) lg('Slaapkamer the variable is empty'); else lg('Slaapkamer the variable is set');
if (!empty(status('Slaapkamer'))) lg('Slaapkamer the variable is set'); else lg('Slaapkamer the variable is empty');
isset seems to be not allowed on a result of function status('Slaapkamer').
Re: Pass2PHP
Posted: Wednesday 17 January 2018 22:34
by Egregius
Could it be that it only happens when your kodi is offline?
In my pass2php the cache status of the device is updated after the device script is executed. Maybe it does strange things because of a timeout in the kodi function.
A workaround could be to create a separate script for the kodi notification and execute that by a curl in shell_exec.
If you like I could post some example code tomorrow, I do something similar for iOS notifications.
Re: Pass2PHP
Posted: Wednesday 17 January 2018 23:10
by sincze
Egregius wrote: ↑Wednesday 17 January 2018 22:34
Could it be that it only happens when your kodi is offline?
In my pass2php the cache status of the device is updated after the device script is executed. Maybe it does strange things because of a timeout in the kodi function.
A workaround could be to create a separate script for the kodi notification and execute that by a curl in shell_exec.
If you like I could post some example code tomorrow, I do something similar for iOS notifications.
Yes please
Re: Pass2PHP
Posted: Thursday 18 January 2018 7:40
by Egregius
This should get you in the good direction:
Make a file kodinotification.php:
Code: Select all
<?PHP
if(isset($_REQUEST['text'])){
notify_kodi($_REQUEST['text']);
}
function notify_kodi($destination,$port,$subject,$msg)
{
....
}
?>
Make a bash script that call's the php script kodinotification.sh:
Code: Select all
#!/bin/bash
MSG="$1"
curl -s --data-urlencode "text=$MSG" "http://127.0.0.1/secure/kodinotification.php"
Execute it in pass2php with shell exec:
Code: Select all
shell_exec('/var/www/html/secure/kodinotification.sh "Deurbel" > /dev/null 2>/dev/null &');
Because the PHP script is executed in another thread and running in the background it shouldn't give a delay.
I'll make today something similar for telegram, sometimes that also gives delays when a message must be resend.
Once the code is ready I'll run some tests in loop to measure the difference in time.
Re: Pass2PHP
Posted: Thursday 18 January 2018 8:02
by sincze
Tnx. I will give it a try.
At least we now know where this issue came from Took a while.
to figure out. But as said it was it this door
that was causing problems. Tnx for the support
Re: Pass2PHP
Posted: Thursday 18 January 2018 8:47
by Egregius
No problem
Time difference between telegram directly and thru shell is huge:
Code: Select all
$start=microtime(true);
for($x=1;$x<=10;$x++){
$msg='Shell '.$x;
shell_exec('/var/www/html/secure/telegram.sh "'.$msg.'" > /dev/null 2>/dev/null &');
}
$total=microtime(true)-$start;
echo '<hr>Shell Time:'.number_format(((microtime(true)-$start)*1000),6);
$start=microtime(true);
for($x=1;$x<=10;$x++){
telegram('Test '.$x);
}
$total=microtime(true)-$start;
echo '<hr>Telegram Time:'.number_format(((microtime(true)-$start)*1000),6);
Result:
Shell Time: 30.284882
Telegram Time: 2685.431004
Re: Pass2PHP
Posted: Thursday 18 January 2018 9:17
by sincze
Egregius wrote: ↑Thursday 18 January 2018 8:47
No problem
Time difference between telegram directly and thru shell is huge:
Code: Select all
$start=microtime(true);
for($x=1;$x<=10;$x++){
$msg='Shell '.$x;
shell_exec('/var/www/html/secure/telegram.sh "'.$msg.'" > /dev/null 2>/dev/null &');
}
$total=microtime(true)-$start;
echo '<hr>Shell Time:'.number_format(((microtime(true)-$start)*1000),6);
$start=microtime(true);
for($x=1;$x<=10;$x++){
telegram('Test '.$x);
}
$total=microtime(true)-$start;
echo '<hr>Telegram Time:'.number_format(((microtime(true)-$start)*1000),6);
Result:
Shell Time: 30.284882
Telegram Time: 2685.431004
So we have optimized Pass2PHP today
I feel a git pull is coming up?
Let's see if it helps with the kodi thing as well. I presume the answer will be yes.
Re: Pass2PHP
Posted: Thursday 18 January 2018 9:22
by Egregius
Maybe I'll update Git later. I do that manually, don't use the Git program.
Happend before that I published before removing personal data so don't want that again...
Re: Pass2PHP
Posted: Thursday 18 January 2018 18:07
by sincze
Egregius wrote: ↑Thursday 18 January 2018 7:40
This should get you in the good direction:
Make a file kodinotification.php:
Code: Select all
<?PHP
if(isset($_REQUEST['text'])){
notify_kodi($_REQUEST['text']);
}
function notify_kodi($destination,$port,$subject,$msg)
{
....
}
?>
Make a bash script that call's the php script kodinotification.sh:
Code: Select all
#!/bin/bash
MSG="$1"
curl -s --data-urlencode "text=$MSG" "http://127.0.0.1/secure/kodinotification.php"
Execute it in pass2php with shell exec:
Code: Select all
shell_exec('/var/www/html/secure/kodinotification.sh "Deurbel" > /dev/null 2>/dev/null &');
Because the PHP script is executed in another thread and running in the background it shouldn't give a delay.
I'll make today something similar for telegram, sometimes that also gives delays when a message must be resend.
Once the code is ready I'll run some tests in loop to measure the difference in time.
I guess we should do the check if device status like check_kodi() to see if it is != off in main pass2php_functions.php to avoid having the same functions in multiple locations and to be able to use the variables from the main code. And have the external .php file do it's magic.
Re: Pass2PHP
Posted: Thursday 18 January 2018 19:42
by Egregius
I would exclusively put the kodi notification function in the separate php file and not in functions anymore.
I already did that for my telegram notifications. No more delay on sending telegram
Re: Pass2PHP
Posted: Thursday 18 January 2018 19:48
by sincze
Egregius wrote: ↑Thursday 18 January 2018 19:42
I would exclusively put the kodi notification function in the separate php file and not in functions anymore.
I already did that for my telegram notifications. No more delay on sending telegram
Can I copy the telegram thing from you? Or I can build it myself same as kodi notification
%)
Re: Pass2PHP
Posted: Thursday 18 January 2018 20:07
by Egregius
I think the Telegram changes are on github
Re: Pass2PHP
Posted: Thursday 18 January 2018 21:18
by sincze
Egregius wrote: ↑Thursday 18 January 2018 20:07
I think the Telegram changes are on github
Check,
Code: Select all
function kodinotification($subject,$content) // Used for external KODI NOTIFICATION.PHP
{
if (cget('house_mode')=='Normal')
{
$kodi_machines=array('Keuken','Woonkamer','Studeerkamer','Slaapkamer');
{
foreach($kodi_machines as $item)
{
if ((!empty(status($item)))&&(status($item)!='Off'))
{
switch ($item) // Determening the IP Address of KODI Machine.
{
case 'Keuken':
$ipadres=keuken;
break;
case 'Woonkamer':
$ipadres=woonkamer;
break;
case 'Studeerkamer':
$ipadres=studeerkamer;
break;
case 'Slaapkamer':
$ipadres=slaapkamer;
break;
}
$msg=($ipadres.';'.port.';'.$subject.';'.$content);
shell_exec(domoticz_location.'scripts/pass2php/kodinotification.sh "'.$msg.'" > /dev/null 2>/dev/null &');
}
}
}
}
}
It is working. I'm going to test it with the front door now
back in a sec.
Re: Pass2PHP
Posted: Friday 19 January 2018 18:57
by sincze
Created one for snapshots as well.. as the initial voordeur open issue/thing came back.... Hope it is solved now.
Code: Select all
function snapshots($camera) // Voordeur / Hal / Keuken / Berging
{
shell_exec(domoticz_location.'scripts/pass2php/snapshots.sh "'.$camera.'" > /dev/null 2>/dev/null &');
}
Re: Pass2PHP
Posted: Saturday 20 January 2018 0:07
by ropske
i'm excited to see the new changes you guys made
Cant wait to see