This commit is contained in:
Your Name
2025-03-28 15:59:54 +01:00
parent c6b138220e
commit 4653fe44e3
8 changed files with 247 additions and 44 deletions

View File

@@ -6,7 +6,6 @@
# @reboot /var/www/moduleair_pro_4g/boot_hotspot.sh >> /var/www/moduleair_pro_4g/logs/app.log 2>&1
OUTPUT_FILE="/var/www/moduleair_pro_4g/wifi_list.csv"
JSON_FILE="/var/www/moduleair_pro_4g/config.json"
echo "-------------------"
echo "-------------------"
@@ -14,16 +13,18 @@ echo "-------------------"
echo "NebuleAir pro started at $(date)"
echo "getting SARA R4 serial number"
echo "getting RPI serial number"
# Get the last 8 characters of the serial number and write to text file
serial_number=$(cat /proc/cpuinfo | grep Serial | awk '{print substr($3, length($3) - 7)}')
# Define the JSON file path
# Use jq to update the "deviceID" in the JSON file
jq --arg serial_number "$serial_number" '.deviceID = $serial_number' "$JSON_FILE" > temp.json && mv temp.json "$JSON_FILE"
# update Sqlite database
echo "Updating SQLite database with device ID: $serial_number"
sqlite3 /var/www/moduleair_pro_4g/sqlite/sensors.db "UPDATE config_table SET value='$serial_number' WHERE key='deviceID';"
echo "id: $serial_number"
#get the SSH port for tunneling
SSH_TUNNEL_PORT=$(jq -r '.sshTunnel_port' "$JSON_FILE")
SSH_TUNNEL_PORT=$(sqlite3 /var/www/moduleair_pro_4g/sqlite/sensors.db "SELECT value FROM config_table WHERE key='sshTunnel_port'")
#need to wait for the network manager to be ready
sleep 20
@@ -39,10 +40,10 @@ if [ "$STATE" == "30 (disconnected)" ]; then
nmcli -f SSID,SIGNAL,SECURITY device wifi list | awk 'BEGIN { OFS=","; print "SSID,SIGNAL,SECURITY" } NR>1 { print $1,$2,$3 }' > "$OUTPUT_FILE"
# Start the hotspot
echo "Starting hotspot..."
sudo nmcli device wifi hotspot ifname wlan0 ssid nebuleair_pro password nebuleaircfg
sudo nmcli device wifi hotspot ifname wlan0 ssid moduleair_pro password moduleaircfg
# Update JSON to reflect hotspot mode
jq --arg status "hotspot" '.WIFI_status = $status' "$JSON_FILE" > temp.json && mv temp.json "$JSON_FILE"
sqlite3 /var/www/moduleair_pro_4g/sqlite/sensors.db "UPDATE config_table SET value='hotspot' WHERE key='WIFI_status'"
else
@@ -50,10 +51,8 @@ else
CONN_SSID=$(nmcli -g GENERAL.CONNECTION device show wlan0)
echo "Connection: $CONN_SSID"
#update config JSON file
jq --arg status "connected" '.WIFI_status = $status' "$JSON_FILE" > temp.json && mv temp.json "$JSON_FILE"
sudo chmod 777 "$JSON_FILE"
# Update SQLite to reflect hotspot mode
sqlite3 /var/www/nebuleair_pro_4g/sqlite/sensors.db "UPDATE config_table SET value='connected' WHERE key='WIFI_status'"
# Lancer le tunnel SSH
#echo "Démarrage du tunnel SSH sur le port $SSH_TUNNEL_PORT..."