Compare commits

..

3 Commits

6 changed files with 78 additions and 15 deletions

View File

@ -371,7 +371,7 @@ fn safe_main() -> anyhow::Result<()> {
let _webserver = httpd(reboot_now.clone()); let _webserver = httpd(reboot_now.clone());
wait_infinity(WaitType::StayAlive, reboot_now.clone()); wait_infinity(WaitType::StayAlive, reboot_now.clone());
} }
let mut did_pump = false;
match plant_to_pump { match plant_to_pump {
Some(plant) => { Some(plant) => {
let mut state = plantstate[plant]; let mut state = plantstate[plant];
@ -395,7 +395,7 @@ fn safe_main() -> anyhow::Result<()> {
"Trying to pump for {}s with pump {} now", "Trying to pump for {}s with pump {} now",
plant_config.pump_time_s, plant plant_config.pump_time_s, plant
); );
did_pump = true;
board.any_pump(true)?; board.any_pump(true)?;
board.store_last_pump_time(plant, cur); board.store_last_pump_time(plant, cur);
board.pump(plant, true)?; board.pump(plant, true)?;
@ -522,14 +522,25 @@ fn safe_main() -> anyhow::Result<()> {
} }
12 * 60 12 * 60
} else if is_day { } else if is_day {
if online_mode == OnlineMode::Online { if did_pump {
let _ = board.mqtt_publish( if online_mode == OnlineMode::Online {
&config, let _ = board.mqtt_publish(
"/deepsleep", &config,
"normal 20m".as_bytes(), "/deepsleep",
); "after pump".as_bytes(),
);
}
0
} else {
if online_mode == OnlineMode::Online {
let _ = board.mqtt_publish(
&config,
"/deepsleep",
"normal 20m".as_bytes(),
);
}
20
} }
20
} else { } else {
if online_mode == OnlineMode::Online { if online_mode == OnlineMode::Online {
let _ = board.mqtt_publish( let _ = board.mqtt_publish(

View File

@ -717,14 +717,22 @@ impl PlantCtrlBoardInteraction for PlantCtrlBoard<'_> {
println!("Some error assembling full_topic 2"); println!("Some error assembling full_topic 2");
bail!("Some error assembling full_topic 2") bail!("Some error assembling full_topic 2")
}; };
client.publish( let publish = client.publish(
&full_topic, &full_topic,
embedded_svc::mqtt::client::QoS::ExactlyOnce, embedded_svc::mqtt::client::QoS::ExactlyOnce,
true, true,
message, message,
)?; );
match publish {
OkStd(_) => return Ok(()),
Err(err) => {
println!("Error during mqtt send on topic {} with message {:#?} error is {:?}",full_topic, message, err);
return Err(err)?
},
}
return Ok(()); ;
} }
fn state_charge_percent(&mut self) -> Result<u8> { fn state_charge_percent(&mut self) -> Result<u8> {

View File

@ -1,6 +1,13 @@
<html> <html>
<body> <body>
<h2>Current Firmware</h2>
<div>
<div id="firmware_buildtime">Buildtime loading</div>
<div id="firmware_githash">Build githash loading</div>
</div>
<h2>firmeware OTA v3</h2> <h2>firmeware OTA v3</h2>
<form id="upload_form" method="post"> <form id="upload_form" method="post">
<input type="file" name="file1" id="file1"><br> <input type="file" name="file1" id="file1"><br>
<progress id="progressBar" value="0" max="100" style="width:300px;"></progress> <progress id="progressBar" value="0" max="100" style="width:300px;"></progress>
@ -9,6 +16,8 @@
<p id="loaded_n_total"></p> <p id="loaded_n_total"></p>
</form> </form>
<h2>config</h2> <h2>config</h2>
<div id="configform"> <div id="configform">
@ -82,4 +91,4 @@
<script src="bundle.js"></script> <script src="bundle.js"></script>
</body> </body>
</html> </html>

View File

@ -1,7 +1,11 @@
<html> <html>
<body> <body>
<input type="button" id="test" value="Test"> <input type="button" id="test" value="Test">
<h2>Current Firmware</h2>
<div>
<div id="firmware_buildtime">Buildtime loading</div>
<div id="firmware_githash">Build githash loading</div>
</div>
<div> <div>
<h2>firmeware OTA v3</h2> <h2>firmeware OTA v3</h2>
<form id="upload_form" method="post"> <form id="upload_form" method="post">

View File

@ -22,6 +22,12 @@ struct SSIDList<'a> {
ssids: Vec<&'a String<32>>, ssids: Vec<&'a String<32>>,
} }
#[derive(Serialize, Debug)]
struct VersionInfo<'a> {
git_hash: &'a str,
build_time: &'a str
}
pub fn httpd_initial(reboot_now: Arc<AtomicBool>) -> Box<EspHttpServer<'static>> { pub fn httpd_initial(reboot_now: Arc<AtomicBool>) -> Box<EspHttpServer<'static>> {
let mut server = shared(); let mut server = shared();
server server
@ -170,7 +176,14 @@ pub fn shared() -> Box<EspHttpServer<'static>> {
server server
.fn_handler("/version", Method::Get, |request| { .fn_handler("/version", Method::Get, |request| {
let mut response = request.into_ok_response()?; let mut response = request.into_ok_response()?;
response.write(env!("VERGEN_GIT_DESCRIBE").as_bytes())?; let git_hash = env!("VERGEN_GIT_DESCRIBE");
let build_time = env!("VERGEN_BUILD_TIMESTAMP");
let version_info = VersionInfo{
git_hash,
build_time,
};
let version_info_json = serde_json::to_string(&version_info)?;
response.write(version_info_json.as_bytes())?;
anyhow::Ok(()) anyhow::Ok(())
}) })
.unwrap(); .unwrap();

View File

@ -33,5 +33,23 @@ export function uploadFile() {
ajax.send(file); ajax.send(file);
} }
interface VersionInfo{
git_hash:string,
build_time: string
}
let file1Upload = document.getElementById("file1") as HTMLInputElement; let file1Upload = document.getElementById("file1") as HTMLInputElement;
file1Upload.onchange = uploadFile; file1Upload.onchange = uploadFile;
let firmware_buildtime = document.getElementById("firmware_buildtime") as HTMLDivElement;
let firmware_githash = document.getElementById("firmware_githash") as HTMLDivElement;
document.addEventListener('DOMContentLoaded', function() {
fetch("/version")
.then(response => response.json())
.then(json => json as VersionInfo)
.then(versionInfo => {
firmware_buildtime.innerText = versionInfo.build_time;
firmware_githash.innerText = versionInfo.git_hash;
})
}, false);