From 77d293353e456e95245d4f333e06e7a202efc93d Mon Sep 17 00:00:00 2001 From: Sebastian Hugentobler Date: Mon, 18 Nov 2024 08:21:14 +0100 Subject: [PATCH] add mosquitto example --- controller/README.md | 11 +++++++++++ controller/src/cmd_handlers/mod.rs | 1 + controller/src/main.rs | 1 - 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/controller/README.md b/controller/README.md index bbc35cb..7d31565 100644 --- a/controller/README.md +++ b/controller/README.md @@ -105,6 +105,17 @@ In order to decode a message, apply the above steps in reverse order. All configuration is read on startup of the microcontroller. +## MQTT + +To read and decode the MQTT messages one can use for example mosquitto as +follows (using the test.mosquitto.org broker): + +``` +mosquitto_sub -h test.mosquitto.org -p 1883 -t "temps/potato" | perl -e 'while(read(STDIN,$b,4)){printf "%.2f\n", unpack("f<",$b)}' +``` + +The perl magic is for decoding the floating point little endian representation. + ## Outlook - Pull the flash/config handling into separate library for testability diff --git a/controller/src/cmd_handlers/mod.rs b/controller/src/cmd_handlers/mod.rs index 1ed5511..35130c2 100644 --- a/controller/src/cmd_handlers/mod.rs +++ b/controller/src/cmd_handlers/mod.rs @@ -8,6 +8,7 @@ use serial_comm::{cobs, protocol::set_config::SetConfig}; use crate::flash::{Config, FlashError}; #[derive(Debug)] +#[allow(dead_code)] pub struct Utf8Error(pub core::str::Utf8Error); impl Format for Utf8Error { diff --git a/controller/src/main.rs b/controller/src/main.rs index 5249780..348d6fc 100644 --- a/controller/src/main.rs +++ b/controller/src/main.rs @@ -13,7 +13,6 @@ use embassy_executor::Spawner; use embassy_net::Stack; use embassy_time::Timer; use flash::{Config, FlashError}; -use mqtt_protocol::publish::MAX_TOPIC_LENGTH; use static_cell::StaticCell; use temperature::{temperature_task, Temperature}; use usb_serial::{init_usb, usb_task};