Pass2PHP

Egregius
Posts: 2080
Joined: Thursday 09 April 2015 12:19
Target OS: Raspberry Pi
Domoticz version: 3.5877
Location: Beitem, BE
Contact:

Re: LUA Pass2php

Postby Egregius » Sunday 25 December 2016 22:24

I use Syno's webstation with nginx as engine.
But that doesn't matter.
First thing you need to start understanding is that this is totally separate from the domoticz server. Own server, own folder, own port etc.
You got it working, why do you want to place the files in the domoticz folder?

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

Re: LUA Pass2php

Postby sincze » Monday 26 December 2016 1:03

sincze wrote:Easier: Yes, everything just in a separate file, no more scrolling and searching. Your functions are even more compact as I use multiple lines. To keep a bit of a NOOB overview.
Global: Okay.. mmm have to look into that one again, Did not work first time. Did see it indeed in your php files indeed. I just copied my whole function to a new file (including the global things) and the system came back to life.
Speed: A yes I do have 0.5 sec faster light in my room that has a door 433 mhz door&motion sensor + 433 mhz kaku light switch, controlled by Domoticz via pass2php now. Before splitting it into separate files the advantage was not noticable.
opache: Well last week I did not even know what php could do for me and what memcached was :shock: , this whole experience had me update wheezy->jessie php5.4-php5.6, this week it will be googling opache then.


A yes using:
https://www.symfony.fi/entry/install-php-7-on-raspbian-raspberry-pi\
http://steveorevo.com/raspberry-pi3-and-php-7/
https://www.stewright.me/2016/03/turn-raspberry-pi-3-php-7-powered-web-server/

I was able yo update my Cubietruck ARM PHP 5.6 Jessie version to.....

Code: Select all

PHP 7.0.14-1~bpo8+1 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.14-1~bpo8+1, Copyright (c) 1999-2016, by Zend Technologies
   


Let's find out if this is a speedupdate :D
Running Domoticz since 2013 with Cubietruck
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266
Sensors: You name it I probably got 1.

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

Re: LUA Pass2php

Postby sincze » Monday 26 December 2016 1:41

sincze wrote:And the numbers are in of the 6 lookups of different .php files.

Code: Select all

0.13304 absolute stream_resolve_include_path OK
0.08202 relative stream_resolve_include_path OK
0.03505 absolute file_exists OK
0.02694 relative file_exists OK
0.12684 absolute is_file OK
0.02098 relative is_file OK



The results are in for php7. ARM Processor Apache 2

Code: Select all

0.06914 absolute stream_resolve_include_path OK
0.06104 relative stream_resolve_include_path OK
0.05794 absolute file_exists OK
0.03219 relative file_exists OK
0.04387 absolute is_file OK
0.17309 relative is_file OK


Some improvements.... However not that much if you average this out in 20x Refresh of the page.
Running Domoticz since 2013 with Cubietruck
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266
Sensors: You name it I probably got 1.

Egregius
Posts: 2080
Joined: Thursday 09 April 2015 12:19
Target OS: Raspberry Pi
Domoticz version: 3.5877
Location: Beitem, BE
Contact:

Re: LUA Pass2php

Postby Egregius » Monday 26 December 2016 8:12

No you measured just 1 function. If you measure a whole script I'm sure it'll be faster.

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

Re: RE: Re: LUA Pass2php

Postby sincze » Monday 26 December 2016 11:14

Egregius wrote:No you measured just 1 function. If you measure a whole script I'm sure it'll be faster.

Ok check :). I'm liking that PhP more and more every day.

Sent from my SM-G925F using Tapatalk
Running Domoticz since 2013 with Cubietruck
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266
Sensors: You name it I probably got 1.

denisj
Posts: 62
Joined: Saturday 17 December 2016 14:13
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: LUA Pass2php

Postby denisj » Monday 26 December 2016 11:31

Can you post your apache virtualhost piece of code here please ?
Thnks again
Denis

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

Re: RE: Re: LUA Pass2php

Postby sincze » Monday 26 December 2016 11:46

