Data output from telnet/nc into Domoticz

All kinds of 'OS' scripts

Moderator: leecollings

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

Data output from telnet/nc into Domoticz

Post 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.
deve87
Posts: 45
Joined: Saturday 08 April 2017 8:21
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Data output from telnet/nc into Domoticz

Post by deve87 »

Anyone? 🙂
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Data output from telnet/nc into Domoticz

Post 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"
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
deve87
Posts: 45
Joined: Saturday 08 April 2017 8:21
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Data output from telnet/nc into Domoticz

Post 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?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Data output from telnet/nc into Domoticz

Post 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
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
deve87
Posts: 45
Joined: Saturday 08 April 2017 8:21
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Data output from telnet/nc into Domoticz

Post by deve87 »

Thank you :) Will try
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest