Pass2PHP
Moderator: leecollings
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: LUA Pass2php
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.
-
- Posts: 483
- Joined: Tuesday 12 August 2014 5:37
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V3_8394
- Location: Rumbeke,Belgium
- Contact:
Re: LUA Pass2php
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¶m=switchlight&idx=".$idx."&switchcmd=Toggle");
else curl(api."json.htm?type=command¶m=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¶m=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¶m=udevice&idx='.$idx.'&nvalue='.$nvalue.'&svalue='.$svalue);
usleep(400000);
}
function lg($msg)
{
curl('http://192.168.1.205:8080/json.htm?type=command¶m=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;}
-
- Posts: 483
- Joined: Tuesday 12 August 2014 5:37
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V3_8394
- Location: Rumbeke,Belgium
- Contact:
Re: LUA Pass2php
my webserver is running at 192.168.1.163
and domoticz is running at 192.168.1.205
you are correct
and domoticz is running at 192.168.1.205
you are correct
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: LUA Pass2php
At least there must be errors in domoticz and/or webserver logs. Lg(test) must drop a error because it must be lg('test')
-
- Posts: 483
- Joined: Tuesday 12 August 2014 5:37
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V3_8394
- Location: Rumbeke,Belgium
- Contact:
Re: LUA Pass2php
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)
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: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: LUA Pass2php
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.
Also check your webserver logs. Because webserver is not on same machine errors will probably not be in domoticz log.
-
- Posts: 483
- Joined: Tuesday 12 August 2014 5:37
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V3_8394
- Location: Rumbeke,Belgium
- Contact:
Re: LUA Pass2php
this log is in domoticz www ui
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: LUA Pass2php
Not good
That only shows stuff generated by domoticz.
That only shows stuff generated by domoticz.
-
- Posts: 483
- Joined: Tuesday 12 August 2014 5:37
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V3_8394
- Location: Rumbeke,Belgium
- Contact:
Re: LUA Pass2php
i activated syslog server of my nas but nothing is shown in here:
webserver log will be something dirrefent?
webserver log will be something dirrefent?
- Attachments
-
- Naamloos.jpg (120.12 KiB) Viewed 1654 times
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: LUA Pass2php
You'll need ssh and Google for that.
-
- Posts: 483
- Joined: Tuesday 12 August 2014 5:37
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V3_8394
- Location: Rumbeke,Belgium
- Contact:
Re: LUA Pass2php
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
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
-
- Posts: 483
- Joined: Tuesday 12 August 2014 5:37
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V3_8394
- Location: Rumbeke,Belgium
- Contact:
Re: LUA Pass2php
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
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: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: LUA Pass2php
Why don't you install it on the same machine as domoticz?
- 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: LUA Pass2php
I can confirm apache and domoticz running on the same machine does work with Egregius solution.Egregius wrote:Why don't you install it on the same machine as domoticz?
@Egregius: All events have been converted and disabled in Domoticz
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.
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.
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: LUA Pass2php
En response time? On what hardware and how many used devices?
- 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: LUA Pass2php
140 ms -> 133 ms.... so next step.... put everything in cset memcached to have all the speed advantages.Egregius wrote:En response time? On what hardware and how many used devices?
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.
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.
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: LUA Pass2php
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.
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.
- 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: LUA Pass2php
After flipping a Switch it shows the following: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.
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
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.
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.
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: LUA Pass2php
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)
And then 81 msecs for the php to launch? With opcode cache enabled?
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')
- 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: LUA Pass2php
Ok, I moved all scripts to archive.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)And then 81 msecs for the php to launch? With opcode cache enabled?Code: Select all
print('start') c = '' for k,v in pairs(devicechanged) do c = c..k.."|"..v.."#" end print('end')
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
root@cubietruck:/home/pi/domoticz/scripts/lua#
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
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
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.
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.
Who is online
Users browsing this forum: No registered users and 0 guests