Egregius wrote:No you measured just 1 function. If you measure a whole script I'm sure it'll be faster.

Let's start fun stuff with PhP controlling light settings of my milights. An add that as well. Flash RED when somebody presses the doorbell.

Sent from my SM-G925F using Tapatalk
Running Domoticz since 2013 with Cubietruck
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266
Sensors: You name it I probably got 1.

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

Re: RE: Re: LUA Pass2php

Postby sincze » Monday 26 December 2016 11:47

denisj wrote:Can you post your apache virtualhost piece of code here please ?
Thnks again
Denis

Who me? Or just anybody?

Sent from my SM-G925F using Tapatalk
Running Domoticz since 2013 with Cubietruck
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266
Sensors: You name it I probably got 1.

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

Re: RE: Re: LUA Pass2php

Postby sincze » Monday 26 December 2016 11:57

sincze wrote:
denisj wrote:Can you post your apache virtualhost piece of code here please ?
Thnks again
Denis

Who me? Or just anybody?

Code: Select all

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin [email protected]
#       DocumentRoot /var/www/html
        DocumentRoot /var/www

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

Sent from my SM-G925F using Tapatalk
Running Domoticz since 2013 with Cubietruck
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266
Sensors: You name it I probably got 1.

denisj
Posts: 62
Joined: Saturday 17 December 2016 14:13
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: LUA Pass2php

Postby denisj » Monday 26 December 2016 14:37

Thanks a lot but I finally finish to setting apache+php to work
And also installed the free SSL certificates
Here is my conf if can help anybody:

Code: Select all

<VirtualHost *:80>
    ServerName xxx.me
    ServerAlias *.xxx.me
    Redirect "/" "https://www.xxx.me/"
</VirtualHost>

<VirtualHost *:443>
 ServerAdmin [email protected]
 DocumentRoot /etc/domoticz/www
 DirectoryIndex index.php index.html
 ServerName xxx.me
 ServerAlias *.xxx.me

 <Directory /etc/domoticz/www>
        Options Indexes FollowSymLinks
        RewriteEngine On
        AllowOverride None
        Require all granted
</Directory>

#Don't proxy *.php, these files will pass trough apache server
 ProxyRequests  off
 ProxyPassMatch ^/(.*\.php)$ !
#Redirect every call to domoticz www (running in port 8080)
 ProxyPass / http://127.0.0.1:8080/
 ProxyPassReverse / http://127.0.0.1:8080/
 ProxyPreserveHost on
 <Proxy *>
 Order allow,deny
 Allow from all
 </Proxy>

 ErrorLog  ${APACHE_LOG_DIR}/error.log
 CustomLog  ${APACHE_LOG_DIR}/access.log combined
#SSL cestificates
 SSLCertificateFile /etc/letsencrypt/live/xxx.me/fullchain.pem
 SSLCertificateKeyFile /etc/letsencrypt/live/xxx.me/privkey.pem
 Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>



Now I finally have apache+php work (I uninstalled nginx)
:-)

Denis

denisj
Posts: 62
Joined: Saturday 17 December 2016 14:13
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: LUA Pass2php

Postby denisj » Monday 26 December 2016 20:39

Egregius,
is possible to adapt your code to a frontpage packet in order to use it with a tablet on wall ?
I understand that the php code is to complicated for me ... I'm not a programmer so I'm not able to install it.
Maibe can be useful and nice think for a big number of users :-)
Thanks
Denis

Egregius
Posts: 2080
Joined: Thursday 09 April 2015 12:19
Target OS: Raspberry Pi
Domoticz version: 3.5877
Location: Beitem, BE
Contact:

Re: LUA Pass2php

Postby Egregius » Monday 26 December 2016 20:48

The frontpage calls php floorplan, see my github and/or viewtopic.php?f=8&t=7551
But, you may not be afraid of some code and trial/error.
Once you got it running it's fantastic.

denisj
Posts: 62
Joined: Saturday 17 December 2016 14:13
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: LUA Pass2php

Postby denisj » Monday 26 December 2016 20:59

Thanks Egregius,
but what i mean is that I want to make a frontpage packet that will stay on wall tablet
just with box, and not include a florplan like you application.

