Pass2PHP

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

Re: Pass2PHP

Post by sincze » Friday 22 December 2017 12:20

Egregius wrote:
Friday 22 December 2017 9:48
Nice, and you're welcome ;)
I do wonder how far you go with it?
A well how far. No deciscion making / no lua / no scripts / no blocky done by Domoticz.
The whole house decision making is done via Pass2PHP. and send to Domoticz.
I still use memcached / opcache so the Pass2PHP basic essentials.

The real advantage is that Pass2PHP can work with device names. So I changed 433mhz to Zwave or Zigbee withou any downtime or modification. Just chanfe the device name and you are using the new sensor as if it was the old one. In addition I start all kinds of plugins in KODI :D . Door opened? SHow a live feed on the tv's that are on. That kind of stuff.

But does that answer your question?
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.

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

Re: Pass2PHP

Post by Egregius » Saturday 23 December 2017 16:12

Yes it does ;)

Same here, everything is done in PHP.
Now at about 300KB code (when just counting the crons and device scripts).
Just added 8 roller shutters, about 400 lines just for the winter programming. The summer programming will even be more...

Next project: water- and gasmeter read out and put it directly to my consumption site (should post that code also in the near future on Github).

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

Re: Pass2PHP

Post by sincze » Saturday 23 December 2017 23:52

Egregius wrote:Yes it does ;)

Same here, everything is done in PHP.
Now at about 300KB code (when just counting the crons and device scripts).
Just added 8 roller shutters, about 400 lines just for the winter programming. The summer programming will even be more...

Next project: water- and gasmeter read out and put it directly to my consumption site (should post that code also in the near future on Github).
Nice I also have summer program for the screens and thermostat code. Data is dumped directly in Influxdb and I have grafana for the nice graphs. As everything is automated I don't have any visual feedback on a tablet or so. Just regular domoticz

Just copied your sw function and modified it so I can use it with the traditional pass2php. The sw( array) is so cool and cleans up a lot of code :) lines. Now looking for more improvements I can copy

Sent from my SM-G925F using Tapatalk

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.

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

Re: Pass2PHP

Post by Egregius » Sunday 24 December 2017 15:52

Yes, arrays are a great way to reduce the code when you have several things that need to react in the same way.
I just compressed my 400 lines for the rollers down to 69 lines thanks to arrays.
Here's my winter program for 8 roller shutters:

Code: Select all

<?php $kwartier=870;$tweeuur=7170;$msg='Rolluiken__';if($buien>=30)$open=31;else$open=0;
$items=array('Rliving','Rbureel','RkeukenL','RkeukenR','Rtobi','Ralex','RkamerL','RkamerR','luifel','raamliving','raamtobi','raamalex','raamkamer','zonOP','buiten_temp','living_temp','tobi_temp','alex_temp','kamer_temp','heatingauto','buien','wind','modeRliving','modeRbureel','modeRkeukenL','modeRkeukenR','modeRtobi','modeRalex','modeRkamerL','modeRkamerR');foreach($items as $i)${$i}=apcu_fetch($i);
$items=array('Rliving','Rbureel','RkeukenL','RkeukenR','Rtobi','Ralex','RkamerL','RkamerR','raamtobi','raamalex','raamkamer');foreach($items as $i)${'T'.$i}=past($i);
if(time<strtotime('7:00')||time>=strtotime('22:00'))$nacht=true;else $nacht=false;
if(time>=strtotime('7:00')&&time<strtotime('8:30'))$ochtend=true;else $ochtend=false;
if(time>=strtotime('8:30')&&time<strtotime('16:30'))$dag=true;else $dag=false;
if(time>=strtotime('16:30')&&time<strtotime('22:00'))$avond=true;else $avond=false;
$boven=array('Rtobi','Ralex','RkamerL','RkamerR');$beneden=array('Rbureel','RkeukenL','RkeukenR');$benedena=array('Rliving','Rbureel','RkeukenL','RkeukenR');
if($heatingauto=='On'){$msg.='Winter__';
	if($Weg==0){$msg.='Thuis__';
		if($nacht){$msg.='Nacht__';
				foreach($benedena as $i){if(${'mode'.$i}&&${$i}<75){sl($i,100);$msg.=$i.' Dicht__';}}
				foreach($boven as $i)	{if(${'mode'.$i}&&${$i}<75){sl($i,100);$msg.=$i.' Dicht__';}}
		}elseif($ochtend){$msg.='Ochtend__';
			if($zonOP&&$zon==0){$msg.='ZonOP && Zon = 0__';
				foreach($benedena as $i){if(${'mode'.$i}&&${$i}!=$open&&${'T'.$i}>$kwartier){sl($i,$open);$msg.=$i.' '.$open.'__';}}
			}elseif($zonOP){$msg.='ZonOP && Zon = '.$zon.'__';
				foreach($benedena as $i){if(${'mode'.$i}&&${$i}!=$open&&${'T'.$i}>$kwartier){sl($i,$open);$msg.=$i.' '.$open.'__';}}
				foreach($boven as $i){if($i=='Rtobi')$raam=$Traamtobi;elseif($i=='Ralex')$raam=$Traamalex;else$raam=$Traamkamer;
					if(${'mode'.$i}&&${$i}!=$open&&${'T'.$i}>$kwartier&&$$raam<$tweeuur){sl($i,$open);$msg.=$i.' '.$open.'__';}
				}
			}
		}elseif($dag){$msg.='Dag__';
				foreach($benedena as $i){if(${'mode'.$i}&&${$i}!=$open&&${'T'.$i}>$kwartier){sl($i,$open);$msg.=$i.' '.$open.'__';}}
				foreach($boven as $i){if($i=='Rtobi')$raam=$Traamtobi;elseif($i=='Ralex')$raam=$Traamalex;else$raam=$Traamkamer;
					if(${'mode'.$i}&&${$i}>$open&&${'T'.$i}>$kwartier&&$raam<$tweeuur){sl($i,$open);$msg.=$i.' '.$open.'__';}
				}
		}elseif($avond){$msg.='Avond__';
			if($zonOP&&$zon==0){$msg.='zonOP && Zon = 0__';
				foreach($beneden as $i){if(${'mode'.$i}&&${$i}<$open&&${'T'.$i}>$kwartier){sl($i,$open);$msg.=$i.' '.$open.'__';}}
			}elseif($zonOP&&$zon<50){$msg.='zonOP && Zon < 50 : '.$zon.'__';
				foreach($boven as $i){if(${'mode'.$i}&&${$i}<$open&&${'T'.$i}>$kwartier){sl($i,100);$msg.=$i.' Dicht__';}}
			}elseif($zonOP){$msg.='zonOP, zon = '.$zon.'__';
			}else{$msg.='Zononder __';
				foreach($beneden as $i){if(${'mode'.$i}&&${$i}<75){sl($i,100);$msg.=$i.' Dicht__';}}
				foreach($boven as $i){if(${'mode'.$i}&&${$i}<75){sl($i,100);$msg.=$i.' Dicht__';}}
			}
		}
	}elseif($Weg==1){$msg.='Slapen__';
		foreach($boven as $i)	{if(${'mode'.$i}&&${$i}<75){sl($i,100);$msg.=$i.' Dicht__';}}
		foreach($benedena as $i){if(${'mode'.$i}&&${$i}<75){sl($i,100);$msg.=$i.' Dicht__';}}
	}elseif($Weg==2){$msg.='Weg__';
		if($nacht){$msg.='Nacht__';
				foreach($benedena as $i){if(${'mode'.$i}&&${$i}<75){sl($i,100);$msg.=$i.' Dicht__';}}
				foreach($boven as $i)	{if(${'mode'.$i}&&${$i}<75){sl($i,100);$msg.=$i.' Dicht__';}}
		}elseif($ochtend){$msg.='Ochtend__';
			if($zonOP&&$zon==0){$msg.='ZonOP && Zon = 0__';
				foreach($benedena as $i){if(${'mode'.$i}&&${$i}!=$open&&${'T'.$i}>$kwartier){sl($i,$open);$msg.=$i.' '.$open.'__';}}
			}elseif($zonOP){$msg.='ZonOP && Zon = '.$zon.'__';
				foreach($benedena as $i){if(${'mode'.$i}&&${$i}!=$open&&${'T'.$i}>$kwartier){sl($i,$open);$msg.=$i.' '.$open.'__';}}
				foreach($boven as $i){if(${'mode'.$i}&&${$i}!=$open&&${'T'.$i}>$kwartier){sl($i,$open);$msg.=$i.' '.$open.'__';}}
			}
		}elseif($dag){$msg.='Dag__';
				foreach($benedena as $i){if(${'mode'.$i}&&${$i}!=$open&&${'T'.$i}>$kwartier){sl($i,$open);$msg.=$i.' '.$open.'__';}}
				foreach($boven as $i){if(${'mode'.$i}&&${$i}>$open&&${'T'.$i}>$kwartier){sl($i,$open);$msg.=$i.' '.$open.'__';}}
		}elseif($avond){$msg.='Avond__';
			if($zonOP&&$zon==0){$msg.='zonOP && Zon = 0__';
				foreach($beneden as $i){if(${'mode'.$i}&&${$i}<$open&&${'T'.$i}>$kwartier){sl($i,$open);$msg.=$i.' '.$open.'__';}}
			}elseif($zonOP&&$zon<50){$msg.='zonOP && Zon < 50 : '.$zon.'__';
				foreach($boven as $i){if(${'mode'.$i}&&${$i}<$open&&${'T'.$i}>$kwartier){sl($i,100);$msg.=$i.' Dicht__';}}
			}elseif($zonOP){$msg.='zonOP, zon = '.$zon.'__';
			}else{$msg.='Zononder __';
				foreach($beneden as $i){if(${'mode'.$i}&&${$i}<75){sl($i,100);$msg.=$i.' Dicht__';}}
				foreach($boven as $i){if(${'mode'.$i}&&${$i}<75){sl($i,100);$msg.=$i.' Dicht__';}}
			}
		}
	}
}
lg(str_replace('__',' | ',$msg));if(strlen($msg)>80)telegram(str_replace('__',PHP_EOL,$msg));?>

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

