peterbos wrote: Friday 01 January 2021 17:27
Hi Waaren,
Maybe your solution works but I can't trigger the custom event from a browser with the simple command. I found out that the problem was not in the URL but in the script. The check if the data is a JSON fails but the data is treated as a JSON correctly.
I cannot replicate your issue so I can only guess you are on a version before build 12019
In this version I made the check for valid JSON strings a bit more forgiving. According the standard a JSON string cannot start with a curly bracket but because the Lua JSON decoder does allow it, I changed dzVents behavior in versions > 12019 to accept them as valid JSON
What do you see when you repeat my tests?
Code: Select all
--[[
(my test system runs on a system named nuc and I use port 8084 for my test / development domotcicz)
test in Browser window
http://nuc:8084/json.htm?type=command¶m=customevent&event=testTrigger&data={"field1":"This is field 1","field2":"This is field 2"}
2021-01-01 18:30:39.902 Status: dzVents: Info: testCustomEvent: ------ Start internal script: dz 20201231 customSensor: Custom event: "testTrigger"
2021-01-01 18:30:39.903 Status: dzVents: Info: testCustomEvent: dzVents version: 3.1.0
2021-01-01 18:30:39.904 Status: dzVents: Info: testCustomEvent: domoticz version: 2020.2 (build 12803)
2021-01-01 18:30:39.904 Status: dzVents: Info: testCustomEvent: isJSON: true ; ==>> {["field2"]="This is field 2", ["field1"]="This is field 1"}
2021-01-01 18:30:39.904 Status: dzVents: Info: testCustomEvent: data ==>> {"field1":"This is field 1","field2":"This is field 2"}
2021-01-01 18:30:39.904 Status: dzVents: Info: testCustomEvent: data.field1 =>> nil
2021-01-01 18:30:39.906 Status: dzVents: Info: testCustomEvent: ------ Finished dz 20201231 customSensor
test from commandLine
curl -d '{"field1":"This is field 1","field2":"This is field 2"}' 'nuc:8084/json.htm?type=command¶m=customevent&event=testTrigger'
2021-01-01 18:32:59.834 Status: dzVents: Info: testCustomEvent: ------ Start internal script: dz 20201231 customSensor: Custom event: "testTrigger"
2021-01-01 18:32:59.836 Status: dzVents: Info: testCustomEvent: dzVents version: 3.1.0
2021-01-01 18:32:59.836 Status: dzVents: Info: testCustomEvent: domoticz version: 2020.2 (build 12803)
2021-01-01 18:32:59.836 Status: dzVents: Info: testCustomEvent: isJSON: true ; ==>> {["field1"]="This is field 1", ["field2"]="This is field 2"}
2021-01-01 18:32:59.836 Status: dzVents: Info: testCustomEvent: data ==>> {"field1":"This is field 1","field2":"This is field 2"}
2021-01-01 18:32:59.836 Status: dzVents: Info: testCustomEvent: data.field1 =>> nil
2021-01-01 18:32:59.838 Status: dzVents: Info: testCustomEvent: ------ Finished dz 20201231 customSensor
]]--
return
{
on =
{
customEvents =
{
'testTrigger',
},
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = ' testCustomEvent',
},
execute = function(dz, item)
dz.log('dzVents version: ' .. dz.settings.dzVentsVersion)
dz.log('domoticz version: ' .. dz.settings.domoticzVersion)
if (item.isJSON) then
dz.log('isJSON: true ; ==>> '.. dz.utils.toStr(item.json) )
end
dz.log('data ==>> ' .. dz.utils.toStr(item.data) )
dz.log('data.field1 =>> ' .. dz.utils.toStr(item.data.field1) )
end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>>
dzVents wiki