Last active
June 18, 2024 09:22
-
-
Save andypiper/127346173c67bb08219cdae3a3bfc995 to your computer and use it in GitHub Desktop.
Update TIldagon wifi network settings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Script to set the WiFi SSID and password on the Tildagon | |
# Author: Andy Piper | |
#echo "This script sets the WiFi SSID and password on the Tildagon." | |
#echo "Usage: $0 [port] [ssid] [password]" | |
#echo " port : The USB port for the Tildagon (e.g., /dev/ttyUSB0)" | |
#echo " ssid : The WiFi SSID" | |
#echo " password : The WiFi password" | |
#echo "" | |
# Check if the correct number of arguments is provided | |
if [ $# -ne 3 ]; then | |
echo "Error: Incorrect number of arguments." | |
echo "Usage: $0 [port] [ssid] [password]" | |
exit 1 | |
fi | |
port=$1 | |
ssid=$2 | |
password=$3 | |
# Check if the SSID is empty | |
if [ -z "$ssid" ]; then | |
echo "Error: SSID cannot be empty." | |
exit 1 | |
fi | |
# Update WiFi settings on the board | |
output=$(mpremote connect $port exec " | |
import settings | |
try: | |
settings.set('wifi_ssid', '$ssid') | |
settings.set('wifi_password', '$password') | |
settings.save() | |
print('WiFi settings updated successfully.') | |
except Exception as e: | |
print('Error updating WiFi settings:', str(e)) | |
") | |
echo "$output" | |
# Check if the WiFi settings were updated successfully | |
if echo "$output" | grep -q "Error updating WiFi settings"; then | |
echo "Failed to update WiFi settings on the Tildagon." | |
exit 1 | |
else | |
echo "WiFi settings updated successfully on the Tildagon." | |
# Reset the badge | |
mpremote connect $port reset | |
exit 0 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment