diff --git a/deploy.sh b/deploy.sh index d0e1f8c..b7b5362 100755 --- a/deploy.sh +++ b/deploy.sh @@ -1,9 +1,6 @@ check_exists() { command -v "$1" > /dev/null } -check_port() { - cargo espflash board-info --port "$1" &> /dev/null -} if ! check_exists esptool.py then echo "esptool.py not installed!" @@ -28,21 +25,6 @@ then echo "install with this command: cargo install espflash" exit 1 fi -if [ -z "$SSID" ] -then - echo "Please set environment variable SSID to the SSID of the wifi you'll use to configure your sphinx-key." - exit 1 -fi -if [ -z "$PASS" ] -then - echo "Please set environment variable PASS to the password of the wifi you'll use to configure your sphinx-key." - exit 1 -fi -if [ ${#PASS} -lt 8 ] -then - echo "Please set PASS to a password longer than 7 characters." - exit 1 -fi cargo espflash erase-flash git pull && cd factory && diff --git a/sphinx-key/sphinx_key.sh b/sphinx-key/sphinx_key.sh index 6b9110d..595fbc5 100755 --- a/sphinx-key/sphinx_key.sh +++ b/sphinx-key/sphinx_key.sh @@ -1,9 +1,6 @@ check_exists() { command -v "$1" > /dev/null } -check_port() { - cargo espflash board-info --port "$1" &> /dev/null -} if ! check_exists esptool.py then echo "esptool.py not installed!" @@ -28,21 +25,6 @@ then echo "install with this command: cargo install espflash" exit 1 fi -if [ -z "$SSID" ] -then - echo "Please set environment variable SSID to the SSID of the wifi you'll use to configure your sphinx-key." - exit 1 -fi -if [ -z "$PASS" ] -then - echo "Please set environment variable PASS to the password of the wifi you'll use to configure your sphinx-key." - exit 1 -fi -if [ ${#PASS} -lt 8 ] -then - echo "Please set PASS to a password longer than 7 characters." - exit 1 -fi cargo espflash save-image --bin sphinx-key --release --chip esp32c3 sphinx-key.bin && espsecure.py sign_data sphinx-key.bin --version 2 --keyfile ../secure_boot_signing_key.pem && espflash write-bin 0x50000 sphinx-key.bin && diff --git a/sphinx-key/src/conn/wifi.rs b/sphinx-key/src/conn/wifi.rs index cc6da69..e6bc5a8 100644 --- a/sphinx-key/src/conn/wifi.rs +++ b/sphinx-key/src/conn/wifi.rs @@ -9,6 +9,10 @@ use esp_idf_svc::wifi::{ }; use log::*; use sphinx_signer::sphinx_glyph::control::Config; +use std::fs; + +const SSID_FILE: &str = "/sdcard/ssid.txt"; +const PASS_FILE: &str = "/sdcard/password.txt"; pub fn start_client( modem: impl peripheral::Peripheral
+ 'static, @@ -89,15 +93,30 @@ pub fn start_access_point( sysloop, )?; - let ssid: &'static str = env!("SSID"); - let password: &'static str = env!("PASS"); + let ssid = match fs::read_to_string(SSID_FILE) { + Ok(ssid) => ssid.trim().to_string(), + Err(_) => { + warn!("Could not read ssid from sd card, using default setting"); + "sphinx".to_string() + } + }; + let password = match fs::read_to_string(PASS_FILE) { + Ok(password) => password.trim().to_string(), + Err(_) => { + warn!("Could not read password from sd card, using default setting"); + "sphinxkey".to_string() + } + }; if password.len() < 8 { - return Err(anyhow::anyhow!("Password error!\nCurrent password: {}\nYour wifi password must be >= 8 characters. Compile this software again with a longer password.", password)); + return Err(anyhow::anyhow!( + "Password error!\nCurrent password: {}\nYour wifi password must be >= 8 characters", + password + )); } wifi.set_configuration(&Configuration::AccessPoint(AccessPointConfiguration { - ssid: ssid.into(), - password: password.into(), + ssid: ssid.as_str().into(), + password: password.as_str().into(), channel: 6, auth_method: AuthMethod::WPA2Personal, ..Default::default()