Here on forum exist already some nice frontpage for tablet
I think they work via java script json request...
...but I like you idea that work more quickly :-)

Thanks again
Denis

denisj
Posts: 62
Joined: Saturday 17 December 2016 14:13
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: LUA Pass2php

Postby denisj » Monday 26 December 2016 21:01

I think I will go to undestand your small sample here
https://egregius.be/2016/lua-pass2php-v ... planation/

And maybe if you let me, I will make a frontpage with box like in order to use it for a tablet
:-)

Denis

Egregius
Posts: 2080
Joined: Thursday 09 April 2015 12:19
Target OS: Raspberry Pi
Domoticz version: 3.5877
Location: Beitem, BE
Contact:

Re: LUA Pass2php

Postby Egregius » Monday 26 December 2016 23:01

You should at least use https://egregius.be/2016/lua-pass2php-v ... al-script/ or better the code from github.
With the newest version it doesn't even matter what I had in it of functions.

I share 2 php based scripts:
Lua pass2php => only for events, actions, automation, notifications,...
PHP Floorplan => graphical interace based on a floorplan with switches and everything on it.
Both are individual scripts that can work standalone, or they can be combined powers in it.

Like I wrote several times, you're absolutely free to do with this whatever you want, if you don't want it, don't use it. Simple for me.
Both require some effort to get them operational, and both give so much more power to Domoticz. Without them I would have stopped with domotica all together.

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

Re: LUA Pass2php

Postby sincze » Wednesday 28 December 2016 13:09

Egregius wrote:You should at least use https://egregius.be/2016/lua-pass2php-v ... al-script/ or better the code from github.
With the newest version it doesn't even matter what I had in it of functions.

I share 2 php based scripts:
...

Like I wrote several times, you're absolutely free to do with this whatever you want, if you don't want it, don't use it. Simple for me.
.


Hi Egregius, Thanks to you I am into PHP right now :lol:
I missed a feature in your php dealing with RGB strips/lights. Probably you don't use it otherwise it would be in 8-) I am sure.
I used a PHP library for controlling the Milight LED lights (flashing when doorbell rings fun stuff like that).
But then I thought... How did Egregius do it.... And I rewrote a function to my needs.

Code: Select all

//CUSTOM GLOBAL FUNCTIONS
function rgb($idx,$colour,$level,$hue,$info=''){
   if(logging==true)lg('SET RGB-WW colbrightness '.$hue.' '.$level.' '.$info.' ',$colour);
   if ($colour=='white')
   {
      curl(domoticz.'json.htm?type=command&param=setcolbrightnessvalue&idx='.$idx.'&hue='.$hue.'&brightness='.$level.'&iswhite=true');

   }
   else
   {
      curl(domoticz.'json.htm?type=command&param=setcolbrightnessvalue&idx='.$idx.'&hue='.$hue.'&brightness='.$level.'&iswhite=false');
      
   }   
}


This will enable me to select a colour and brightness or have the white light enabled ;-)

To have it flashing I could added a function flashgreen() to the doorbell function:
Function could be a little bit more practical like rgbflash($colour) so you can add a colour name.. I don't know yet what is more practical.

Code: Select all

      if ($s['Lamp LED TV']!="Off")
      {
         for ($counter = 1; $counter <= 4; $counter++)
         {
         rgb($i['Lamp LED TV'],'rgb',50,106,'Colour Green');
         sleep(0.3);
         rgb($i['Lamp LED TV'],'white',25,106,'Colour White');
         sleep(0.3);
         }
      }   


I also don't know if sleep is an overall good ID to slow the whole thing (domoticz) down?
Running Domoticz since 2013 with Cubietruck
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266
Sensors: You name it I probably got 1.

Egregius
Posts: 2080
Joined: Thursday 09 April 2015 12:19
Target OS: Raspberry Pi
Domoticz version: 3.5877
Location: Beitem, BE
Contact:

Re: LUA Pass2php

Postby Egregius » Wednesday 28 December 2016 13:22

Great :) See, php isn't that hard to learn.

