Pass2PHP

Moderator: leecollings

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 »

Make a php page that stores a post or get request in cache ;)
Shall I post some code later?
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 »

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: 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: 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:
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 »

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: 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 »

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';
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 »

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 / ODroid
Domoticz version:
Contact:

Re: Pass2PHP

Post by dilepa »

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 / ODroid
Domoticz version:
Contact:

Re: Pass2PHP

Post by dilepa »

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: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

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: 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: 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 ...
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 »

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).
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 Egregius,

i updated my Domoticz to the latest version => V3.8699
and what i see in the Domoticz log file now is that all commands executed by your php script are executed 2 or 3times after eachother.
Please see attached screenshot.

You can help me by pointing me in what direction in need to look for?
Thanks mate!
Attachments
2017-11-05 13_33_14-Domoticz.jpg
2017-11-05 13_33_14-Domoticz.jpg (127.36 KiB) Viewed 2373 times
mosjonathan
Posts: 40
Joined: Friday 24 February 2017 21:20
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Pass2PHP

Post by mosjonathan »

fixed in beta 8701
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 »

I've seen topics about double actions so I assume it is/was a domoticz issue.
I don't know because I don't update anymore :P
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 better staid with my older version, seems domoticz is crashing a lot now :(
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 »

Restore a backup...
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 »

Happy Birthday Pass2PHP.

Ik has been over a year I started to use this and I must say it has been worthwile. The system is running faster than ever.. Tnx @egregius.
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, and you're welcome ;)
I do wonder how far you go with it?

Speeking of fast: I recently moved from a RPi2 to a oversized Intel NUC and virtualized Debian with Domoticz in Proxmox...
In the beginning of this topic I was so happy to get response times lower than 80msec. Now they're down to 6 msec :D
DarkAllMan
Posts: 52
Joined: Friday 23 December 2016 9:41
Target OS: Linux
Domoticz version:
Contact:

Re: Pass2PHP

Post by DarkAllMan »

sincze wrote: Thursday 21 December 2017 12:36 Happy Birthday Pass2PHP.

Ik has been over a year I started to use this and I must say it has been worthwile. The system is running faster than ever.. Tnx @egregius.
Hear hear!
Egregius wrote: Friday 22 December 2017 8:48 Nice, and you're welcome ;)
I do wonder how far you go with it?

Speeking of fast: I recently moved from a RPi2 to a oversized Intel NUC and virtualized Debian with Domoticz in Proxmox...
In the beginning of this topic I was so happy to get response times lower than 80msec. Now they're down to 6 msec :D
I was already running Domoticz on a Ubuntu VM on an ESXi NUC :)
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 »

Guys guys. Tell me what to buy. :) exactly. Need for speed.

Currently running it on CubieTruck with ssd. Seems fast :) enough haha. It must be low power consuming.

I try to teach people how to use pass2php but if they look at github they are overwhelmed with confusion. And may be it lacks a bit of explanatory documentation. As I have read ALL forum posts I at least understand the power. :) your latest security additions are still a mystery to me :)



Sent from my SM-G925F using Tapatalk

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.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 0 guests