Re: Pass2PHP

Post by sincze » Sunday 24 December 2017 21:07

I build this array one around your pingdomain function. :D
However unfortunately I have some devices that don't respond to a port, so they are always down. Did not figure out how to solve that. Any ideas?

Code: Select all

function pingtest()
{
    global $s,$i;

    $to_ping= array( array( Device => "Sonoff_Badkamer", Address => "10.1.1.215",  Port => 80 ),              
                    array( Device => "Xiaomi Gateway", Address => "10.1.1.243", Port => 8080 ),
                    array( Device => "Mi-Light Beneden", Address => "10.1.1.242", Port => 80 ),              
                    array( Device => "Mi-Light Woonkamer",  Address => "10.1.1.241", Port => 80 ),
                    array( Device => "Internet",    Address => "8.8.8.8", Port => 53   ),
                    array( Device => "Synology", Address => "10.1.1.12", Port => 80),
                    array( Device => "TV Server",  Address => "10.1.1.80", Port => 80 ),
                    array( Device => "TV Keuken", Address => "10.1.1.41",  Port => 8080 ), 
                    array( Device => "TV Woonkamer", Address => "10.1.1.40",  Port => 8080 ), 
                    array( Device => "Harmony Hub",  Address => "10.1.1.235", Port => 5222 )
                    );

    foreach ($to_ping as $ping) 
    {
        $device=$ping['Device'];
        $result=pingdomain($ping['Address'],$ping['Port']);
        if ($result=='-1') $status='Off'; else $status='On';        
        if ($s[$device]!=$status) sw($i[$device],$status,"Ping Service: ".$device);                
    }
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.

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

Re: Pass2PHP

Post by Egregius » Sunday 24 December 2017 23:50

Will look at that tomorrow, also need one to check my Xiaomi gateway, doesn't seem to respond to any port either.

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

Re: Pass2PHP

Post by sincze » Monday 25 December 2017 2:43

Egregius wrote:Will look at that tomorrow, also need one to check my Xiaomi gateway, doesn't seem to respond to any port either.
You have xiaomi equipment as well? Image what do you think of the response times.
I just found out my system usage said uptime Bla Bla 2.06 2.25 3.00

That would mean my CubieTruck is under some stress. Sometimes light switches took over 1 sec.


Sent from my SM-G925F using Tapatalk

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.

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

Re: Pass2PHP

Post by Egregius » Monday 25 December 2017 5:22

Here's your ping function:

Code: Select all

function ping($ip){
	$result=exec("/bin/ping -c1 -w1 $ip",$outcome,$status);
    if($status==0)$status=true;else $status=false;
    return $status;
}
Usage:

Code: Select all

if(ping('192.168.2.1'))echo 'device online';
if(!ping('192.168.2.197'))echo 'device offline';
I only recently reveived my Xiaomi Gateway. Only use it as a doorbell for now.
When movement is detected on one of the camera's the knock knock sound sounds and the light goes yellow. If someone pushes the doorbell the ding dong sounds and the light is red. Now also ordered one door contact. Only plan to use it for less critical stuff.

I don't see such usage:
top - 04:21:55 up 5 days, 10:52, 1 user, load average: 0.18, 0.17, 0.16

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

Re: Pass2PHP

Post by sincze » Monday 25 December 2017 12:11

Yes I had that exact ping function yesterday. Did not work. Even changed exec to shell_exec

Fun fact is that it should work. As it is described over the Internet a lot. I even pointed to the ping file location exactly.

Even 192.168.1.0 was returned to true. But good to hear it should work. Let's start debugging.

Xiaomi stuff I have a complete floor with. Works like a charm. Doorbell and sounds really funny. I use the rgb as night light to find your way in the dark corridor :). Knock knock as doorbell. Motion sensors small and responsively quick. Good zwave alternative. Door switches nice and small. Zigbee should be a little lower in battery usage.

