delay messages to reduce mqtt issues (sender to fast) improve mqtt debugging

This commit is contained in:
Empire 2024-03-02 14:43:52 +01:00
parent e070c802d5
commit 869a581242
2 changed files with 35 additions and 24 deletions

View File

@ -325,33 +325,45 @@ fn safe_main() -> anyhow::Result<()> {
let mut water_frozen = false;
let mut temp:Option<f32> = None;
for _attempt in 0..5 {
let water_temperature = board.water_temperature_c();
match water_temperature {
Ok(temp) => {
Ok(res) => {
temp = Some(res);
break;
}
Err(err) => {
println!("Could not get water temp {} attempt {}", err, _attempt)
}
}
}
match temp {
Some(res) => {
println!("Water temp is {}", res);
if res < 4_f32 {
water_frozen = true;
}
if online_mode == OnlineMode::Online {
let _ = board.mqtt_publish(
&config,
"/water/temperature",
temp.to_string().as_bytes(),
res.to_string().as_bytes(),
);
}
//FIXME mqtt here
println!("Water temp is {}", temp);
if temp < 4_f32 {
water_frozen = true;
}
break;
}
Err(err) => {
},
None => {
if online_mode == OnlineMode::Online {
let _ = board.mqtt_publish(&config, "/water/temperature", "Error".as_bytes());
}
println!("Could not get water temp {}", err)
}
}
},
}
let mut plantstate = [PlantState {
..Default::default()
}; PLANT_COUNT];
@ -560,7 +572,6 @@ fn safe_main() -> anyhow::Result<()> {
//is light out of work trigger soon?
//is battery low ??
//is deep sleep
mark_app_valid();
unsafe { esp_deep_sleep(1000 * 1000 * 60 * deep_sleep_duration_minutes as u64) };
@ -953,9 +964,6 @@ fn determine_next_plant(
}
println!("Plant {} state is {:?}", plant, state);
}
if online_mode == OnlineMode::Online {
update_plant_state(plantstate, board, config);
}
for plant in 0..PLANT_COUNT {
let state = &plantstate[plant];
println!(

View File

@ -723,11 +723,14 @@ impl PlantCtrlBoardInteraction for PlantCtrlBoard<'_> {
true,
message,
);
Delay::new(10).delay_ms(10);
match publish {
OkStd(_) => return Ok(()),
OkStd(message_id) => {
println!("Published mqtt topic {} with message {:#?} msgid is {:?}",full_topic, String::from_utf8_lossy(message), message_id);
return Ok(())
},
Err(err) => {
println!("Error during mqtt send on topic {} with message {:#?} error is {:?}",full_topic, message, err);
println!("Error during mqtt send on topic {} with message {:#?} error is {:?}",full_topic, String::from_utf8_lossy(message), err);
return Err(err)?
},
}