From 7afb8aedd6f3553aa0ec138373aea18068abd2f8 Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 30 May 2022 20:27:44 +0200 Subject: feat(minion): add print MAC address --- minion/src/wifi_module.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'minion/src/wifi_module.cpp') diff --git a/minion/src/wifi_module.cpp b/minion/src/wifi_module.cpp index 953e9fa..8a2dd6a 100644 --- a/minion/src/wifi_module.cpp +++ b/minion/src/wifi_module.cpp @@ -254,6 +254,60 @@ auto WiFiModule::get_local_ip(char *local_ip_out) noexcept -> const char * return local_ip_out; } +auto WiFiModule::get_mac_address(char *mac_address_out) noexcept -> const char * +{ + const auto send_success = _send_serial("AT+CIFSR"); + + if (!send_success) + { + return mac_address_out; + } + + auto *buf = util::malloc(strlen(mac_address_out) + 1U); + + if (buf == nullptr) + { + strcpy(mac_address_out, "Memory allocation failure"); + return mac_address_out; + } + + strcpy(buf, ""); + + const auto response_status = _read(10000U, buf); + + if (response_status != WiFiModuleResponseStatus::OK) + { + free(buf); + + sprintf( + mac_address_out, + "Response status was not OK. Was %d", + static_cast(response_status) + ); + + return mac_address_out; + } + + const auto stamac_title = "CIFSR:STAMAC,\""; + + auto mac_address_start = strstr(buf, stamac_title); + + if (mac_address_start == nullptr) + { + free(buf); + strcpy(mac_address_out, "Response parsing error"); + return mac_address_out; + } + + mac_address_start += strlen(stamac_title); + + util::substr(mac_address_start, mac_address_start + 17U, mac_address_out); + + free(buf); + + return mac_address_out; +} + auto WiFiModule::read_incoming_request() noexcept -> HTTPRequest { char request_prefix[] = "+IPD,"; -- cgit v1.2.3-18-g5258