The Other floors in house I use zwave. And lights 433mhz Coco as Fibaro is really to expensive for the whole house :) for me.

All in all works like a charm. Stopped Influxdb now and the figures look more like yours. Image

So how about that virtuslization?

Sent from my SM-G925F using Tapatalk

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.

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

Re: Pass2PHP

Post by sincze » Monday 25 December 2017 16:22

Egregius wrote:
Monday 25 December 2017 5:22
Here's your ping function:

Code: Select all

function ping($ip){
	$result=exec("/bin/ping -c1 -w1 $ip",$outcome,$status);
    if($status==0)$status=true;else $status=false;
    return $status;
}
Usage:

Code: Select all

if(ping('192.168.2.1'))echo 'device online';
if(!ping('192.168.2.197'))echo 'device offline';
I only recently reveived my Xiaomi Gateway. Only use it as a doorbell for now.
When movement is detected on one of the camera's the knock knock sound sounds and the light goes yellow. If someone pushes the doorbell the ding dong sounds and the light is red. Now also ordered one door contact. Only plan to use it for less critical stuff.

I don't see such usage:
top - 04:21:55 up 5 days, 10:52, 1 user, load average: 0.18, 0.17, 0.16
pff don't lnow what just happened.
Copied your exact version and it worked. :lol:
Modified it so it can be used with the array as well. :D

Code: Select all

function ping($ip){
  $result=exec("/bin/ping -c1 -w1 $ip",$outcome,$status); 
  if($status==0)$status="On";else $status="False"; 
  return $status;
}
Xiaomi is now officially online.
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.

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

Re: Pass2PHP

Post by Egregius » Tuesday 26 December 2017 10:27

sincze wrote:
Monday 25 December 2017 12:11
So how about that virtuslization?
What do you mean?
I use Proxmox as virtual host on a Intel i3 Nuc with 8GB ram :)

Image

btw, If you return true or false it's easier to handle them.
Now you need if(ping('1.2.3.4')=='On')...
And with true/false that could be just if(ping('1.2.3.4'))...

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

Re: Pass2PHP

Post by sincze » Friday 29 December 2017 22:09

Mmm Domoticz v3.8796

Currently installing a new Raspberry Pi 3 and try to figure out why: "

The solution cbjson64 as described here, is not working anymore.
"https://www.domoticz.com/forum/viewtopi ... 20#p109800"

Code: Select all

0. just before cb64json
lua: script_device_sneezydevil.lua:4: module 'cb64json' not found:
        no field package.preload['cb64json']
        no file './cb64json.lua'
        no file '/usr/local/share/lua/5.1/cb64json.lua'
        no file '/usr/local/share/lua/5.1/cb64json/init.lua'
        no file '/usr/local/lib/lua/5.1/cb64json.lua'
        no file '/usr/local/lib/lua/5.1/cb64json/init.lua'
        no file '/usr/share/lua/5.1/cb64json.lua'
        no file '/usr/share/lua/5.1/cb64json/init.lua'
        no file './cb64json.so'
        no file '/usr/local/lib/lua/5.1/cb64json.so'
        no file '/usr/lib/arm-linux-gnueabihf/lua/5.1/cb64json.so'
        no file '/usr/lib/lua/5.1/cb64json.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
        [C]: in function 'require'
        script_device_sneezydevil.lua:4: in main chunk
        [C]: ?
even a simple other script like:

Code: Select all

--c = ''
--s = ''
--i = ''
--t = ''
--for k,v in pairs(devicechanged) do c = c..k.."|"..v.."#" end
--for k,v in pairs(otherdevices) do s = s..k.."|"..v.."#" end
--for k,v in pairs(otherdevices_idx) do i = i..k.."|"..v.."#" end
--for k,v in pairs(otherdevices_lastupdate) do t = t..k.."|"..v.."#" end

--os.execute('curl -s --data "c='..c..'&s='..s..'&i='..i..'&t='..t..'" http://127.0.0.1/secure/pass2php &')
print("Curl Ended")

commandArray={}
return commandArray
let's Domoitcz hang.
If I remo the script.device.name.lua the system works again.

Maybe something changed..
https://domoticz.com/forum/viewtopic.php?f=6&t=18276

Updated the settings:
Pass2php Settings.JPG
Settings
Pass2php Settings.JPG (23.98 KiB) Viewed 966 times
At least now i have:

Code: Select all

2017-12-29 21:34:05.375 User: Admin initiated a switch command (1/Dummy/On)
2017-12-29 21:34:05.379 (Dummy) Light/Switch (Dummy)
2017-12-29 21:34:05.381 LUA: Curl Ended
So it is showing up again.
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.

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

Re: Pass2PHP

Post by Egregius » Friday 29 December 2017 23:00

Let me try tomorrow if I experience the same issue with the latest beta. I normally don't update that often anymore.
Either way, pass2php doesn't need json anymore.

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

Re: Pass2PHP

Post by sincze » Friday 29 December 2017 23:33

Egregius wrote:
Friday 29 December 2017 23:00
Let me try tomorrow if I experience the same issue with the latest beta. I normally don't update that often anymore.
Either way, pass2php doesn't need json anymore.
tnx. got it now working with the csjon64 again by installing

Code: Select all

sudo apt-get install lua5.2
Event system is up and running.
You know I still use file based.php files for executing. So really interesting if we can also modify / update my installation so we don't need JSON anymore ;-) :D

Code: Select all

for d,s in pairs(devicechanged)
do
os.execute('curl -X POST -d "d='..d.."&s="..s..'" http://127.0.0.1/secure/pass2php.php &')
end
commandArray={}
return commandArray
My work is still based on parsing all the tables (c,s,i,t)

Code: Select all

<?php
error_reporting(E_ALL);
require '/var/www/html/secure/pass2php_include/settings.php';
if(debug) lg('Executing Pass2php');

// --------------------------------------------------------------------------------
// Pass2PHP Stuff from here
// --------------------------------------------------------------------------------
// $a = status of triggered device 			devicechanged
// $s = array of all statusses				otherdevices
// $i = array of all IDXs					otherdevices_idx
// $t = array of all last update times 		otherdevices_lastupdate
// $c = array (equals devicechanged in lua)

$c=json_decode(base64_decode($_REQUEST['c']),true);
$s=json_decode(base64_decode($_REQUEST['s']),true);
$i=json_decode(base64_decode($_REQUEST['i']),true);
$t=json_decode(base64_decode($_REQUEST['t']),true);

foreach($c as $device=>$status)
{	
	if(@include '/var/www/html/secure/pass2php/'.$device.'.php') 
		{ 
			if(debug) lg('Executing device: '.$device);
			$dev=$device;
		}
}

if(!isset($dev))die();
include '/var/www/html/secure/pass2php/__CRON.php';

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

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

Re: Pass2PHP

Post by Egregius » Saturday 30 December 2017 9:02

Well, latest beta works here without any issue with pass2php (rest is still to be evaluated).
If this is yout script_device_pass2php.lua you shouldn't need the json library:

Code: Select all

for d,s in pairs(devicechanged)
do
os.execute('curl -X POST -d "d='..d.."&s="..s..'" http://127.0.0.1/secure/pass2php.php &')
end
commandArray={}
return commandArray
And you should consider placing all statusses in apcu or memcached. It'll be a lot faster than parsing everything everytime.

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

Re: Pass2PHP

Post by Egregius » Saturday 30 December 2017 9:04

Oh, and if you don't use dzvents you can disable that also.

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

Re: Pass2PHP

Post by sincze » Saturday 30 December 2017 21:16

Egregius wrote:
Saturday 30 December 2017 9:02
Well, latest beta works here without any issue with pass2php (rest is still to be evaluated).
If this is yout script_device_pass2php.lua you shouldn't need the json library:

Code: Select all

for d,s in pairs(devicechanged)
do
os.execute('curl -X POST -d "d='..d.."&s="..s..'" http://127.0.0.1/secure/pass2php.php &')
end
commandArray={}
return commandArray
And you should consider placing all statusses in apcu or memcached. It'll be a lot faster than parsing everything everytime.
So I can use the lua above and in meantime still the pass2php php as posted in 2 posts back?

At the moment I am not that far to do all in acpu but have to have an in between working solution. Disabled dzvents indeed. :)

My feeling says that in that case I would be missing the following information:

Code: Select all

"
/ $s = array of all statusses				otherdevices
// $i = array of all IDXs					otherdevices_idx
// $t = array of all last update times 		otherdevices_lastupdate
"
As I currently don''t store that in memory.
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.

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

Re: Pass2PHP

Post by Egregius » Sunday 31 December 2017 0:24

Depending on the number of scripts you have it should be done in several hours to convert everything to use apcu instead of parsing everything.
Advantage is that you don't need json and base64 encode in lua and decode in php.
I know only sent the changed device in plain text resulting in a much faster response.
I wouldn't spend time to have both running simultaneously.

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

Re: Pass2PHP

Post by sincze » Sunday 31 December 2017 2:25

Egregius wrote:
Sunday 31 December 2017 0:24
Depending on the number of scripts you have it should be done in several hours to convert everything to use apcu instead of parsing everything.
Advantage is that you don't need json and base64 encode in lua and decode in php.
I know only sent the changed device in plain text resulting in a much faster response.
I wouldn't spend time to have both running simultaneously.
A well, starting to give it a shot ;-), downloaded your github files.
Now have your lua and the following pass2php.php.
Had to modify the lg function again so it would show up It results in a device. Pass2php is executed.
Now I have to figure out how the rest works. APCU is installed.

Code: Select all

<?php

define('rootdir','/var/www/html/secure2/');
require(rootdir.'pass2php_include/settings.php');
lg('Debug: Executing Pass2php new style');

