diff options
author | HampusM <hampus@hampusmat.com> | 2022-05-30 20:27:44 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-05-30 20:27:44 +0200 |
commit | 7afb8aedd6f3553aa0ec138373aea18068abd2f8 (patch) | |
tree | f5d806be8c8564bdf082602befb8f4e981c67196 /minion/src/wifi_module.cpp | |
parent | fddfa1a7f48b5fa0dd5a3746206952581ef34128 (diff) |
feat(minion): add print MAC address
Diffstat (limited to 'minion/src/wifi_module.cpp')
-rw-r--r-- | minion/src/wifi_module.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
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<char>(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<int>(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,"; |