Skip to content

Commit f1588d9

Browse files
committed
feat: bluetooth get auto setup settings
1 parent d9063c8 commit f1588d9

File tree

7 files changed

+31
-27
lines changed

7 files changed

+31
-27
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ local-ip-address = "0.6.3"
2424
mdns-sd = "0.13.1"
2525
reqwest = { version = "0.12.12", features = ["json", "rustls-tls"], default-features = false }
2626
serde = { version = "1.0.217", features = ["derive"] }
27-
serde_json = "1.0.137"
27+
serde_json = "1.0.138"
2828
tokio = { version = "1.43.0", features = ["full"] }
2929
tower-http = { version = "0.6.2", features = ["trace"] }
3030
tracing = "0.1.41"

src/bluetooth.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,13 @@ async fn setup_bt_device(device: btleplug::platform::Peripheral) -> Result<()> {
8888

8989
// get wifi settings from API or env
9090
tracing::trace!("Getting wifi settings");
91-
let (ssid, psk) = if let Ok((ssid, psk)) = crate::socket::api::get_wifi_settings().await {
92-
(ssid, psk)
91+
let auto_setup_settings = if let Ok(ass) = crate::socket::api::get_auto_setup_settings().await {
92+
ass
9393
} else {
94-
let ssid = std::env::var("WIFI_SSID")?;
95-
let psk = std::env::var("WIFI_PSK")?;
96-
(ssid, psk)
94+
std::env::var("AUTOSETUP_SETTINGS")?
9795
};
9896

99-
let set_wifi_data = format!("{ssid}|{psk}");
97+
let set_wifi_data = format!("{auto_setup_settings}\0");
10098
let set_wifi_data = set_wifi_data.as_bytes();
10199
tracing::trace!("Got wifi settings");
102100

src/main.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
use std::{os::unix::fs::PermissionsExt, path::PathBuf};
2-
31
use anyhow::Result;
2+
use std::{os::unix::fs::PermissionsExt, path::PathBuf};
43

54
mod bluetooth;
65
mod github;

src/socket/api.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,19 +170,15 @@ pub async fn add_device(esp_id: u32, firmware_type: &str) -> Result<(), UnixErro
170170
res
171171
}
172172

173-
pub async fn get_wifi_settings() -> Result<(String, String)> {
173+
pub async fn get_auto_setup_settings() -> Result<String> {
174174
let res = crate::UNIX_SOCKET
175-
.send_tagged_request(UnixRequestData::WifiSettings)
175+
.send_tagged_request(UnixRequestData::AutoSetupSettings)
176176
.await
177177
.map_err(|e| anyhow::anyhow!("Unix error: {e:?}"))?;
178178

179-
if let UnixResponseData::WifiSettingsResp {
180-
wifi_ssid,
181-
wifi_password,
182-
} = res
183-
{
184-
return Ok((wifi_ssid, wifi_password));
179+
if let UnixResponseData::AutoSetupSettingsResp(resp) = res {
180+
return Ok(serde_json::to_string(&resp)?);
185181
}
186182

187-
Err(anyhow::anyhow!("Cant get wifi settings!"))
183+
Err(anyhow::anyhow!("Cant get auto setup settings!"))
188184
}

unix-utils/src/request.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub enum UnixRequestData {
1616
PersonInfo {
1717
card_id: String,
1818
},
19-
WifiSettings,
19+
AutoSetupSettings,
2020
CreateAttendance {
2121
card_id: String,
2222
esp_id: u32,

unix-utils/src/response.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,26 @@ pub struct UnixResponse {
1010
pub data: Option<UnixResponseData>,
1111
}
1212

13+
#[derive(Serialize, Deserialize, Debug, Clone)]
14+
pub struct AutoSetupSettings {
15+
pub ssid: String,
16+
pub psk: String,
17+
pub data: AutoSetupData,
18+
}
19+
20+
#[derive(Serialize, Deserialize, Debug, Clone)]
21+
pub struct AutoSetupData {
22+
pub mdns: bool,
23+
24+
#[serde(rename = "wsUrl")]
25+
pub ws_url: String,
26+
}
27+
1328
#[derive(Serialize, Deserialize, Debug, Clone)]
1429
#[serde(tag = "type", content = "data")]
1530
#[serde(rename_all_fields = "camelCase")]
1631
pub enum UnixResponseData {
17-
WifiSettingsResp2(String),
18-
WifiSettingsResp {
19-
wifi_ssid: String,
20-
wifi_password: String,
21-
},
32+
AutoSetupSettingsResp(AutoSetupSettings),
2233
ServerStatus(CompetitionStatusResp),
2334
PersonInfoResp {
2435
id: String,

0 commit comments

Comments
 (0)