Page 1 of 1

Data output from telnet/nc into Domoticz

Posted: Sunday 13 January 2019 13:54
by deve87
Hi.
I have a Rotel receiver with an RS232 port. Connected that to a RS232 -> TCP device.

If I type telnet 192.168.10.134 10232 | strings in terminal.
I get data from my Rotel receiver every time I do some changes.
It prints

Code: Select all

pi@Domoticz:~ $ nc 192.168.10.134 10232 | strings

 TV            VOL  55
 TV            VOL  55PCM 2CH
 TV            VOL  55STEREO
 TV            VOL  55PCM 2CH
 TV            VOL  55PCM 2CH         48K
How do I (the easy way) get that into a text device into Domoticz?
I already tried

Code: Select all

#!bin/bash
THE_AMP_TEXT=`nc 192.168.10.134 10232 | strings`

wget "http://127.0.0.1:8081/json.htm?type=command&param=udevice&idx=1330&nvalue=0&svalue=${THE_AMP_TEXT}"

And nothing happens.

Code: Select all

telnet 192.168.10.134 10232 | strings > /home/pi/output
Logs into the "output" file OK

And

Code: Select all

wget "http://127.0.0.1:8081/json.htm?type=command&param=udevice&idx=1330&nvalue=0&svalue=TEST TEXT"
Updates the correct text device with TEST TEXT.

Re: Data output from telnet/nc into Domoticz

Posted: Monday 22 April 2019 22:23
by deve87
Anyone? 🙂

Re: Data output from telnet/nc into Domoticz

Posted: Monday 22 April 2019 23:08
by waaren
deve87 wrote: ↑Monday 22 April 2019 22:23Anyone? 🙂
The attached works on my system.
note the / before bin/bash
-w 5 ==>> wait max 5 seconds
var=$(commands) ==>> get outpu of commands in var
$THE_AMP_TEXT ==>> content of the var

Code: Select all

#!/bin/bash
THE_AMP_TEXT=$(nc -w 5 192.168.10.134 10232 | strings)

wget "http://127.0.0.1:8081/json.htm?type=command&param=udevice&idx=1330&nvalue=0&svalue=$THE_AMP_TEXT"

Re: Data output from telnet/nc into Domoticz

Posted: Tuesday 23 April 2019 9:15
by deve87
Thanks :D It works.

If I do multiple changes from amp, I get many lines in one json.
How can I make it send one line at a time?

Possible to make it stay connected and send when amp sends without it disconnected every 5 sec?

Re: Data output from telnet/nc into Domoticz

Posted: Tuesday 23 April 2019 10:12
by waaren
deve87 wrote: ↑Tuesday 23 April 2019 9:15 Thanks :D It works.

If I do multiple changes from amp, I get many lines in one json.
How can I make it send one line at a time?
could be something like

Code: Select all

#!/bin/bash
THE_AMP_TEXT=$(nc -w 5 192.168.10.134 10232 | strings)

while IFS= read -r line; do
   wget "http://127.0.0.1:8081/json.htm?type=command&param=udevice&idx=1330&nvalue=0&svalue=$line"
done < <(echo $THE_AMP_TEXT)
Possible to make it stay connected and send when amp sends without it disconnected every 5 sec?
Maybe if you find a way to send the output of a permanent nc connection to a file and let another bash script wait for new lines in this file.
Look here for some nc examples

Re: Data output from telnet/nc into Domoticz

Posted: Tuesday 23 April 2019 20:46
by deve87
Thank you :) Will try