Passing multiple commands delayed to same process / PID

#1

Hi,

I have a n AVR which I only can command (including answers) using a telnet connection. The connection has to be reset after every command.
After reding for hours about telnet and NodeRed with no conclusion, I decided to install the telnet client at my RPi3. Idea is to use an exec node to do the stuff. Exec node connects fine using the bash (telnet ip port), also manual kill is fine.

Problem is to send a second command after establishing the connection.

I have tried sending all data as payload, first the connection, as soon as it is established, my telnet command also as payload. Problem then is, the node changes to RC-2 and turns red, command is not sended.

Is there any way using the same PID and add commands?

0 Likes

#2

I would either use exec (in spawn mode) to call a complete bash script that did it all eg see https://stackoverflow.com/questions/7013137/automating-telnet-session-using-bash-scripts

Or try the node red node daemon which uses the inputort to accept msgs so you could send them suitably spaced.

0 Likes

#3

Yeah, that´s what I hoped to be able to avoid :smiley:

If someone else has the same problem, I played around alot, and finally my solution is using the telnetlib in python, and a pythonshell node to trigger the script and get the information back.

Code of the python script with my telnet´s server IP address, port 23 and 1 sec timeout is

import telnetlib

import sys

try:

	tn = telnetlib.Telnet("192.168.178.180", 23, 1)

	tn.write(sys.argv[1].encode() + "\r\n")

	tn.close()
	
	#print ("successful")


except:
	print ("Unable to connect to Telnet server")

This way I can call the script with the input of the node as the sended telnet command.
Here, a new connection is established every time I send a command, otherwise my AVR would not accept them.
print (tn.read_some()) can be used to print out the response. If you need the f.e. third response , add two tn.read_some() before it, every reads a line. Careful, it is a blocking process.
the prints are the output of the node then, I have uncommented it on try block to speed up the node ~150ms.

Which leads me to my final question: what is the best way to get the information the node is ready again? Node itself does not have such a functionality, status node always reads "unknown". As it always generates an output ("" or "thePrintedText"), I thought I could use this as a signal. Problem is, I need it to be handled very fast, so setting an value every time I get an output and read it on the entrance within a loop would be a way, but I assume not the best (fastest^^).
Maybe someone knows an "and-node" with a timeout option and two inputs or something, which could directly react on the output?

0 Likes