File tree Expand file tree Collapse file tree 2 files changed +9
-4
lines changed Expand file tree Collapse file tree 2 files changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,8 @@ fn main() -> anyhow::Result<()> {
2626 let nvs = EspDefaultNvsPartition :: take ( ) ?;
2727 let peripherals = Peripherals :: take ( ) ?;
2828
29- let wifi = wifi:: configure ( & event_loop, & nvs, peripherals. modem ) ?;
29+ let mut wifi = wifi:: configure ( & event_loop, & nvs, peripherals. modem ) ?;
30+ let device_id = wifi:: get_mac ( & mut wifi) ;
3031 std:: mem:: forget ( wifi) ;
3132
3233 let ( mut mqtt_client, mqtt_connection) = mqtt:: configure ( ) ?;
@@ -91,8 +92,7 @@ fn main() -> anyhow::Result<()> {
9192 if question_id. is_empty ( ) {
9293 continue ;
9394 }
94- // TODO: add device id (from MAC?)
95- let payload = format ! ( "{}|{}" , question_id, data) ;
95+ let payload = format ! ( "{}|{}|{}" , device_id, question_id, data) ;
9696 mqtt_client. enqueue ( "answer" , QoS :: AtLeastOnce , false , payload. as_bytes ( ) ) ?;
9797
9898 display. clear ( ) ;
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ use embedded_svc::wifi::{ClientConfiguration, Configuration};
44use esp_idf_svc:: eventloop:: EspSystemEventLoop ;
55use esp_idf_svc:: hal:: modem:: Modem ;
66use esp_idf_svc:: nvs:: EspDefaultNvsPartition ;
7- use esp_idf_svc:: wifi:: { BlockingWifi , EspWifi } ;
7+ use esp_idf_svc:: wifi:: { BlockingWifi , EspWifi , WifiDeviceId } ;
88use log:: info;
99
1010pub fn configure (
@@ -28,3 +28,8 @@ pub fn configure(
2828 info ! ( "[WIFI] Connected" ) ;
2929 Ok ( wifi)
3030}
31+
32+ pub fn get_mac ( wifi : & mut BlockingWifi < EspWifi > ) -> String {
33+ let mac_bytes = wifi. wifi_mut ( ) . get_mac ( WifiDeviceId :: Sta ) . unwrap ( ) ;
34+ mac_bytes. map ( |b| format ! ( "{:X}" , b) ) . join ( ":" )
35+ }
You can’t perform that action at this time.
0 commit comments