Pass2PHP

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

Re: LUA Pass2php

Postby Egregius » Thursday 05 January 2017 21:14

That's an old version and you didn't change the ip address of domoticz in the functions at the bottom. I asume your webserver isn't the same as your domoticz because you entered that ip in the lua file.

ropske
Posts: 162
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi
Domoticz version: V3_6235
Location: Rumbeke,Belgium
Contact:

Re: LUA Pass2php

Postby ropske » Thursday 05 January 2017 21:43

if i try it with this version it also not works:

Code: Select all

<?php
lg(test);
error_reporting(E_ALL);ini_set("display_errors","on");date_default_timezone_set('Europe/Amsterdam');
define('api',"http://192.168.1.205:8080/");
$t=microtime(true);$micro=sprintf("%03d",($t-floor($t))*1000);define('stamp',strftime("%Y-%m-%d %H:%M:%S.", $t).$micro);
$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);$a=$s[key($c)];$devidx=$i[key($c)];
//Create the array of events. Wich idx calls wich function?
$events=array(151=>'Test_switch');
if(isset($events[$devidx]))call_user_func($events[$devidx]);
//Start of user functions
function Test_switch(){
    global $a,$s,$i,$t;
    if($a=="On"){
        sw($i['Ledlampenzolder'],'On');
    }
    if($a=="Off"){
        sw($i['Ledlampenzolder'],'Off');
    }
}
//End of user functions
// ========== FUNCTIONS ==========
/* sw switches $idx on/off. If no action is provided a toggle is made. $info is optional logging */
function sw($idx,$action="",$info=""){
    $t=microtime(true);$micro=sprintf("%03d",($t-floor($t))*1000);$stamp=strftime("%Y-%m-%d %H:%M:%S.", $t).$micro;
    print $stamp."          Switch ".$idx." (".ucfirst($info).") ".strtoupper($action)."
";
    if(empty($action)) curl(api."json.htm?type=command&param=switchlight&idx=".$idx."&switchcmd=Toggle");
    else curl(api."json.htm?type=command&param=switchlight&idx=".$idx."&switchcmd=".$action);
    usleep(400000);
}
/* sl sets dimmer $idx to level $level. $info is optional logging */
function sl($idx,$level,$info=""){
    $t=microtime(true);$micro=sprintf("%03d",($t-floor($t))*1000);$stamp=strftime("%Y-%m-%d %H:%M:%S.", $t).$micro;
    print $stamp."        Set Level ".$idx." ".ucfirst($info)." ".$level."
";
    curl(api . "json.htm?type=command&param=switchlight&idx=".$idx."&switchcmd=Set%20Level&level=".$level);
    usleep(400000);
}
/* ud updates a device $idx with $nvalue and $svalue. $info is optional logging */
function ud($idx,$nvalue,$svalue,$info=""){
    $t=microtime(true);$micro=sprintf("%03d",($t-floor($t))*1000);$stamp=strftime("%Y-%m-%d %H:%M:%S.", $t).$micro;
    if(!in_array($idx, array(395,532,534))) print $stamp."  --- UPDATE ".$idx." ".$info." ".$nvalue." ".$svalue."
";
    curl(api.'json.htm?type=command&param=udevice&idx='.$idx.'&nvalue='.$nvalue.'&svalue='.$svalue);
    usleep(400000);
}
function lg($msg)
{
   curl('http://192.168.1.205:8080/json.htm?type=command&param=addlogmessage&message='.urlencode('=> '.$msg));
}
function curl($url){dl("curl.so");$headers=array('Content-Type: application/json',);$ch=curl_init();curl_setopt($ch,CURLOPT_URL,$url);curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);curl_setopt($ch, CURLOPT_FRESH_CONNECT, TRUE);$data=curl_exec($ch);curl_close($ch);return $data;}
 

ropske
Posts: 162
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi
Domoticz version: V3_6235
Location: Rumbeke,Belgium
Contact:

Re: LUA Pass2php

Postby ropske » Thursday 05 January 2017 21:47

my webserver is running at 192.168.1.163
and domoticz is running at 192.168.1.205

you are correct ;)

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

Re: LUA Pass2php

Postby Egregius » Thursday 05 January 2017 22:41

At least there must be errors in domoticz and/or webserver logs. Lg(test) must drop a error because it must be lg('test')

ropske
Posts: 162
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi
Domoticz version: V3_6235
Location: Rumbeke,Belgium
Contact:

Re: LUA Pass2php

Postby ropske » Thursday 05 January 2017 22:46

