Read / Write HEX (RS232 TCP-server)

Moderator: leecollings

Post Reply
deve87
Posts: 45
Joined: Saturday 08 April 2017 8:21
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Read / Write HEX (RS232 TCP-server)

Post by deve87 »

Hi.

I have connected my Rotel-RSP 1068 receiver (RS232 port) to a shareable TCP-server. If I use a normal TCP client program on a Windows PC. I can read status change and write HEX command to client and then turn on / off, change volume.

Example: Turn On receiver HEX - FE 03 A1 10 4B FF

How can I do this in a script and then update received data to a text file.

I use a Raspberry PI (Stretch) for Domoticz

I found this code which connects to the TCP server

Code: Select all

  local host, port = "192.168.10.134", 10232
local socket = require("socket")
local tcp = assert(socket.tcp())

tcp:connect(host, port);

while true do
    local s, status, partial = tcp:receive()
    print(s or partial)
    if status == "closed" then break end
end
tcp:close()
If I do any chance on my receiver, it shows up in the log.
But I get a Error that the script has been running for more than 10sec
And it continues to connect to server as multiple client. So if I don't set allow client to 1 on the server, it will continue to connect as multiple client's 🤔

So I need a "If connected then stop connecting" and a way to send HEX command from dummy switches 🙂
Last edited by deve87 on Monday 07 January 2019 12:00, edited 2 times in total.
deve87
Posts: 45
Joined: Saturday 08 April 2017 8:21
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Read / Write HEX (RS232 TCP-server)

Post by deve87 »

Okay so I managed to send ON/OFF command

Code: Select all

IP = '192.168.10.134'
Port = '10232';
local hex = {
              "FE","03","A1","10", "4B", "FF"
            }
local binary = "";
for i, v in ipairs(hex) do
  binary = binary .. string.char(tonumber(v, 16))
end

function send(msg) 
   runcommand = "echo "..msg .."| nc "..IP.." "..Port.." "
   print (runcommand)
   os.execute(runcommand)
end
commandArray = {}
if(devicechanged['Rotel']=='On') then
     print(binary)
     send(binary)
end
end
return commandArray
I have to convert HEX into binary for it to work.
Now I have one script for ON and one for Off. Any way I can have one script for all the HEX code I want to convert? It's one HEX for Off, On, Volume Up, Volume down and changing source.

Help please 🙂
deve87
Posts: 45
Joined: Saturday 08 April 2017 8:21
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Read / Write HEX (RS232 TCP-server)

Post by deve87 »

This is how I conrol the amp.

Create bash script for every command

Code: Select all

#!/bin/bash
echo -n -e "\xFE\x03\xA1\x10\x08\xBC" | nc 192.168.10.110 20108 &
and execute it in "run script" line in switch option.

But!
I'm struggling to get a stable respons from amp. I tried io.popen and lua socket. But it seem both of them loops over and over, and eventually, Domoticz stops working. I do get a respons and manage to update a text device. Not a stable one.

No one can help to get data from telnet / netcat in to Domoticz? :(
User avatar
Dnpwwo
Posts: 820
Joined: Sunday 23 March 2014 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Re: Read / Write HEX (RS232 TCP-server)

Post by Dnpwwo »

@deve87,

Stitching Lua and bash scripts together will always give you a laggy hard to debug solution. Why don't you make a Python plugin for your hardware?

There are an examples shipped with Domoticz to connect to a device over: and documentation on the wiki (https://www.domoticz.com/wiki/Developin ... hon_plugin).

If you turn on debugging in the plugin Domoticz will hex dump all messages to and from the device for you, also you can debug the plugin while its running in Domoticz (https://www.domoticz.com/wiki/Developin ... #Debugging).
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw
sasitamil
Posts: 1
Joined: Monday 18 March 2019 8:52
Target OS: Windows
Domoticz version:
Contact:

Re: Read / Write HEX (RS232 TCP-server)

Post by sasitamil »

Very well written blog and I always love to read blogs like these because they offer very good information to readers with very less amount of words....thanks for sharing your info with us and keep sharing.
https://www.gangboard.com/big-data-trai ... -training
https://www.gangboard.com/cloud-computi ... s-training
deve87
Posts: 45
Joined: Saturday 08 April 2017 8:21
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Read / Write HEX (RS232 TCP-server)

Post by deve87 »

Thanks for replying.

I don't have enough skills to make a python plugin :|

I was hoping someone knew a simple way to get this telnet session in Domoticz (text device)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest