@Egregius
I am busy installing LUA pass2php, but having an error message running a test.
I get:
Code: Select all
Notice: Undefined index: Ledlampenzolder in /var/www/html/fp/php/secure/pass2php.php on line 14
Code: Select all
Fatal error: Call to undefined function dl
This is my pass2php lua file.
Code: Select all
function execute(command)
-- returns success, error code, output.
local f = io.popen(command..' 2>&1 && echo " $?"')
local output = f:read"*a"
return output
end
JSON=loadfile('/home/gerard/domoticz/scripts/lua/functions/JSON.lua')()
base64=loadfile('/home/gerard/domoticz/scripts/lua/functions/base64.lua')()
c=base64.encode(JSON:encode(devicechanged))
s=base64.encode(JSON:encode(otherdevices))
i=base64.encode(JSON:encode(otherdevices_idx))
t=base64.encode(JSON:encode(otherdevices_lastupdate))
--str=execute('/volume1/web/secure/pass2php.php "'..c..'" "'..s..'" "'..i..'" "'..t..'" &')
str=execute('curl -s --data "c='..c..'&s='..s..'&i='..i..'&t='..t..'" http://127.0.0.1/fp/php/secure/pass2php.php &')
print(str)
commandArray={}
print('PHP script runs')
return commandArray
And the PHP page
Code: Select all
#!/usr/bin/php
<?php
error_reporting(E_ALL);ini_set("display_errors","on");date_default_timezone_set('Europe/Amsterdam');
define('api',"http://127.0.0.1:8084/");
$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(369=>'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 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;}
Any ideas what I can do to fix this?