mirror of
https://github.com/stakwork/sphinx-key.git
synced 2025-12-17 07:14:23 +01:00
parse config from json encoded param
This commit is contained in:
@@ -26,6 +26,7 @@ log = "0.4"
|
||||
url = "2"
|
||||
serde_urlencoded = "0.7.1"
|
||||
serde = "1.0.137"
|
||||
serde_json = "1.0.81"
|
||||
|
||||
[build-dependencies]
|
||||
embuild = "0.29"
|
||||
|
||||
@@ -12,17 +12,25 @@ use esp_idf_svc::nvs_storage::EspNvsStorage;
|
||||
use embedded_svc::storage::Storage;
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize)]
|
||||
pub struct Params {
|
||||
pub config: String
|
||||
}
|
||||
#[derive(Clone, Debug, Deserialize)]
|
||||
pub struct Config {
|
||||
pub broker: String,
|
||||
// pub ssid: String,
|
||||
// pub pass: String,
|
||||
pub ssid: String,
|
||||
pub pass: String,
|
||||
}
|
||||
|
||||
/*
|
||||
curl -X POST 192.168.71.1/config?broker=52.91.253.115%3A1883&ssid=apples%26acorns&pass=42flutes
|
||||
|
||||
curl -X POST 192.168.71.1/config?ssid=apples%26acorns&pass=42flutes&broker=52.91.253.115%3A1883
|
||||
|
||||
curl -X POST 192.168.71.1/config?broker=52.91.253.115%3A1883
|
||||
|
||||
curl -X POST 192.168.71.1/config?config=%7B%22ssid%22%3A%22apples%26acorns%22%2C%22pass%22%3A%2242flutes%22%2C%22broker%22%3A%2252.91.253.115%3A1883%22%7D
|
||||
*/
|
||||
|
||||
#[allow(unused_variables)]
|
||||
@@ -34,8 +42,11 @@ pub fn config_server(mutex: Arc<(Mutex<Option<Config>>, Condvar)>, store: Arc<Mu
|
||||
.at("/config")
|
||||
.post(move |mut request| {
|
||||
let bod = &request.query_string()
|
||||
.ok_or(anyhow::anyhow!("failed to parse query string"))?;;
|
||||
let conf = serde_urlencoded::from_str::<Config>(bod)?;
|
||||
.ok_or(anyhow::anyhow!("failed to parse query string"))?;
|
||||
println!("bod {:?}", bod);
|
||||
let params = serde_urlencoded::from_str::<Params>(bod)?;
|
||||
|
||||
let conf = serde_json::from_str::<Config>(¶ms.config)?;
|
||||
|
||||
let mut wait = mutex.0.lock().unwrap();
|
||||
*wait = Some(conf);
|
||||
|
||||
Reference in New Issue
Block a user