Page 1 of 1
can't get domoticz_updateDevice working
Posted: Friday 05 August 2016 8:48
by Number8
Hello,
I setup a LUA script as explained here:
https://www.domoticz.com/wiki/Inserting ... ua_parsers.
The callback works fine, domoticz log file reports:
Code: Select all
2016-08-05 08:18:25.194 CLuaHandler (updateDevice from LUA) : idx=266 nvalue=0 svalue=228.4 invalue=0 signallevel=12 batterylevel=255
which is what is expected.
However the dummy voltage sensor never gets updated.
If I use the following json command, it is updated
Code: Select all
http://192.168.21.240:8080/json.htm?type=command¶m=udevice&idx=266&nvalue=0&svalue=200
Here is the LUA parser code:
Code: Select all
local tensionAC = uri['tensionAC']
domoticz_updateDevice(266,0,tensionAC)
Thank you
Re: can't get domoticz_updateDevice working
Posted: Friday 05 August 2016 11:14
by Number8
Should have added I'm running v3.5259 on a RaspPI. Just updated to the last beta 5406. No change
Re: can't get domoticz_updateDevice working
Posted: Saturday 06 August 2016 8:29
by Number8
Anybody?
Thanks
Re: can't get domoticz_updateDevice working
Posted: Saturday 06 August 2016 10:31
by SweetPants
The example in the documentation talks about:
Callback : http://<domoticz ip>:<domoticz port>/json.htm?type=command¶m='''udevices'''&script='''yoctopuce_meteo.lua'''&
If domoticz_updateDevice uses that, it won;t work.
Domoticz needs ¶m=udevice (no s), and as you already noticed, that works.
Re: can't get domoticz_updateDevice working
Posted: Saturday 06 August 2016 10:46
by Number8
Thanks SweetPants.
Indeed the Wiki is wrong. The callback that I setup is not as per Wiki, it is the following and so far is correct. To me the "s" is needed
Code: Select all
IPAddress:port/json.htm?type=command¶m=udevices&script=yoctopuce.lua&
since Domoticz log reports
Code: Select all
2016-08-05 08:18:25.194 CLuaHandler (updateDevice from LUA) : idx=266 nvalue=0 svalue=228.4 invalue=0 signallevel=12 batterylevel=255
However the idx device 266 never gets updated.
Is it a bug of domoticz_updateDevice function, or am I missing something?
Re: can't get domoticz_updateDevice working
Posted: Saturday 06 August 2016 10:53
by SweetPants
Well i still see the extra 's' in your callback.(IPAddress:port/json.htm?type=command¶m=udevices&script=yoctopuce.lua&).
And as the JSON works, i tend to believe it's a problem of domoticz_updateDevice
Re: can't get domoticz_updateDevice working
Posted: Saturday 06 August 2016 10:54
by Number8
it is indeed needed, or the callback is not fired.
Re: can't get domoticz_updateDevice working
Posted: Saturday 06 August 2016 18:15
by Number8
I dig a bit into LuaHandler.cpp. It seems to me that ID should be selected in the DB instead of DeviceID
Code: Select all
int CLuaHandler::l_domoticz_updateDevice(lua_State* lua_state)
{
int nargs = lua_gettop(lua_state);
if (nargs >= 3 && nargs <= 5)
{
// Supported format ares :
// - deviceId (integer), svalue (string), nvalue (string), [rssi(integer)], [battery(integer)]
// - deviceId (integer), svalue (string), nvalue (integer), [rssi(integer)], [battery(integer)]
if (lua_isnumber(lua_state, 1) && (lua_isstring(lua_state, 2) || lua_isnumber(lua_state, 2)) && lua_isstring(lua_state, 3))
{
// Extract the parameters from the lua 'updateDevice' function
int ideviceId = (int)lua_tointeger(lua_state, 1);
std::string nvalue = lua_tostring(lua_state, 2);
std::string svalue = lua_tostring(lua_state, 3);
if (((lua_isstring(lua_state, 3) && nvalue.empty()) && svalue.empty()))
{
_log.Log(LOG_ERROR, "CLuaHandler (updateDevice from LUA) : nvalue and svalue are empty ");
return 0;
}
// Parse
int invalue = (!nvalue.empty()) ? atoi(nvalue.c_str()) : 0;
int signallevel = 12;
if (nargs >= 4 && lua_isnumber(lua_state, 4))
{
signallevel = (int)lua_tointeger(lua_state, 4);
}
int batterylevel = 255;
if (nargs == 5 && lua_isnumber(lua_state, 5))
{
batterylevel = (int)lua_tointeger(lua_state, 5);
}
_log.Log(LOG_NORM, "CLuaHandler (updateDevice from LUA) : idx=%d nvalue=%s svalue=%s invalue=%d signallevel=%d batterylevel=%d", ideviceId, nvalue.c_str(), svalue.c_str(), invalue, signallevel, batterylevel);
// Get the raw device parameters
std::vector<std::vector<std::string> > result;
result = m_sql.safe_query("SELECT HardwareID, DeviceID, Unit, Type, SubType FROM DeviceStatus WHERE (DeviceID==%d)", ideviceId);
if (result.empty())
return 0;
std::string hid = result[0][0];
std::string did = result[0][1];
std::string dunit = result[0][2];
std::string dtype = result[0][3];
std::string dsubtype = result[0][4];
int HardwareID = atoi(hid.c_str());
std::string DeviceID = did;
int unit = atoi(dunit.c_str());
int devType = atoi(dtype.c_str());
int subType = atoi(dsubtype.c_str());
std::stringstream sstr;
unsigned long long ulIdx;
sstr << ideviceId;
sstr >> ulIdx;
m_mainworker.UpdateDevice(HardwareID, DeviceID, unit, devType, subType, invalue, svalue, signallevel, batterylevel);
}
else
{
_log.Log(LOG_ERROR, "CLuaHandler (updateDevice from LUA) : Incorrect parameters type");
}
}
else
{
_log.Log(LOG_ERROR, "CLuaHandler (updateDevice from LUA) : Not enough parameters");
}
return 0;
}
Re: can't get domoticz_updateDevice working
Posted: Monday 08 August 2016 14:40
by Number8
Is anyboby willing to have a look at what seems to be a bug? (reported also here :
http://www.domoticz.com/forum/viewtopic ... 604#p92604
Thank you
Re: can't get domoticz_updateDevice working
Posted: Wednesday 19 October 2016 19:46
by FrBoulli
Re: can't get domoticz_updateDevice working
Posted: Wednesday 19 October 2016 22:52
by Number8
Thanks FrBoulli. Does that mean that it will be fixed in the next build?