Implemented Pull OTA json
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
use chrono::NaiveDateTime;
|
||||
use enum_stringify::EnumStringify;
|
||||
use serde::{ser::SerializeStruct, Deserialize, Serialize};
|
||||
use sqlx::types::mac_address::MacAddress;
|
||||
use strum::EnumString;
|
||||
|
||||
#[derive(Deserialize, Debug, Serialize)]
|
||||
pub struct TelemetryMessage {
|
||||
@@ -35,11 +37,10 @@ pub struct ValueMessage {
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct Device {
|
||||
pub display_name: Option<String>,
|
||||
pub id: MacAddress
|
||||
pub display_name: Option<String>,
|
||||
pub id: MacAddress,
|
||||
}
|
||||
|
||||
|
||||
impl Serialize for Device {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
@@ -50,9 +51,35 @@ impl Serialize for Device {
|
||||
// Serialize each field with custom logic
|
||||
let bytes = self.id.bytes();
|
||||
state.serialize_field("display_name", &self.display_name)?;
|
||||
state.serialize_field("id", &format!("{}{}{}{}{}{}", bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5]))?;
|
||||
state.serialize_field(
|
||||
"id",
|
||||
&format!(
|
||||
"{}{}{}{}{}{}",
|
||||
bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5]
|
||||
),
|
||||
)?;
|
||||
|
||||
// End the serialization process
|
||||
state.end()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
pub struct OTAConfiguration {
|
||||
pub board: BoardType,
|
||||
pub configuration: BoardConfig,
|
||||
pub version: String,
|
||||
pub url: String
|
||||
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize, EnumString)]
|
||||
pub enum BoardType {
|
||||
Waterlevel
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize, EnumString)]
|
||||
pub enum BoardConfig {
|
||||
INA226,
|
||||
INA233
|
||||
}
|
||||
Reference in New Issue
Block a user