Merge pull request #441 from alanbjohnston/master-bs

Add hotspot.ini config file
master-ba
Alan Johnston 2 months ago committed by GitHub
commit 8f370fcec0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,11 @@
[Hotspot]
# WiFi hotspot name
hotspot_ssid=CubeSat
# WiFi hotspot password - note: this password is stored in the clear!
hotspot_password=amsatcubesat
# Web Dashboard port number. If 80, no port needs to be entered in browser
# dashboard_port=80
# Web terminal setting during hotspot - note, there is no authentication for this!
web_term_hotspot=yes
# Web terminal setting during WiFi - note: there is no authentication for this!
web_term_wifi=no

@ -265,12 +265,13 @@ if [[ $(grep 'bookworm' /etc/os-release) ]]; then
sudo sed -i 's/managed=false/managed=true/g' /etc/NetworkManager/NetworkManager.conf # allow nmcli to manage WiFi
if [ ! -d "/var/log/journal" ]; then # persistant journal logs across boots
sudo mkdir -p /var/log/journal
# if [ ! -d "/var/log/journal" ]; then # persistant journal logs across boots
echo "Setting up journal logs across boots"
sudo mkdir -p /var/log/journal &>/dev/null
sudo systemd-tmpfiles --create --prefix /var/log/journal
sudo systemctl restart systemd-journal-flush.service
sudo sed -i 's/Storage=volatile/Storage=persistent/g' /etc/systemd/journald.conf
fi
# fi
elif [[ $(grep 'trixie' /etc/os-release) ]]; then

@ -7,6 +7,38 @@ import subprocess
import time
import os
from time import sleep
import configparser
def read_config_ini():
global hotspot_ssid
global hotspot_password
global web_term_hotspot
global web_term_wifi
# global dashboard_port
try:
# Initialize the parser
config = configparser.ConfigParser()
# Read the file
config.read('/home/pi/CubeSatSim/hotspot.ini')
# Access the values like a dictionary
hotspot_ssid = config['Hotspot']['hotspot_ssid']
hotspot_password = config['Hotspot']['hotspot_password']
web_term_hotspot = config['Hotspot']['web_term_hotspot']
web_term_wifi = config['Hotspot']['web_term_wifi']
# dashboard_port = config.getint('Hotspot', 'dashboard_port')
print(f"SSID: {hotspot_ssid} Password: {hotspot_password} Term Hotspot: {web_term_hotspot} Term WiFi {web_term_wifi}") # : {dashboard_}")
except Exception as e:
print(f"An error occurred: {e}")
print(" failed, setting defaults")
hotspot_ssid = "CubeSat"
hotspot_password = "amsat"
web_term_hotspot = "yes"
web_term_wifi = "no"
# dashboard_port = 80
def blink(times):
blink_time = 0.1
@ -126,6 +158,7 @@ GPIO.output(powerPin, 0)
GPIO.setup(push_button, GPIO.IN, pull_up_down=GPIO.PUD_UP)
read_config_ini()
if not GPIO.input(push_button): # if pushbutton is held down during boot
print("Activating WiFi access point!", flush=True)
GPIO.output(powerPin, 1)
@ -141,17 +174,22 @@ if not GPIO.input(push_button): # if pushbutton is held down during boot
GPIO.output(powerPin, 0)
success = 1
count = 0
while (success != 0) and (count < 5):
result = subprocess.run(['nmcli', 'device', 'wifi', 'hotspot', 'con-name', 'Hotspot', 'ifname', 'wlan0', 'ssid', 'CubeSat', 'password', 'amsatao7'], capture_output=True, text=True)
while (success != 0) and (count < 5):
result = subprocess.run(['nmcli', 'device', 'wifi', 'hotspot', 'con-name', 'Hotspot', 'ifname', 'wlan0', 'ssid', hotspot_ssid, 'password', hotspot_password], capture_output=True, text=True)
print(result, flush=True) #.stdout)
count = count + 1
success = result.returncode
sleep(1)
print(f"Starting Wi-Fi Hotspot with SSID: {hotspot_ssid} and password: {hotspot_password}")
result = subprocess.run(['nmcli', 'connection', 'show'], capture_output=True, text=True)
print(result, flush=True)
sleep(2)
if web_term_hotspot == "yes":
subprocess.Popen(['sudo', '-u', 'pi', 'ttyd', '-p', '8081', 'bash'])
print("Starting web terminal on port 8081")
elif web_term_wifi == "yes":
subprocess.Popen(['sudo', '-u', 'pi', 'ttyd', '-p', '8081', 'bash'])
print("Starting web terminal on port 8081")
GPIO.setup(powerPin, GPIO.OUT)
GPIO.output(powerPin, 1)
while (True):

Loading…
Cancel
Save

Powered by TurnKey Linux.