Page 1 of 1

Need Domoticz.Send and onMessage to handle byte arrays

Posted: Wednesday 01 March 2017 20:36
by jorgh
Hi All,

I've started developing a plugin for the Onkyo receiver.
I'm basing my plugin on the Python script I've already developed and posted in this forum.
However, I'm hitting a bump.
The Onkyo receiver does not communicate using plain text, but eISCP frames.
These frames can contain for example bytes holding the value 0. As such, sending and receiving as strings is not an option.
The onMessage function, actually returns a byte array instead of a string, but the data stops as the first hit of a zero byte.
The send function, only seems to accepts strings, and hence, I've got the same issue here.

Is there another option to send and receive using the build in Domoticz functions? Otherwise I would need to implement using raw sockets, which is not a problem, but I will lose the event system which I think is very nice.

Might it be an option for a feature request, to accept byte arrays in the Domoticz.Send function?
The onMessage alreade returns the data in byte array format, but truncates this. I don't think it would be an issue for anyone using devices that communicate in strings, to return all received data as a byte array. At least, that will allow me to use the onMessage event.

Kind regards,

Jorg

Re: Need Domoticz.Send and onMessage to handle byte arrays

Posted: Thursday 02 March 2017 5:33
by Dnpwwo
@jorgh,

The intention is to allow both onMessage and Send to work properly with bytes arrays.

I've been limited by the devices that I have on what I can test but if you have a device that needs it I'm happy to uplift it now, backwards compatibility will not be a problem.

If you build Domoticz from source you could switch to the Python-Plugins branch and I could push changes quickly otherwise updates will take a little longer to test.

The changes are quite small, I should be able to have something available in the next day or so.

Re: Need Domoticz.Send and onMessage to handle byte arrays

Posted: Thursday 02 March 2017 7:52
by jorgh
@Dnpwwo,

Well, that's great news to wake up to ;-)
It should not be an issue for me to compile from source. I'm running on a spare pi (yes a slow one) so building will take quite some time. But I'm happy to try.
One silly question, what do I have to change on the git command to pull the Python-Plugins branch? I guess this is the only difference with the procedure documented on the wiki to build from source.

Regards,

Jorg

Re: Need Domoticz.Send and onMessage to handle byte arrays

Posted: Friday 03 March 2017 19:54
by jorgh
Ok,

I'm currently compiling the Python-Plugins branch. So I should be up and running quickly after the code update. Any idea when I could expect the code to be updated?

Kind regards,

Jorg

Re: Need Domoticz.Send and onMessage to handle byte arrays

Posted: Saturday 04 March 2017 7:42
by Dnpwwo
@jorgh,

Shouldn't be too long, already got sending working (with minimal testing)

Edit: Committed to branch with sending. If you turn on debugging you now get something like this:

Code: Select all

2017-03-04 18:16:58.609 (Test Kodi) Transport set to: 'TCP/IP', 192.168.0.247:9090.
2017-03-04 18:16:58.609 (Test Kodi) Protocol set to: 'JSON'.
2017-03-04 18:16:58.609 (Test Kodi) Heartbeat interval set to: 10.
2017-03-04 18:16:58.610 PluginSystem: Starting I/O service thread.
2017-03-04 18:16:58.610 (Test Kodi) Connect directive received, transport connect initiated successfully.
2017-03-04 18:16:58.661 (Test Kodi) Calling message handler 'onConnect'.
2017-03-04 18:16:58.661 (Test Kodi) Connected successfully to: 192.168.0.247:9090
2017-03-04 18:16:58.661 (Test Kodi) Sending 127 bytes of data:.
2017-03-04 18:16:58.661 (Test Kodi) 7b 22 6a 73 6f 6e 72 70 63 22 3a 22 32 2e 30 22 2c 22 6d 65 {"jsonrpc":"2.0","me
2017-03-04 18:16:58.662 (Test Kodi) 74 68 6f 64 22 3a 22 53 79 73 74 65 6d 2e 47 65 74 50 72 6f thod":"System.GetPro
2017-03-04 18:16:58.662 (Test Kodi) 70 65 72 74 69 65 73 22 2c 22 70 61 72 61 6d 73 22 3a 7b 22 perties","params":{"
2017-03-04 18:16:58.663 (Test Kodi) 70 72 6f 70 65 72 74 69 65 73 22 3a 5b 22 63 61 6e 68 69 62 properties":["canhib
2017-03-04 18:16:58.663 (Test Kodi) 65 72 6e 61 74 65 22 2c 22 63 61 6e 73 75 73 70 65 6e 64 22 ernate","cansuspend"
2017-03-04 18:16:58.663 (Test Kodi) 2c 22 63 61 6e 73 68 75 74 64 6f 77 6e 22 5d 7d 2c 22 69 64 ,"canshutdown"]},"id
2017-03-04 18:16:58.663 (Test Kodi) 22 3a 31 30 30 37 7d .. .. .. .. .. .. .. .. .. .. .. .. .. ":1007}
2017-03-04 18:16:58.664 (Test Kodi) Sending 107 bytes of data:.
2017-03-04 18:16:58.664 (Test Kodi) 7b 22 6a 73 6f 6e 72 70 63 22 3a 22 32 2e 30 22 2c 22 6d 65 {"jsonrpc":"2.0","me
2017-03-04 18:16:58.664 (Test Kodi) 74 68 6f 64 22 3a 22 41 70 70 6c 69 63 61 74 69 6f 6e 2e 47 thod":"Application.G
2017-03-04 18:16:58.664 (Test Kodi) 65 74 50 72 6f 70 65 72 74 69 65 73 22 2c 22 69 64 22 3a 31 etProperties","id":1
2017-03-04 18:16:58.664 (Test Kodi) 30 31 31 2c 22 70 61 72 61 6d 73 22 3a 7b 22 70 72 6f 70 65 011,"params":{"prope
2017-03-04 18:16:58.665 (Test Kodi) 72 74 69 65 73 22 3a 5b 22 76 6f 6c 75 6d 65 22 2c 22 6d 75 rties":["volume","mu
2017-03-04 18:16:58.665 (Test Kodi) 74 65 64 22 5d 7d 7d .. .. .. .. .. .. .. .. .. .. .. .. .. ted"]}}
2017-03-04 18:16:58.665 (Test Kodi) Sending 62 bytes of data:.
2017-03-04 18:16:58.665 (Test Kodi) 7b 22 6a 73 6f 6e 72 70 63 22 3a 22 32 2e 30 22 2c 22 6d 65 {"jsonrpc":"2.0","me
2017-03-04 18:16:58.666 (Test Kodi) 74 68 6f 64 22 3a 22 50 6c 61 79 65 72 2e 47 65 74 41 63 74 thod":"Player.GetAct
2017-03-04 18:16:58.666 (Test Kodi) 69 76 65 50 6c 61 79 65 72 73 22 2c 22 69 64 22 3a 31 30 30 ivePlayers","id":100
2017-03-04 18:16:58.666 (Test Kodi) 31 7d .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 1}
2017-03-04 18:16:58.667 (Test Kodi) Calling message handler 'onMessage'.
2017-03-04 18:16:58.667 (Test Kodi) 1007 response received: {"id":1007,"jsonrpc":"2.0","result":{"canhibernate":false,"canshutdown":true,"cansuspend":false}}
2017-03-04 18:16:58.667 (Test Kodi) Kodi shutdown options response processed.
2017-03-04 18:16:58.667 (Test Kodi) Calling message handler 'onMessage'.
2017-03-04 18:16:58.668 (Test Kodi) 1011 response received: {"id":1011,"jsonrpc":"2.0","result":{"muted":false,"volume":100}}
Edit 2: Has issues compiling on Linux so hold off updating to this.

Re: Need Domoticz.Send and onMessage to handle byte arrays

Posted: Saturday 04 March 2017 21:46
by jorgh
@Dnpwwo,

Ok, good to know there is progress. I've continued developing Python code in stand-alone scripts, so I should have something to share soon after the send and receive code is working.

Edit: I'ts working after the last commit. Thanks

Regards,

Jorg