delay messages to reduce mqtt issues (sender to fast) improve mqtt debugging
This commit is contained in:
parent
e070c802d5
commit
869a581242
@ -325,33 +325,45 @@ fn safe_main() -> anyhow::Result<()> {
|
|||||||
|
|
||||||
|
|
||||||
let mut water_frozen = false;
|
let mut water_frozen = false;
|
||||||
|
let mut temp:Option<f32> = None;
|
||||||
for _attempt in 0..5 {
|
for _attempt in 0..5 {
|
||||||
let water_temperature = board.water_temperature_c();
|
let water_temperature = board.water_temperature_c();
|
||||||
match water_temperature {
|
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 {
|
if online_mode == OnlineMode::Online {
|
||||||
let _ = board.mqtt_publish(
|
let _ = board.mqtt_publish(
|
||||||
&config,
|
&config,
|
||||||
"/water/temperature",
|
"/water/temperature",
|
||||||
temp.to_string().as_bytes(),
|
res.to_string().as_bytes(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
//FIXME mqtt here
|
},
|
||||||
println!("Water temp is {}", temp);
|
None => {
|
||||||
if temp < 4_f32 {
|
|
||||||
water_frozen = true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
if online_mode == OnlineMode::Online {
|
if online_mode == OnlineMode::Online {
|
||||||
let _ = board.mqtt_publish(&config, "/water/temperature", "Error".as_bytes());
|
let _ = board.mqtt_publish(&config, "/water/temperature", "Error".as_bytes());
|
||||||
}
|
}
|
||||||
println!("Could not get water temp {}", err)
|
},
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let mut plantstate = [PlantState {
|
let mut plantstate = [PlantState {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}; PLANT_COUNT];
|
}; PLANT_COUNT];
|
||||||
@ -560,7 +572,6 @@ fn safe_main() -> anyhow::Result<()> {
|
|||||||
//is light out of work trigger soon?
|
//is light out of work trigger soon?
|
||||||
//is battery low ??
|
//is battery low ??
|
||||||
//is deep sleep
|
//is deep sleep
|
||||||
|
|
||||||
mark_app_valid();
|
mark_app_valid();
|
||||||
|
|
||||||
unsafe { esp_deep_sleep(1000 * 1000 * 60 * deep_sleep_duration_minutes as u64) };
|
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);
|
println!("Plant {} state is {:?}", plant, state);
|
||||||
}
|
}
|
||||||
if online_mode == OnlineMode::Online {
|
|
||||||
update_plant_state(plantstate, board, config);
|
|
||||||
}
|
|
||||||
for plant in 0..PLANT_COUNT {
|
for plant in 0..PLANT_COUNT {
|
||||||
let state = &plantstate[plant];
|
let state = &plantstate[plant];
|
||||||
println!(
|
println!(
|
||||||
|
@ -723,11 +723,14 @@ impl PlantCtrlBoardInteraction for PlantCtrlBoard<'_> {
|
|||||||
true,
|
true,
|
||||||
message,
|
message,
|
||||||
);
|
);
|
||||||
|
Delay::new(10).delay_ms(10);
|
||||||
match publish {
|
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) => {
|
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)?
|
return Err(err)?
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user