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 | |
| parent | fddfa1a7f48b5fa0dd5a3746206952581ef34128 (diff) | |
feat(minion): add print MAC address
Diffstat (limited to 'minion/src')
| -rw-r--r-- | minion/src/gymnasiearbete.cpp | 5 | ||||
| -rw-r--r-- | minion/src/wifi_module.cpp | 54 | ||||
| -rw-r--r-- | minion/src/wifi_module.hpp | 9 | 
3 files changed, 68 insertions, 0 deletions
diff --git a/minion/src/gymnasiearbete.cpp b/minion/src/gymnasiearbete.cpp index 54e8d50..d2a970b 100644 --- a/minion/src/gymnasiearbete.cpp +++ b/minion/src/gymnasiearbete.cpp @@ -80,6 +80,11 @@ void setup()  	Serial.print(F("IP address: "));  	Serial.println(wifi_module.get_local_ip(local_ip)); +	char mac_address[MAX_NETWORK_MODULE_RESPONSE_LENGTH] = ""; + +	Serial.print(F("MAC address: ")); +	Serial.println(wifi_module.get_mac_address(mac_address)); +  	wifi_module.set_multiple_connections_enabled(true);  	delay(MILLIS_IN_SECOND); 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,"; diff --git a/minion/src/wifi_module.hpp b/minion/src/wifi_module.hpp index 9bc2c20..da4a487 100644 --- a/minion/src/wifi_module.hpp +++ b/minion/src/wifi_module.hpp @@ -98,6 +98,15 @@ public:  	auto get_local_ip(char *local_ip_out) noexcept -> const char *;  	/** +	 * Gets the MAC address of the wifi module. +	 * +	 * @param mac_address_out MAC address output buffer. +	 * +	 * @returns A pointer to the MAC address output buffer. +	 */ +	auto get_mac_address(char *mac_address_out) noexcept -> const char *; + +	/**  	 * Reads a incoming HTTP request.  	 *  	 * @returns A request. Has a connection with a ID of -1 if reading the request failed.  | 
