I try to use a bash script to watch the serial-port for a specific string. If this string is shown, some commands should be send back to the connected device. It´s a router I am connected to. It is a router I am connected to and I want to send the commands, after the uboot-menu has appeared.
When using minicom with a ftdi-USB-UART-device directly (no with the script) everything works. "It works" in that case means:
- Bootmenu is shown while a time is counting down, the device is waiting for input until I enter a number or the countdown is over.
- I am able to send a command/enter a number.
- The router "boots" into the selected option. (in my case - the system starts tftp-bootmode where I could input stuff liker server IP and so on...)
Now, when I use the script. The router does not care about inpu also the countdown is not runnig. It just boots directly into the default option. Same behavior when using minicom + /dev/ttyAMA0 on a raspberry pi (ftdi device otherwise works as described).
I am thinking that in my script, there are some parameters missing. Maybe I have to choose special options for stty?
Or do I have to send a special "control character" right at the beginning, for the router to recognize that "there is someone out there who is able to send me some commands"?
I am able to detect the string I am searching for, but as I said before - the router doesn´t recognize the command(s) send:
#!/bin/bash
tty=/dev/ttyUSB0
exec 4<$tty 5>$tty
stty -F $tty 115200 -echo
while [ "${output}" != "Please choose the operation:" ]; do #wait for bootmenu to appear
read output <&4
echo "$output"
done
printf "\t\n ***** gotcha! ***** \n\n" #bootmenu is showing
echo -e "\x31" >&5 # echo '1' for taking boot option 1
printf "\t\n ***** echo '1' ***** \n\n"
while true; do #just for debugging (was command received?)...
read output <&4
echo "$output"
done
#commands for setting Target-IP, TFTP-Server-IP-address should follow here...
Many thanks in advance :-)
echo
will send a linefeed after the '1', but it's likely that the router is looking for a carriage return, or perhaps looking for both CR and LF. Tryecho -e '1\x0d'
(there's no need to write\x31
to represent the character1
) to introduce a CR before the automatic LF. If that works but following commands are messed up, tryecho -n -e '1\x0d'
to suppress the LF thatecho
sends by default.