This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
guides:virtual_modem:script [2022-12-20 06:23] omolini |
guides:virtual_modem:script [2022-12-20 07:15] omolini |
||
---|---|---|---|
Line 130: | Line 130: | ||
# SEND MESSAGE ON SCREEN AND OVER SERIAL | # SEND MESSAGE ON SCREEN AND OVER SERIAL | ||
sendtty () { | sendtty () { | ||
+ | # Prints message in console and over serial. Message is given as first parameter. | ||
message="$1" | message="$1" | ||
echo -en "$message" | tee /dev/$serport | echo -en "$message" | tee /dev/$serport | ||
+ | } | ||
+ | |||
+ | readtty () { | ||
+ | # Reads input from TTY and stores it in variable given as first parameter | ||
+ | line= | ||
+ | while [[ -z "$line" ]]; do | ||
+ | charhex=`head -c 1 /dev/$serport | xxd -p -` | ||
+ | char="`echo -e "\x$charhex"`" | ||
+ | echo -n "$char" | ||
+ | echo -n "$char" > /dev/$serport | ||
+ | # Newline received | ||
+ | if [ "$charhex" = "0d" -o "$charhex" = "0a" ]; then | ||
+ | line=$buffer | ||
+ | buffer= | ||
+ | char= | ||
+ | sendtty "\n" | ||
+ | fi | ||
+ | buffer=$buffer$char | ||
+ | done | ||
+ | local __resultvar=$1 | ||
+ | local result="$line" | ||
+ | eval $__resultvar="'$result'" | ||
} | } | ||
export -f sendtty | export -f sendtty | ||
+ | export -f readtty | ||
export -f ttyinit | export -f ttyinit | ||
Line 452: | Line 476: | ||
while true; do | while true; do | ||
# Display menu | # Display menu | ||
+ | sendtty "\n" | ||
sendtty "System Setup\n" | sendtty "System Setup\n" | ||
sendtty "============\n" | sendtty "============\n" | ||
Line 458: | Line 483: | ||
sendtty "Enter your selection: " | sendtty "Enter your selection: " | ||
# Read user input | # Read user input | ||
- | read -p selection | + | readtty selection |
# Wireless network settings | # Wireless network settings | ||
if [[ "$selection" == "1" ]]; then | if [[ "$selection" == "1" ]]; then | ||
while true; do | while true; do | ||
+ | sendtty "\n" | ||
sendtty "Wi-Fi Settings\n" | sendtty "Wi-Fi Settings\n" | ||
sendtty "==============\n" | sendtty "==============\n" | ||
Line 471: | Line 498: | ||
sendtty "Enter your selection: " | sendtty "Enter your selection: " | ||
# Read user input | # Read user input | ||
- | read -p selection | + | readtty selection |
# Connect to new Wi-Fi network | # Connect to new Wi-Fi network | ||
if [[ "$selection" == "1" ]]; then | if [[ "$selection" == "1" ]]; then | ||
sendtty "Enter SSID: " | sendtty "Enter SSID: " | ||
- | read -p ssid | + | readtty ssid |
sendtty "Enter password: " | sendtty "Enter password: " | ||
- | read -p password | + | readtty password |
#sudo wpa_cli -i wlan0 remove_network 0 | #sudo wpa_cli -i wlan0 remove_network 0 | ||
#sudo wpa_cli -i wlan0 add_network | #sudo wpa_cli -i wlan0 add_network | ||
Line 487: | Line 514: | ||
elif [[ "$selection" == "2" ]]; then | elif [[ "$selection" == "2" ]]; then | ||
sendtty "Enter new password: " | sendtty "Enter new password: " | ||
- | read -p password | + | readtty password |
#sudo wpa_cli -i wlan0 set_network 0 psk "\"$password\"" | #sudo wpa_cli -i wlan0 set_network 0 psk "\"$password\"" | ||
# Disconnect from current Wi-Fi network | # Disconnect from current Wi-Fi network | ||
Line 496: | Line 523: | ||
elif [[ "$selection" == "4" ]]; then | elif [[ "$selection" == "4" ]]; then | ||
status=$(sudo wpa_cli -i wlan0 status) | status=$(sudo wpa_cli -i wlan0 status) | ||
+ | sendtty "\n" | ||
+ | sendtty "Wi-fi connection status\n" | ||
+ | sendtty "=======================\n" | ||
sendtty "$status" | sendtty "$status" | ||
+ | sendtty "\n" | ||
# Exit | # Exit | ||
elif [[ "$selection" == "5" ]]; then | elif [[ "$selection" == "5" ]]; then | ||
Line 507: | Line 538: | ||
# Exit | # Exit | ||
elif [[ "$selection" == "2" ]]; then | elif [[ "$selection" == "2" ]]; then | ||
+ | sendtty "Exited setup\n" | ||
+ | sendtty "READY.\n" | ||
break | break | ||
# Invalid selection | # Invalid selection | ||
else | else | ||
- | echo "Invalid selection. Please try again." | + | sendtty "Invalid selection. Please try again.\n" |
fi | fi | ||
done | done | ||
Line 634: | Line 667: | ||
sendtty "\n" | sendtty "\n" | ||
sendtty "Please enter your name: \n" | sendtty "Please enter your name: \n" | ||
- | read -e -p "User? " username | + | readtty username |
sendtty "\n" | sendtty "\n" | ||
sendtty "Hello, $username!\n" | sendtty "Hello, $username!\n" |