if($_SERVER['REQUEST_METHOD']=='POST'){
		$device=$_POST['d'];
		$status=$_POST['s'];
		if(@include rootdir.'pass2php/'.$device.'.php'){
			lg($device.' = '.$status);
			setstatus($device,$status);
        }
        else lg('Debug: Pass2PHP new style could not find device: '.$device);
}

if(apcu_fetch('cron5')<time()-4){
	apcu_store('cron5',time());
	if(apcu_fetch('cron604800')<time()-604790){
		apcu_store('cron604800',time());
		include(rootdir.'pass2php/cron/_cron604800.php');
	}
	if(apcu_fetch('cron300')<time()-298){
		apcu_store('cron300',time());
		include(rootdir.'pass2php/cron/_cron300.php');
	}
	if(apcu_fetch('cron120')<time()-118){
		apcu_store('cron120',time());
		include(rootdir.'pass2php/cron/_cron120.php');
		
		if(apcu_fetch('cron28800')<time()-27790){
			apcu_store('cron28800',time());
			include(rootdir.'pass2php/cron/_cron28800.php');
		}
	}
	if(apcu_fetch('cron60')<time()-58){
		apcu_store('cron60',time());
		include(rootdir.'pass2php/cron/_cron60.php');
	}
	include(rootdir.'pass2php/cron/_cron5.php');
}

?>
each device file should do someting with $status that it receives. And then I can use the regular functions sw,ud e.g.
I guess but I have to look you modified these as well to obtain the appropriate idx / timestamps from apcu,
It's getting a bit late so will have to look at it tomorrow.
Thanks for the support and tips are welcome.
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.

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

Re: Pass2PHP

Post by sincze » Sunday 31 December 2017 2:25

Egregius wrote:
Sunday 31 December 2017 0:24
Depending on the number of scripts you have it should be done in several hours to convert everything to use apcu instead of parsing everything.
Advantage is that you don't need json and base64 encode in lua and decode in php.
I know only sent the changed device in plain text resulting in a much faster response.
I wouldn't spend time to have both running simultaneously.
A well, starting to give it a shot ;-), downloaded your github files.
Now have your lua and the following pass2php.php.
Had to modify the lg function again so it would show up It results in a device. Pass2php is executed.
Now I have to figure out how the rest works. APCU is installed.

Code: Select all

<?php

define('rootdir','/var/www/html/secure2/');
require(rootdir.'pass2php_include/settings.php');
lg('Debug: Executing Pass2php new style');

if($_SERVER['REQUEST_METHOD']=='POST'){
		$device=$_POST['d'];
		$status=$_POST['s'];
		if(@include rootdir.'pass2php/'.$device.'.php'){
			lg($device.' = '.$status);
			setstatus($device,$status);
        }
        else lg('Debug: Pass2PHP new style could not find device: '.$device);
}

if(apcu_fetch('cron5')<time()-4){
	apcu_store('cron5',time());
	if(apcu_fetch('cron604800')<time()-604790){
		apcu_store('cron604800',time());
		include(rootdir.'pass2php/cron/_cron604800.php');
	}
	if(apcu_fetch('cron300')<time()-298){
		apcu_store('cron300',time());
		include(rootdir.'pass2php/cron/_cron300.php');
	}
	if(apcu_fetch('cron120')<time()-118){
		apcu_store('cron120',time());
		include(rootdir.'pass2php/cron/_cron120.php');
		
		if(apcu_fetch('cron28800')<time()-27790){
			apcu_store('cron28800',time());
			include(rootdir.'pass2php/cron/_cron28800.php');
		}
	}
	if(apcu_fetch('cron60')<time()-58){
		apcu_store('cron60',time());
		include(rootdir.'pass2php/cron/_cron60.php');
	}
	include(rootdir.'pass2php/cron/_cron5.php');
}

?>
each device file should do someting with $status that it receives. And then I can use the regular functions sw,ud e.g.
I guess but I have to look you modified these as well to obtain the appropriate idx / timestamps from apcu,
It's getting a bit late so will have to look at it tomorrow.
Thanks for the support and tips are welcome.
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.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests