Pass2PHP

User avatar
Egregius
Posts: 2390
Joined: Thursday 09 April 2015 12:19
Target OS: Raspberry Pi
Domoticz version: BetaRPi2
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius » Friday 08 September 2017 18:23

Make a php page that stores a post or get request in cache ;)
Shall I post some code later?

User avatar
Egregius
Posts: 2390
Joined: Thursday 09 April 2015 12:19
Target OS: Raspberry Pi
Domoticz version: BetaRPi2
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius » Friday 08 September 2017 19:01

It's on my github already :D
https://github.com/Egregius/LUA-Pass2PH ... /cache.php

Usage:
cache.php?fetch=devicename returns the value of that cache
cache.php?store=devicename&value=Off = store that value in cache

I only need it internally so my file is in my secure folder.
If you make this available from internat you could ad forexample &token=anystring and use that as a security measurement.

User avatar
sincze
Posts: 690
Joined: Monday 02 June 2014 22:46
Target OS: Linux
Domoticz version: 3.8153
Location: Netherlands
Contact:

Re: Pass2PHP

Post by sincze » Friday 08 September 2017 19:17

Egregius wrote:
Friday 08 September 2017 19:01
It's on my github already :D
https://github.com/Egregius/LUA-Pass2PH ... /cache.php

Usage:
cache.php?fetch=devicename returns the value of that cache
cache.php?store=devicename&value=Off = store that value in cache

I only need it internally so my file is in my secure folder.
If you make this available from internat you could ad forexample &token=anystring and use that as a security measurement.
Damn... You completely redesigned pass2php since december 2016....
It seems I have a working... however outdated version running :lol:
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: 2390
Joined: Thursday 09 April 2015 12:19
Target OS: Raspberry Pi
Domoticz version: BetaRPi2
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius » Friday 08 September 2017 19:28

Indeed, I just rewrote all the cache functions yesterday ;)
It's still a work in progress,still some fine tuning but a lot less than a year ago. Once it does everything you need there's not much left to do.

User avatar
sincze
Posts: 690
Joined: Monday 02 June 2014 22:46
Target OS: Linux
Domoticz version: 3.8153
Location: Netherlands
Contact:

Re: Pass2PHP

Post by sincze » Friday 08 September 2017 21:15

Hmm have been looking at your latest Github. It looks very nice and I can imagine for the 'starter' this now becomes a little bit more complicated than in December 2016. Even I got lost. :shock:

In my mind normally all functions would be in (and known within) pass2php.php that is called by the lua.
Pass2php.php would call (include) the pass2php/devicename.php

As all functions are within the 'root' document they can be used in the childs e.g. devicename.php.

I even got lost now as I can see the separate functions.php, cleaning up pass2php.php.
However I did not find a file that would include the functions.php to actually be able to use it. (I found it witin settings.php). :lol:

In addition I can imagine you added security for the floorplan access as well as some nice custom arrows and colours.
Where it used to be floorplans as project 1 and pass2php as project 2 you managed to integrate them both. :lol:

Pieuw brainteaser.

I'm still on...
Spoiler: show

Code: Select all

<?php
error_reporting(E_ALL);
ini_set("display_errors","on");
date_default_timezone_set('Europe/Amsterdam');

//$actions=0;
// --------------------------------------------------------------------------------
// CONFIG
// --------------------------------------------------------------------------------
define('time',$_SERVER['REQUEST_TIME']);
define('domoticz','http://127.0.0.1:8080/');
define('webserver','http://127.0.0.1/');
define('port','8080');						
// --------------------------------------------------------------------------------
// DEBUG OPTIONS
// --------------------------------------------------------------------------------
define('debug','false');					// Only Print Known functions
define('logging','true');					// Only Print Known functions (Pass2PHP functions)
define('influxdb','true');					// If this is set to true data will be exported. false will prevent this
define('thermostatdebug','true');			// If this is set to true thermostat data will be shown in the log
// --------------------------------------------------------------------------------
// 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/php/pass2php/'.$device.'.php') 
		{ 
			if(debug=="true") lg('Executing device: '.$device);
			$dev=$device;
		}
}

if(!isset($dev))die();
if(debug=="true") lg('Calling __CRON.php');
include '/var/www/php/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: 2390
Joined: Thursday 09 April 2015 12:19
Target OS: Raspberry Pi
Domoticz version: BetaRPi2
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius » Friday 08 September 2017 22:41

It's indeed difficult to separate the two things as they work perfectly together
Your json decode is very long time ago...

I wanted to create the settingsfile to have all user specific stuff in there, still some work to do. Once ready it should be a lot easier to update the other files.

dilepa
Posts: 8
Joined: Thursday 16 June 2016 6:27
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Pass2PHP

Post by dilepa » Saturday 09 September 2017 10:21

Hi Egregius,

I barely started to understand your old pass2php, :shock: you have already updated. :lol: :lol: :lol:

Any particular reason you have removed apcu?

on a different note, would you run your programs from devicename.php or would you schedule it in cron jobs? Just some guidance..

Thanks :)

dilepa
Posts: 8
Joined: Thursday 16 June 2016 6:27
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Pass2PHP

Post by dilepa » Saturday 09 September 2017 11:59

Hi Egregius,

_cron604800.php is still reflecting apcu functions.

setidx is not used and none of the switch works, because the idx values are zero. :shock:

User avatar
Egregius
Posts: 2390
Joined: Thursday 09 April 2015 12:19
Target OS: Raspberry Pi
Domoticz version: BetaRPi2
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius » Saturday 09 September 2017 16:25

apcu wasn't stable here on Jessie. Did some very strange things.
My floorplan is based completely on the cache from pass2php. First evening after the update to Jessie it showed 9 of 10 times the good status but 1 of 10 times like a status of half hour before. Of course resulting in some serious flipping of the automated lights.
I instantly started to work on file based cache, have used that before.
Another advantage of this is that you can sync the cache to SD when domoticz stops. So even after a reboot you still have the cache from before.

Also updated cron604800 on github ;)

User avatar
sincze
Posts: 690
Joined: Monday 02 June 2014 22:46
Target OS: Linux
Domoticz version: 3.8153
Location: Netherlands
Contact:

Re: Pass2PHP

Post by sincze » Sunday 10 September 2017 11:36

Egregius wrote:
Saturday 09 September 2017 16:25
apcu wasn't stable here on Jessie. Did some very strange things.
My floorplan is based completely on the cache from pass2php. First evening after the update to Jessie it showed 9 of 10 times the good status but 1 of 10 times like a status of half hour before. Of course resulting in some serious flipping of the automated lights.
I instantly started to work on file based cache, have used that before.
Another advantage of this is that you can sync the cache to SD when domoticz stops. So even after a reboot you still have the cache from before.

Also updated cron604800 on github ;)
haha Mr innovator. :lol: luckily I was not able to use acpu... back in the days.
I did install it on Jessie yesterday so I will not continue with that and use memcached.

Although I already started by digging up some of your old code:
Spoiler: show

Code: Select all


function cset($key,$value){
	if(cache=='apcu'){
		apcu_store($key,$value);
	}elseif(cache=='apc'){
		apc_store($key,$value);
	}elseif(cache=='memcached'){
		if(!$m=xsMemcached::Connect('127.0.0.1',11211)){return;}$m->Set($key,$value);
	}
}

function cget($key){
	if(cache=='apcu'){
		return apcu_fetch($key);
	}elseif(cache=='apc'){
		return apc_fetch($key);
	}elseif(cache=='memcached'){
		if(!$m=xsMemcached::Connect('127.0.0.1',11211)){return 0;}return $m->Get($key);
	}
}
BTW I know you are a home automation speed / response junky.
What do your metrics say with file based cache.. Fast .. Faster .. Fastest ??
or reliable, more reliable ...
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: 2390
Joined: Thursday 09 April 2015 12:19
Target OS: Raspberry Pi
Domoticz version: BetaRPi2
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius » Sunday 10 September 2017 12:39

File based is a little bit slower than apcu but almost not measurable in pass2php.
For my floorplan I read about 80 caches, there the time needed is 3msec for apcu, 6msec for file based. So maybe 3msec divided by 80 is the speed difference between apcu en file.

And I made a huge error, it's not on Jessie that apcu wasn't stable but on Stretch (Debian 9).

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest