Small tweaks
This commit is contained in:
parent
ad2ecdfa52
commit
a81c17cbb1
4
updater/Cargo.lock
generated
4
updater/Cargo.lock
generated
|
@ -378,6 +378,9 @@ dependencies = [
|
||||||
name = "embassy-futures"
|
name = "embassy-futures"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/embassy-rs/embassy#f1f4943ca51e8827146daca950fdf88d5b1e046b"
|
source = "git+https://github.com/embassy-rs/embassy#f1f4943ca51e8827146daca950fdf88d5b1e046b"
|
||||||
|
dependencies = [
|
||||||
|
"defmt",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "embassy-net"
|
name = "embassy-net"
|
||||||
|
@ -1215,6 +1218,7 @@ dependencies = [
|
||||||
"defmt",
|
"defmt",
|
||||||
"defmt-rtt",
|
"defmt-rtt",
|
||||||
"embassy-boot",
|
"embassy-boot",
|
||||||
|
"embassy-futures",
|
||||||
"embassy-net",
|
"embassy-net",
|
||||||
"embassy-time",
|
"embassy-time",
|
||||||
"embedded-io-async",
|
"embedded-io-async",
|
||||||
|
|
|
@ -27,6 +27,7 @@ embassy-time = { version = "0.1", features = [
|
||||||
"defmt-timestamp-uptime",
|
"defmt-timestamp-uptime",
|
||||||
"nightly",
|
"nightly",
|
||||||
] }
|
] }
|
||||||
|
embassy-futures = { version = "0.1", features = ["defmt"] }
|
||||||
rand_core = "0.6.4"
|
rand_core = "0.6.4"
|
||||||
embedded-io-async = { version = "0.5", features = ["defmt-03"] }
|
embedded-io-async = { version = "0.5", features = ["defmt-03"] }
|
||||||
embedded-storage = "0.3.0"
|
embedded-storage = "0.3.0"
|
||||||
|
@ -48,6 +49,7 @@ static_cell = { version = "1.2.0", features = ["nightly"] }
|
||||||
impl-tools = "0.10.0"
|
impl-tools = "0.10.0"
|
||||||
|
|
||||||
[patch.crates-io]
|
[patch.crates-io]
|
||||||
|
embassy-futures = { git = "https://github.com/embassy-rs/embassy" }
|
||||||
embassy-net = { git = "https://github.com/embassy-rs/embassy" }
|
embassy-net = { git = "https://github.com/embassy-rs/embassy" }
|
||||||
embassy-boot = { git = "https://github.com/embassy-rs/embassy" }
|
embassy-boot = { git = "https://github.com/embassy-rs/embassy" }
|
||||||
embassy-time = { git = "https://github.com/embassy-rs/embassy" }
|
embassy-time = { git = "https://github.com/embassy-rs/embassy" }
|
||||||
|
|
|
@ -30,7 +30,7 @@ pub use crate::error::Error;
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
#[serde(rename_all = "snake_case", tag = "status")]
|
#[serde(rename_all = "snake_case", tag = "status")]
|
||||||
enum Status<'a> {
|
pub enum Status<'a> {
|
||||||
Connected { version: &'a str },
|
Connected { version: &'a str },
|
||||||
Disconnected,
|
Disconnected,
|
||||||
PreparingUpdate,
|
PreparingUpdate,
|
||||||
|
@ -48,6 +48,9 @@ impl Status<'_> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This is a wrapper around `BlockingFirmwareUpdater` that downloads signed updates
|
||||||
|
/// from a HTTPS url.
|
||||||
|
/// It also provides the current device status over MQTT
|
||||||
// TODO: Make this the owner of the blocking firmware updater
|
// TODO: Make this the owner of the blocking firmware updater
|
||||||
// TODO: When fixed, use the async firmware updater
|
// TODO: When fixed, use the async firmware updater
|
||||||
pub struct Updater<'a, DFU, STATE>
|
pub struct Updater<'a, DFU, STATE>
|
||||||
|
@ -59,7 +62,6 @@ where
|
||||||
updater: BlockingFirmwareUpdater<'a, DFU, STATE>,
|
updater: BlockingFirmwareUpdater<'a, DFU, STATE>,
|
||||||
|
|
||||||
topic_status: &'static str,
|
topic_status: &'static str,
|
||||||
topic_update: &'static str,
|
|
||||||
version: &'static str,
|
version: &'static str,
|
||||||
public_key: &'static [u8],
|
public_key: &'static [u8],
|
||||||
}
|
}
|
||||||
|
@ -70,22 +72,22 @@ where
|
||||||
STATE: NorFlash,
|
STATE: NorFlash,
|
||||||
DFU::Error: Format,
|
DFU::Error: Format,
|
||||||
{
|
{
|
||||||
|
/// Wrap the `BlockingFirmwareUpdater`
|
||||||
pub fn new(
|
pub fn new(
|
||||||
updater: BlockingFirmwareUpdater<'a, DFU, STATE>,
|
updater: BlockingFirmwareUpdater<'a, DFU, STATE>,
|
||||||
topic_status: &'static str,
|
topic_status: &'static str,
|
||||||
topic_update: &'static str,
|
|
||||||
version: &'static str,
|
version: &'static str,
|
||||||
public_key: &'static [u8],
|
public_key: &'static [u8],
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
updater,
|
updater,
|
||||||
topic_status,
|
topic_status,
|
||||||
topic_update,
|
|
||||||
version,
|
version,
|
||||||
public_key,
|
public_key,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set MQTT connection up to notify over MQTT when the device loses connection
|
||||||
pub fn add_will<const MAX_PROPERTIES: usize>(
|
pub fn add_will<const MAX_PROPERTIES: usize>(
|
||||||
&self,
|
&self,
|
||||||
config: &mut ClientConfig<'_, MAX_PROPERTIES, impl RngCore>,
|
config: &mut ClientConfig<'_, MAX_PROPERTIES, impl RngCore>,
|
||||||
|
@ -94,6 +96,8 @@ where
|
||||||
config.add_will(self.topic_status, msg, true);
|
config.add_will(self.topic_status, msg, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Mark the device is ready and booted, will notify over MQTT that the device is connected and the
|
||||||
|
/// currently running firmware version
|
||||||
pub async fn ready<const MAX_PROPERTIES: usize>(
|
pub async fn ready<const MAX_PROPERTIES: usize>(
|
||||||
&mut self,
|
&mut self,
|
||||||
client: &mut MqttClient<'_, impl Write + Read, MAX_PROPERTIES, impl RngCore>,
|
client: &mut MqttClient<'_, impl Write + Read, MAX_PROPERTIES, impl RngCore>,
|
||||||
|
@ -107,21 +111,20 @@ where
|
||||||
.send_message(self.topic_status, &status, QualityOfService::QoS1, true)
|
.send_message(self.topic_status, &status, QualityOfService::QoS1, true)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
client.subscribe_to_topic(self.topic_update).await?;
|
|
||||||
|
|
||||||
self.updater.mark_booted()?;
|
self.updater.mark_booted()?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Download signed update from specified url and notify progress over MQTT
|
||||||
pub async fn update<const MAX_PROPERTIES: usize>(
|
pub async fn update<const MAX_PROPERTIES: usize>(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
url: Url<'_>,
|
||||||
stack: &'static Stack<impl Driver>,
|
stack: &'static Stack<impl Driver>,
|
||||||
rng: &mut (impl RngCore + CryptoRng),
|
rng: &mut (impl RngCore + CryptoRng),
|
||||||
client: &mut MqttClient<'_, impl Write + Read, MAX_PROPERTIES, impl RngCore>,
|
client: &mut MqttClient<'_, impl Write + Read, MAX_PROPERTIES, impl RngCore>,
|
||||||
url: Url<'_>,
|
|
||||||
) -> Result<!, Error<DFU::Error>> {
|
) -> Result<!, Error<DFU::Error>> {
|
||||||
let result = self._update(stack, rng, client, url).await;
|
let result = self._update(url, stack, rng, client).await;
|
||||||
|
|
||||||
if let Err(err) = &result {
|
if let Err(err) = &result {
|
||||||
let status = Status::UpdateFailed {
|
let status = Status::UpdateFailed {
|
||||||
|
@ -139,10 +142,10 @@ where
|
||||||
|
|
||||||
async fn _update<const MAX_PROPERTIES: usize>(
|
async fn _update<const MAX_PROPERTIES: usize>(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
url: Url<'_>,
|
||||||
stack: &'static Stack<impl Driver>,
|
stack: &'static Stack<impl Driver>,
|
||||||
rng: &mut (impl RngCore + CryptoRng),
|
rng: &mut (impl RngCore + CryptoRng),
|
||||||
client: &mut MqttClient<'_, impl Write + Read, MAX_PROPERTIES, impl RngCore>,
|
client: &mut MqttClient<'_, impl Write + Read, MAX_PROPERTIES, impl RngCore>,
|
||||||
url: Url<'_>,
|
|
||||||
) -> Result<!, Error<DFU::Error>> {
|
) -> Result<!, Error<DFU::Error>> {
|
||||||
info!("Preparing for OTA...");
|
info!("Preparing for OTA...");
|
||||||
let status = Status::PreparingUpdate.json();
|
let status = Status::PreparingUpdate.json();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user