Page 1 of 1

Domoticz crashes on complex data in customEvent

Posted: Saturday 21 March 2020 11:12
by sabcio
Hi,

trying out customEvents but my domoticz service crashes each time I try to send some more data

Code: Select all

2020-03-21 10:58:19.235 MQTT: Topic: domoticz/in, Message: {"command":"customevent","event":"notResponsive","data":[{"idx":29,"test":"ok"}]}
2020-03-21 10:58:19.244 Error: Domoticz(pid:32647, tid:32690('EventSystemQueu')) received fatal signal 6 (Aborted)
2020-03-21 10:58:19.244 Error: siginfo address=0x7f87, address=0xffffffff
I've tried different payloads, every time a valid json. The only thing that works is when data is a plain integer, string value:

Code: Select all

Message: {"command":"customevent","event":"notResponsive","data":29}
Does not work:

Code: Select all

Message: {"command":"customevent","event":"notResponsive","data":[{"idx":29,"test":"ok"}]}
Message: {"command":"customevent","event":"notResponsive","data":{"idx":29,"test":"ok"}}
The script doesn't do anything yet, it just logs data output:

Code: Select all

return {
	on = {
        customEvents =
        {
            'notResponsive',
        }
	},

	logging = {
        level = domoticz.LOG_DEBUG,
        marker = "BatteryStatus"
    },

	execute = function(dz, item, info)
		dz.log(item.data)
		dz.log(item.isCustomEvent)
	end
}

EDIT1: I thought I should parse json but it still failed and then I tried empty execute function which also crashes.

Re: Domoticz crashes on complex data in customEvent

Posted: Saturday 21 March 2020 13:46
by MrHobbes74
Can you try to put the data json in a string? I think that is the problem. I’m not 100% sure, but I think you can’t provide a json object, you can only provide a string, that can contain a json object.

{"command":"customevent","event":"notResponsive","data":”[{"idx":29,"test":"ok"}]”}

Re: Domoticz crashes on complex data in customEvent

Posted: Saturday 21 March 2020 19:39
by sabcio
Ok, that does work, thanks MrHobbes74. Does not make sense to me but I'm no lua expert. Here's a working example

Message payload:

Code: Select all

{"command":"customevent","event":"notResponsive","data":"{\"idx\":29,\"test\":\"ok\"}"}'
Function:

Code: Select all

	execute = function(dz, item)
	    dz.log(item.data["idx"])
	    dz.log(item.data["test"])
	end

Re: Domoticz crashes on complex data in customEvent  [Solved]

Posted: Saturday 21 March 2020 19:59
by MrHobbes74
It has nothing to do with Lua. The reason is that the parameter ‘data’ can only contain a string. In that string, you can also put a flat raw json string. As long as it is a string 😉. In dzVents, if the string contains a json object, it allows access to the object. In other cases (no json object) you get the whole string.