progress new ui
This commit is contained in:
@@ -258,7 +258,7 @@ fn safe_main() -> anyhow::Result<()> {
|
||||
Err(err) => {
|
||||
println!("Missing normal config, entering config mode {}", err);
|
||||
//config upload will trigger reboot!
|
||||
let _ = board.wifi_ap();
|
||||
let _ = board.wifi_ap(Option::None);
|
||||
drop(board);
|
||||
let reboot_now = Arc::new(AtomicBool::new(false));
|
||||
let _webserver = httpd(reboot_now.clone());
|
||||
@@ -293,13 +293,15 @@ fn safe_main() -> anyhow::Result<()> {
|
||||
board.general_fault(true);
|
||||
}
|
||||
}
|
||||
match board.mqtt(&config) {
|
||||
Ok(_) => {
|
||||
println!("Mqtt connection ready");
|
||||
mqtt = true;
|
||||
}
|
||||
Err(err) => {
|
||||
println!("Could not connect mqtt due to {}", err);
|
||||
if (config.network.mqtt_url.is_some()){
|
||||
match board.mqtt(&config) {
|
||||
Ok(_) => {
|
||||
println!("Mqtt connection ready");
|
||||
mqtt = true;
|
||||
}
|
||||
Err(err) => {
|
||||
println!("Could not connect mqtt due to {}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -312,6 +314,16 @@ fn safe_main() -> anyhow::Result<()> {
|
||||
println!("No wifi configured");
|
||||
}
|
||||
|
||||
if !wifi && to_config {
|
||||
println!("Could not connect to station and config mode forced, switching to ap mode!");
|
||||
match board.wifi_ap(Some(config.network.ap_ssid.clone())) {
|
||||
Ok(_) => {
|
||||
println!("Started ap, continuing")
|
||||
},
|
||||
Err(err) => println!("Could not start config override ap mode due to {}", err.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
let timezone_time = cur.with_timezone(&TIME_ZONE);
|
||||
println!(
|
||||
"Running logic at utc {} and {} {}",
|
||||
|
@@ -514,9 +514,10 @@ impl PlantCtrlBoard<'_> {
|
||||
unsafe { gpio_hold_en(self.general_fault.pin()) };
|
||||
}
|
||||
|
||||
pub fn wifi_ap(&mut self) -> Result<()> {
|
||||
pub fn wifi_ap(&mut self, ap_ssid: Option<heapless::String<32>>) -> Result<()> {
|
||||
let ssid = ap_ssid.unwrap_or(heapless::String::from_str("PlantCtrl Emergency Mode").unwrap());
|
||||
let apconfig = AccessPointConfiguration {
|
||||
ssid: heapless::String::from_str("PlantCtrl").unwrap(),
|
||||
ssid,
|
||||
auth_method: AuthMethod::None,
|
||||
ssid_hidden: false,
|
||||
..Default::default()
|
||||
@@ -643,6 +644,7 @@ impl PlantCtrlBoard<'_> {
|
||||
}
|
||||
|
||||
pub fn get_rtc_time(&mut self) -> Result<DateTime<Utc>> {
|
||||
|
||||
match self.rtc.datetime() {
|
||||
OkStd(rtc_time) => {
|
||||
return Ok(rtc_time.and_utc());
|
||||
@@ -743,11 +745,18 @@ impl PlantCtrlBoard<'_> {
|
||||
.base_topic
|
||||
.as_ref()
|
||||
.context("missing base topic")?;
|
||||
if base_topic.is_empty() {
|
||||
bail!("Mqtt base_topic was empty")
|
||||
}
|
||||
let mqtt_url = config
|
||||
.network
|
||||
.mqtt_url
|
||||
.as_ref()
|
||||
.context("missing mqtt url")?;
|
||||
if mqtt_url.is_empty() {
|
||||
bail!("Mqtt url was empty")
|
||||
}
|
||||
|
||||
|
||||
let last_will_topic = format!("{}/state", base_topic);
|
||||
let mqtt_client_config = MqttClientConfiguration {
|
||||
@@ -805,26 +814,41 @@ impl PlantCtrlBoard<'_> {
|
||||
}
|
||||
}
|
||||
}
|
||||
embedded_svc::mqtt::client::EventPayload::Connected(_) => {
|
||||
esp_idf_svc::mqtt::client::EventPayload::Connected(_) => {
|
||||
mqtt_connected_event_received_copy
|
||||
.store(true, std::sync::atomic::Ordering::Relaxed);
|
||||
mqtt_connected_event_ok_copy.store(true, std::sync::atomic::Ordering::Relaxed);
|
||||
println!("Mqtt connected");
|
||||
}
|
||||
embedded_svc::mqtt::client::EventPayload::Disconnected => {
|
||||
esp_idf_svc::mqtt::client::EventPayload::Disconnected => {
|
||||
mqtt_connected_event_received_copy
|
||||
.store(true, std::sync::atomic::Ordering::Relaxed);
|
||||
mqtt_connected_event_ok_copy.store(false, std::sync::atomic::Ordering::Relaxed);
|
||||
println!("Mqtt disconnected");
|
||||
}
|
||||
embedded_svc::mqtt::client::EventPayload::Error(esp_error) => {
|
||||
esp_idf_svc::mqtt::client::EventPayload::Error(esp_error) => {
|
||||
println!("EspMqttError reported {:?}", esp_error);
|
||||
mqtt_connected_event_received_copy
|
||||
.store(true, std::sync::atomic::Ordering::Relaxed);
|
||||
mqtt_connected_event_ok_copy.store(false, std::sync::atomic::Ordering::Relaxed);
|
||||
println!("Mqtt error");
|
||||
}
|
||||
_ => {}
|
||||
esp_idf_svc::mqtt::client::EventPayload::BeforeConnect => {
|
||||
println!("Mqtt before connect")
|
||||
},
|
||||
esp_idf_svc::mqtt::client::EventPayload::Subscribed(_) => {
|
||||
println!("Mqtt subscribed")
|
||||
},
|
||||
esp_idf_svc::mqtt::client::EventPayload::Unsubscribed(_) => {
|
||||
println!("Mqtt unsubscribed")
|
||||
},
|
||||
esp_idf_svc::mqtt::client::EventPayload::Published(_) => {
|
||||
println!("Mqtt published")
|
||||
},
|
||||
esp_idf_svc::mqtt::client::EventPayload::Deleted(_) => {
|
||||
println!("Mqtt deleted")
|
||||
},
|
||||
|
||||
}
|
||||
})?;
|
||||
|
||||
|
Reference in New Issue
Block a user