set user variable fails when -webroot is used
Posted: Sunday 17 December 2017 21:59
Hi all,
I'm trying to set a user variable from a dzVents script (so that another script can trigger on it). I think it is failing because I start domoticz with the -webroot option:
Then, when from a dzVents script I try to set a user variable:
This result in an error message in the domoticz log:
... which is indeed incorrect because the webroot is missing in the url. It should start with http://127.0.0.1:8081/domoticz/json.html?...
It seems to me two things should be done to fix this. First, in main/EventSystem.cpp, in EventSystem::EvaluateLua(), the Lua global variable 'globalvariables' is set, including the domoticz_listening_port. Here domoticz_webroot should be added with code like this:
I'm not sure where the webroot is stored in domoticz.
Second, in dzVents/runtime/EventHelpers.lua the line
should be something like
(except that this add a superfluous / when the webroot is empty).
Am I thinking in the right direction? BTW, running Domoticz 3.8153 with the included dzVents 2.2.0.
Thanks for any help,
Jan-Pascal
I'm trying to set a user variable from a dzVents script (so that another script can trigger on it). I think it is failing because I start domoticz with the -webroot option:
Code: Select all
-daemon -www 8081 -sslwww 0 -log /var/log/domoticz/log.txt -webroot domoticz -verbose 2 -pidfile $PIDFILE -userdata /var/lib/domoticz/ -dbase /var/lib/domoticz/domoticz.db -loglevel 3
Code: Select all
domoticz.variables('AlarmDetected').set(1)
Code: Select all
Error opening url: http://127.0.0.1:8081/json.htm?type=command¶m=updateuservariable&vname=AlarmDetected&vtype=0&vvalue=1&idx=1
It seems to me two things should be done to fix this. First, in main/EventSystem.cpp, in EventSystem::EvaluateLua(), the Lua global variable 'globalvariables' is set, including the domoticz_listening_port. Here domoticz_webroot should be added with code like this:
Code: Select all
lua_pushstring(lua_state, "domoticz_webroot");
lua_pushstring(lua_state, <SOMETHING>);
lua_rawset(lua_state, -3);
Second, in dzVents/runtime/EventHelpers.lua the line
Code: Select all
['Domoticz url'] = 'http://127.0.0.1:' .. (tostring(globalvariables['domoticz_listening_port']) or "8080")
Code: Select all
['Domoticz url'] = 'http://127.0.0.1:' .. (tostring(globalvariables['domoticz_listening_port']) or "8080") .. '/' ..(tostring(globalvariables['domoticz_webroot']) or ''')
Am I thinking in the right direction? BTW, running Domoticz 3.8153 with the included dzVents 2.2.0.
Thanks for any help,
Jan-Pascal