no errors :(

this is what i have in log:
2017-01-05 21:46:25.142 LUA: PHP script runs
2017-01-05 21:46:24.805 (Open zwave usb) Usage (Verbruik Droogkast)
2017-01-05 21:46:25.585 LUA: PHP script runs
2017-01-05 21:46:25.252 (Open zwave usb) General/kWh (Totaal verbruik droogkast)
2017-01-05 21:46:26.034 LUA: PHP script runs
2017-01-05 21:46:25.691 (Open zwave usb) Usage (Verbruik vaatwas)
2017-01-05 21:46:26.623 LUA: PHP script runs
2017-01-05 21:46:26.143 (Open zwave usb) General/kWh (Totaal verbruik vaatwas)
2017-01-05 21:46:27.302 LUA: PHP script runs
2017-01-05 21:46:26.766 (Open zwave usb) Usage (Verbruik vaatwas)
2017-01-05 21:46:28.010 LUA: PHP script runs
2017-01-05 21:46:27.475 (Open zwave usb) General/kWh (Totaal verbruik vaatwas)
2017-01-05 21:46:28.491 LUA: PHP script runs
2017-01-05 21:46:28.151 (Open zwave usb) Usage (Verbruik vaatwas)
2017-01-05 21:46:28.596 (Open zwave usb) General/kWh (Totaal verbruik vaatwas)
2017-01-05 21:46:30.878 LUA: PHP script runs
2017-01-05 21:46:30.668 (Stijn) Temp (Living)
2017-01-05 21:46:31.367 LUA: PHP script runs
2017-01-05 21:46:31.153 (Stijn) Temp + Humidity (Kinderen)

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

Re: LUA Pass2php

Postby Egregius » Thursday 05 January 2017 22:59

Is that the log from domoticz www ui or through ssh? There's a difference.
Also check your webserver logs. Because webserver is not on same machine errors will probably not be in domoticz log.

ropske
Posts: 162
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi
Domoticz version: V3_6235
Location: Rumbeke,Belgium
Contact:

Re: LUA Pass2php

Postby ropske » Thursday 05 January 2017 23:01

this log is in domoticz www ui

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

Re: LUA Pass2php

Postby Egregius » Thursday 05 January 2017 23:04

Not good :P
That only shows stuff generated by domoticz.

ropske
Posts: 162
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi
Domoticz version: V3_6235
Location: Rumbeke,Belgium
Contact:

Re: LUA Pass2php

Postby ropske » Thursday 05 January 2017 23:07

i activated syslog server of my nas but nothing is shown in here:

webserver log will be something dirrefent?
Attachments
Naamloos.jpg
Naamloos.jpg (120.12 KiB) Viewed 425 times

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

Re: LUA Pass2php

Postby Egregius » Thursday 05 January 2017 23:09

You'll need ssh and Google for that.

ropske
Posts: 162
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi
Domoticz version: V3_6235
Location: Rumbeke,Belgium
Contact:

Re: LUA Pass2php

Postby ropske » Thursday 05 January 2017 23:56

lol i quit searching
i better bought another NAS server instead of this Zyxell NAS540
Almost no support, not many 'extra' packages available.
Installed 'Entware' a 3th party plugin
but you can't set the Zyxell much to 'your hands' :(

i wanted to run my php pages on this webserver
is there maybe another way to setup a php webserver somewhere else? :s

ropske
Posts: 162
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi
Domoticz version: V3_6235
Location: Rumbeke,Belgium
Contact:

Re: LUA Pass2php

Postby ropske » Thursday 05 January 2017 23:59

apt-get is not working here
opkg should be working according to forum, but like many people, it's not working, so it's difficult to install some things

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

Re: LUA Pass2php

Postby Egregius » Friday 06 January 2017 0:44

Why don't you install it on the same machine as domoticz?

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

Re: LUA Pass2php

Postby sincze » Friday 06 January 2017 21:12

Egregius wrote:Why don't you install it on the same machine as domoticz?


I can confirm apache and domoticz running on the same machine does work :D with Egregius solution.

@Egregius: All events have been converted and disabled in Domoticz :lol: :lol:
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: 2082
Joined: Thursday 09 April 2015 12:19
Target OS: Raspberry Pi
Domoticz version: 3.5877
Location: Beitem, BE
Contact:

Re: LUA Pass2php

Postby Egregius » Friday 06 January 2017 22:25

En response time? On what hardware and how many used devices?

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

Re: LUA Pass2php

Postby sincze » Saturday 07 January 2017 1:24

Egregius wrote:En response time? On what hardware and how many used devices?


140 ms -> 133 ms.... so next step.... put everything in cset memcached to have all the speed advantages. :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.

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

Re: LUA Pass2php

Postby Egregius » Saturday 07 January 2017 9:28

Can you check where the time is lost?
Add 3 lines to the lua file:
print('encoding started')
print('encoding finished')
print('curl finished')
and a lg function in the php file at the start.

The memcached/apcu will only be several milliseconds, not 100.

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

Re: LUA Pass2php

Postby sincze » Sunday 08 January 2017 2:06

Egregius wrote:Can you check where the time is lost?
Add 3 lines to the lua file:
print('encoding started')
print('encoding finished')
print('curl finished')
and a lg function in the php file at the start.

The memcached/apcu will only be several milliseconds, not 100.


After flipping a Switch it shows the following:

Code: Select all

2017-01-08 01:04:15.032 User: Admin initiated a switch command (621/ZonweringAuto/On)
2017-01-08 01:04:15.069 LUA: 1. encoding started
2017-01-08 01:04:15.073 LUA: 2. encoding finished
2017-01-08 01:04:15.085 LUA: 3. curl finished
2017-01-08 01:04:15.033 (Virtual Device) Light/Switch (ZonweringAuto)
2017-01-08 01:04:15.154 --->> 4. Egregius Start of Pass2PHP
2017-01-08 01:04:15.157 --->> SETLEVEL 100
2017-01-08 01:04:15.160 User: Admin initiated a switch command (531/Lamp (CV Ruimte) (RF)/Set Level)
2017-01-08 01:04:15.161 RFLink Sending: 10;NewKaku;ba1e09;a;15
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: 2082
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 08 January 2017 17:29

That's strange. You already lose 37msecs for the lua to start. Sure your scripts folders are empty, except the pass2php script?
The encoding, is that just the devicechanged table?
Because this takes 9/10 times less than 1 msec (same timestamp in logfile)

Code: Select all

print('start')
c = ''
for k,v in pairs(devicechanged) do c = c..k.."|"..v.."#" end
print('end')

And then 81 msecs for the php to launch? With opcode cache enabled?

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

Re: LUA Pass2php

Postby sincze » Sunday 08 January 2017 19:10

Egregius wrote:That's strange. You already lose 37msecs for the lua to start. Sure your scripts folders are empty, except the pass2php script?
The encoding, is that just the devicechanged table?
Because this takes 9/10 times less than 1 msec (same timestamp in logfile)

Code: Select all

print('start')
c = ''
for k,v in pairs(devicechanged) do c = c..k.."|"..v.."#" end
print('end')

And then 81 msecs for the php to launch? With opcode cache enabled?


Ok, I moved all scripts to archive.

Code: Select all

drwxr-xr-x 2 root root 4096 Jan  8 17:59 archive
drwxr-xr-x 2 root root 4096 Jan  8 17:56 converted2db
-rw-r--r-- 1 root root  734 Jan  8 01:06 script_device_pass2php.lua
[email protected]:/home/pi/domoticz/scripts/lua#


Pass2php.lua is currently based on sneezydevil cjson. As not all has been rewritten to cset/cget memcached style.

Code: Select all

local cb64json = require "cb64json"

c=cb64json.b64encode(cb64json.encode(devicechanged))
s=cb64json.b64encode(cb64json.encode(otherdevices))
i=cb64json.b64encode(cb64json.encode(otherdevices_idx))
t=cb64json.b64encode(cb64json.encode(otherdevices_lastupdate))

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

commandArray={}
return commandArray


This is the result.

Code: Select all

2017-01-08 18:06:24.962 User: Admin initiated a switch command (621/ZonweringAuto/On)
2017-01-08 18:06:25.011 LUA: 1. encoding started
2017-01-08 18:06:25.014 LUA: 2. encoding finished
2017-01-08 18:06:25.027 LUA: 3. curl finished
2017-01-08 18:06:24.964 (Virtual Device) Light/Switch (ZonweringAuto)
2017-01-08 18:06:25.103 --->> 4. Egregius Start of Pass2PHP
2017-01-08 18:06:25.108 --->> SETLEVEL 100
2017-01-08 18:06:25.114 User: Admin initiated a switch command (531/Lamp (CV Ruimte) (RF)/Set Level)
2017-01-08 18:06:25.120 RFLink Sending: 10;NewKaku;ba1e09;a;15


And the in database events are all disabled.
egregius_disabled.JPG
egregius_disabled.JPG (39.22 KiB) Viewed 254 times
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