I don't use rgb :P

The sleep shouldn't be a problem because multiple scripts can run simultaneous, the one with the sleep in will not hold up the others.
Does the sleep 0.3 works? Tought I tested that before and didn't work, I then turned to usleep(300000) wich sleeps x microseconds.

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

Re: LUA Pass2php

Postby sincze » Wednesday 28 December 2016 14:57

Egregius wrote:Great :) See, php isn't that hard to learn.

I don't use rgb :P

The sleep shouldn't be a problem because multiple scripts can run simultaneous, the one with the sleep in will not hold up the others.
Does the sleep 0.3 works? Tought I tested that before and didn't work, I then turned to usleep(300000) wich sleeps x microseconds.


I learned also that RFLINK deals with my COCO doorbell in a different way: "Group On" vs "Chime" when using the RFXCom.
The 'Chime' is again interpreted by the rflink as "On" make it a little more complicated. A well.
Great to learn all this with $s :lol:

The light is flashing at 0.3.... with a certain pause. However that might as well be because of the rflink commands it receives. So needs more investigation. Got some more learning to do. Like when to use the include at the beginning of the script of how PHP deals with variables like the global ones I do seem to need them in my separate php files.

Code: Select all

function Deurbel()
{
    global 
$s,$i,$debug,$domoticz_host,$domoticz_port;
    ....
 


.
Running Domoticz since 2013 with Cubietruck
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266
Sensors: You name it I probably got 1.

Egregius
Posts: 2080
Joined: Thursday 09 April 2015 12:19
Target OS: Raspberry Pi
Domoticz version: 3.5877
Location: Beitem, BE
Contact:

Re: LUA Pass2php

Postby Egregius » Wednesday 28 December 2016 15:05

You still use the version with the functions?
With the new version you don't need that anymore as the function is the whole file. So also no need to do the global thing anymore.
FYI: global is needed to use a variable that is declared outside the function.

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

Re: LUA Pass2php

Postby sincze » Wednesday 28 December 2016 15:25

Egregius wrote:You still use the version with the functions?
With the new version you don't need that anymore as the function is the whole file. So also no need to do the global thing anymore.
FYI: global is needed to use a variable that is declared outside the function.


Let me check the latest Github. Currently I use t he pass2php where we defined:

Code: Select all

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

// CONFIG
define('time',$_SERVER['REQUEST_TIME']);
define('domoticz','http://192.168.2.10:8080/');
define('webserver','http://127.0.0.1/');

$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);

$r=str_replace(" ","_",key($c));
$c2=key($c);

$domoticz_host="192.168.2.10";
$domoticz_port="8080";

// --------------------------------------------------------------------------------
// DEBUG OPTIONS
// --------------------------------------------------------------------------------
$debug="true";                // Only Print Known functions
$debug2="false";            // JUST PRINT EVERY
$debug3="true";            // JUST PRINT EVERY

 if($debug2=="true")
    {
    lg('Pass2PHP echo functie is: '.$c2);
    lg('Pass2PHP de functie reversed: '.$r);
    }
// --------------------------------------------------------------------------------

 if(is_file('pass2php/'.key($c).'.php'))                // Added this function 25-12-2016, faster than file_exists
     { include 'pass2php/'.key($c).'.php';
       $c2();
         if($debug3=="true")
        {
        lg('Step 1: Pass2PHP running de file bestaat: '.key($c));
         lg('Step 2: Pass2PHP running echo file functie is: '.$c2);
        }     
     
}
 elseif(is_file('pass2php/'.($r).'.php'))                // Added this function 25-12-2016, faster than file_exists
     { include 'pass2php/'.($r).'.php';
        $r();
         if($debug3=="true")
        {
         lg('Step 3: Pass2PHP running echo file functie is REVERSED: '.$r);
        }     
     
}
 


If I remove the globals from the functions in the separate files it does not work for me. For example the $s stays empty.
Running Domoticz since 2013 with Cubietruck
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266
Sensors: You name it I probably got 1.


Return to “PHP and all others”

Who is online

Users browsing this forum: No registered users and 0 guests