From ea8110d3a0036a4ff7bdecf9554f747a342d6b49 Mon Sep 17 00:00:00 2001 From: Jan Romann Date: Sun, 24 Nov 2024 15:09:41 +0100 Subject: [PATCH] fixup! feat: use uuid urn as device ID in TD --- src/bin/async_main.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/bin/async_main.rs b/src/bin/async_main.rs index f90943e..f419012 100644 --- a/src/bin/async_main.rs +++ b/src/bin/async_main.rs @@ -4,7 +4,10 @@ extern crate alloc; -use alloc::{borrow::ToOwned, format, string::String}; +use alloc::{ + format, + string::{String, ToString}, +}; use embassy_executor::Spawner; use embassy_net::{Stack, StackResources}; use embassy_sync::{blocking_mutex::raw::CriticalSectionRawMutex, mutex::Mutex}; @@ -27,13 +30,13 @@ use esp_wifi::{ }, EspWifiController, }; -use nuuid::Uuid; use picoserve::{ extract::State, response::{Response, StatusCode}, routing::get, }; use shtcx::{self, sensor_class::Sht2Gen, shtc3, PowerMode, ShtCx}; +use uuid::Builder; use wot_td::{builder::*, Thing}; #[derive(Clone, Copy)] @@ -87,19 +90,15 @@ macro_rules! mk_static { const SSID: &str = env!("SSID"); const PASSWORD: &str = env!("PASSWORD"); -fn convert_integer_buffer_to_bytes(data: [u32; 8]) -> [u8; 32] { +fn convert_integer_buffer_to_bytes(data: [u32; 4]) -> [u8; 16] { unsafe { core::mem::transmute(data) } } fn generate_uuid_urn(rng: &mut Rng) -> alloc::string::String { - let mut uuid_buffer: [u8; 45] = [0; 45]; - let seed: [u8; 32] = convert_integer_buffer_to_bytes([(); 8].map(|()| rng.random())); - - let mut uuid_rng = nuuid::Rng::from_seed(seed); - let uuid = Uuid::new_v4_rng(&mut uuid_rng); + let random_bytes: [u8; 16] = convert_integer_buffer_to_bytes([(); 4].map(|()| rng.random())); + let uuid = Builder::from_random_bytes(random_bytes).into_uuid(); - uuid.to_urn(&mut uuid_buffer); - core::str::from_utf8(&uuid_buffer).unwrap().to_owned() + uuid.urn().to_string() } #[esp_hal_embassy::main]