From 3a44c0f273598b4920592d75a732c53e8d1f6d69 Mon Sep 17 00:00:00 2001 From: pennam Date: Mon, 21 Oct 2024 16:17:09 +0200 Subject: [PATCH 1/7] MbedSocketClass: remove commented code --- libraries/SocketWrapper/src/SocketHelpers.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/SocketWrapper/src/SocketHelpers.cpp b/libraries/SocketWrapper/src/SocketHelpers.cpp index ada31434f..e8f0eb2fd 100644 --- a/libraries/SocketWrapper/src/SocketHelpers.cpp +++ b/libraries/SocketWrapper/src/SocketHelpers.cpp @@ -7,7 +7,6 @@ uint8_t* arduino::MbedSocketClass::macAddress(uint8_t* mac) { sscanf(&mac_str[b * 2 + (b)], "%02x", (unsigned int*)&tmp); mac[5 - b] = (uint8_t)tmp; } - //sscanf(mac_str, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", &mac[5], &mac[4], &mac[3], &mac[2], &mac[1], &mac[0]); return mac; } From b3a7171726463a4d9787d74fbb366d77660d6ffd Mon Sep 17 00:00:00 2001 From: pennam Date: Mon, 21 Oct 2024 16:18:03 +0200 Subject: [PATCH 2/7] MbedSocketClass: add checks on mac address string --- libraries/SocketWrapper/src/SocketHelpers.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libraries/SocketWrapper/src/SocketHelpers.cpp b/libraries/SocketWrapper/src/SocketHelpers.cpp index e8f0eb2fd..25af983f3 100644 --- a/libraries/SocketWrapper/src/SocketHelpers.cpp +++ b/libraries/SocketWrapper/src/SocketHelpers.cpp @@ -11,7 +11,11 @@ uint8_t* arduino::MbedSocketClass::macAddress(uint8_t* mac) { } String arduino::MbedSocketClass::macAddress() { - return String(getNetwork()->get_mac_address()); + const char* mac_str = getNetwork()->get_mac_address(); + if (!mac_str) { + return String("ff:ff:ff:ff:ff:ff"); + } + return String(mac_str); } int arduino::MbedSocketClass::hostByName(const char* aHostname, IPAddress& aResult) { From d84e2fc5caf2b9c30366e2f164e2c2c85365047e Mon Sep 17 00:00:00 2001 From: pennam Date: Mon, 21 Oct 2024 16:23:40 +0200 Subject: [PATCH 3/7] macAddress: add function description --- libraries/SocketWrapper/src/SocketHelpers.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/libraries/SocketWrapper/src/SocketHelpers.h b/libraries/SocketWrapper/src/SocketHelpers.h index c31988fde..046a63a0a 100644 --- a/libraries/SocketWrapper/src/SocketHelpers.h +++ b/libraries/SocketWrapper/src/SocketHelpers.h @@ -128,7 +128,26 @@ class MbedSocketClass { int hostByName(const char* aHostname, IPAddress& aResult); + /* + * Get the interface MAC address. + * + * Network interface should be ready to get a valid mac address. + * Call WiFi.begin("",""); or Ethernet.begin(); before issuing a mac address + * request, otherwhise returned value will be ff:ff:ff:ff:ff:ff + * + * return: pointer to uint8_t array with length WL_MAC_ADDR_LENGTH + */ uint8_t* macAddress(uint8_t* mac); + + /* + * Get the interface MAC address String. + * + * Network interface should be ready to get a valid MAC address. + * Call WiFi.begin("",""); or Ethernet.begin(); before issuing a mac address + * request, otherwhise returned value will be ff:ff:ff:ff:ff:ff + * + * return: MAC Address String + */ String macAddress(); void setFeedWatchdogFunc(voidFuncPtr func); From 89d6ea7f5db1fecc6861b93d0817067e9036047f Mon Sep 17 00:00:00 2001 From: pennam Date: Mon, 21 Oct 2024 16:28:03 +0200 Subject: [PATCH 4/7] SocketHelpers: align comments --- libraries/SocketWrapper/src/SocketHelpers.h | 114 ++++++++++---------- 1 file changed, 57 insertions(+), 57 deletions(-) diff --git a/libraries/SocketWrapper/src/SocketHelpers.h b/libraries/SocketWrapper/src/SocketHelpers.h index 046a63a0a..85f3fea32 100644 --- a/libraries/SocketWrapper/src/SocketHelpers.h +++ b/libraries/SocketWrapper/src/SocketHelpers.h @@ -28,100 +28,100 @@ class MbedSocketClass { void config(IPAddress local_ip); /* Change Ip configuration settings disabling the dhcp client - * - * param local_ip: Static ip configuration as string - */ + * + * param local_ip: Static ip configuration as string + */ void config(const char* local_ip); /* Change Ip configuration settings disabling the dhcp client - * - * param local_ip: Static ip configuration - * param dns_server: IP configuration for DNS server 1 - */ + * + * param local_ip: Static ip configuration + * param dns_server: IP configuration for DNS server 1 + */ void config(IPAddress local_ip, IPAddress dns_server); /* Change Ip configuration settings disabling the dhcp client - * - * param local_ip: Static ip configuration - * param dns_server: IP configuration for DNS server 1 - * param gateway : Static gateway configuration - */ + * + * param local_ip: Static ip configuration + * param dns_server: IP configuration for DNS server 1 + * param gateway : Static gateway configuration + */ void config(IPAddress local_ip, IPAddress dns_server, IPAddress gateway); /* Change Ip configuration settings disabling the dhcp client - * - * param local_ip: Static ip configuration - * param dns_server: IP configuration for DNS server 1 - * param gateway: Static gateway configuration - * param subnet: Static Subnet mask - */ + * + * param local_ip: Static ip configuration + * param dns_server: IP configuration for DNS server 1 + * param gateway: Static gateway configuration + * param subnet: Static Subnet mask + */ void config(IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet); /* Change DNS Ip configuration - * - * param dns_server1: ip configuration for DNS server 1 - */ + * + * param dns_server1: ip configuration for DNS server 1 + */ void setDNS(IPAddress dns_server1); /* Change DNS Ip configuration - * - * param dns_server1: ip configuration for DNS server 1 - * param dns_server2: ip configuration for DNS server 2 - * - */ + * + * param dns_server1: ip configuration for DNS server 1 + * param dns_server2: ip configuration for DNS server 2 + * + */ void setDNS(IPAddress dns_server1, IPAddress dns_server2); /* - * Get the interface IP address. - * - * return: Ip address value - */ + * Get the interface IP address. + * + * return: Ip address value + */ IPAddress localIP(); /* - * Get the interface subnet mask address. - * - * return: subnet mask address value - */ + * Get the interface subnet mask address. + * + * return: subnet mask address value + */ IPAddress subnetMask(); /* - * Get the gateway ip address. - * - * return: gateway ip address value - */ + * Get the gateway ip address. + * + * return: gateway ip address value + */ IPAddress gatewayIP(); /* - * Get the DNS Server ip address. - * - * return: DNS Server ip address value - */ + * Get the DNS Server ip address. + * + * return: DNS Server ip address value + */ IPAddress dnsServerIP(); /* - * Get the DNS Server ip address. - * - * return: DNS Server ip address value - */ + * Get the DNS Server ip address. + * + * return: DNS Server ip address value + */ IPAddress dnsIP(int n = 0); virtual NetworkInterface* getNetwork() = 0; - + /* - * Download a file from an HTTP endpoint and save it in the provided `target` location on the fs - * The parameter cbk can be used to perform actions on the buffer before saving on the fs - * - * return: on success the size of the downloaded file, on error -status code - */ + * Download a file from an HTTP endpoint and save it in the provided `target` location on the fs + * The parameter cbk can be used to perform actions on the buffer before saving on the fs + * + * return: on success the size of the downloaded file, on error -status code + */ int download( const char* url, const char* target, bool const is_https = false); /* - * Download a file from an HTTP endpoint and handle the body of the request on a callback - * passed as an argument - * - * return: on success the size of the downloaded file, on error -status code - */ + * Download a file from an HTTP endpoint and handle the body of the request on a callback + * passed as an argument + * + * return: on success the size of the downloaded file, on error -status code + */ int download( const char* url, bool const is_https = false, mbed::Callback cbk = nullptr); From b6bc4bf2a1f2c4e0349453cbefc0ffff2d2e6ed1 Mon Sep 17 00:00:00 2001 From: pennam Date: Fri, 25 Oct 2024 09:58:23 +0200 Subject: [PATCH 5/7] WiFi: align comments --- libraries/WiFi/src/WiFi.h | 118 +++++++++++++++++++------------------- 1 file changed, 59 insertions(+), 59 deletions(-) diff --git a/libraries/WiFi/src/WiFi.h b/libraries/WiFi/src/WiFi.h index dd01192a2..35590cd02 100644 --- a/libraries/WiFi/src/WiFi.h +++ b/libraries/WiFi/src/WiFi.h @@ -55,25 +55,25 @@ class WiFiClass : public MbedSocketClass { : wifi_if(_if){}; /* - * Get firmware version - */ + * Get firmware version + */ static const char* firmwareVersion(); /* Start Wifi connection for OPEN networks - * - * param ssid: Pointer to the SSID string. - */ + * + * param ssid: Pointer to the SSID string. + */ int begin(const char* ssid); void MACAddress(uint8_t *mac_address); /* Start Wifi connection with passphrase - * the most secure supported mode will be automatically selected - * - * param ssid: Pointer to the SSID string. - * param passphrase: Passphrase. Valid characters in a passphrase - * must be between ASCII 32-126 (decimal). - */ + * the most secure supported mode will be automatically selected + * + * param ssid: Pointer to the SSID string. + * param passphrase: Passphrase. Valid characters in a passphrase + * must be between ASCII 32-126 (decimal). + */ int begin(const char* ssid, const char* passphrase, wl_enc_type security = ENC_TYPE_UNKNOWN); // When using DHCP the hostname provided will be used. @@ -87,86 +87,86 @@ class WiFiClass : public MbedSocketClass { int beginAP(const char* ssid, const char* passphrase, uint8_t channel = DEFAULT_AP_CHANNEL); /* - * Disconnect from the network - * - * return: one value of wl_status_t enum - */ + * Disconnect from the network + * + * return: one value of wl_status_t enum + */ int disconnect(void); void end(void); /* - * Return the current SSID associated with the network - * - * return: ssid string - */ + * Return the current SSID associated with the network + * + * return: ssid string + */ char* SSID(); /* - * Return the current BSSID associated with the network. - * It is the MAC address of the Access Point - * - * return: pointer to uint8_t array with length WL_MAC_ADDR_LENGTH - */ + * Return the current BSSID associated with the network. + * It is the MAC address of the Access Point + * + * return: pointer to uint8_t array with length WL_MAC_ADDR_LENGTH + */ uint8_t* BSSID(uint8_t* bssid); /* - * Return the current RSSI /Received Signal Strength in dBm) - * associated with the network - * - * return: signed value - */ + * Return the current RSSI /Received Signal Strength in dBm) + * associated with the network + * + * return: signed value + */ int32_t RSSI(); /* - * Return the Encryption Type associated with the network - * - * return: one value of wl_enc_type enum - */ + * Return the Encryption Type associated with the network + * + * return: one value of wl_enc_type enum + */ uint8_t encryptionType(); /* - * Start scan WiFi networks available - * - * return: Number of discovered networks - */ + * Start scan WiFi networks available + * + * return: Number of discovered networks + */ int8_t scanNetworks(); /* - * Return the SSID discovered during the network scan. - * - * param networkItem: specify from which network item want to get the information - * - * return: ssid string of the specified item on the networks scanned list - */ + * Return the SSID discovered during the network scan. + * + * param networkItem: specify from which network item want to get the information + * + * return: ssid string of the specified item on the networks scanned list + */ char* SSID(uint8_t networkItem); /* - * Return the encryption type of the networks discovered during the scanNetworks - * - * param networkItem: specify from which network item want to get the information - * - * return: encryption type (enum wl_enc_type) of the specified item on the networks scanned list - */ + * Return the encryption type of the networks discovered during the scanNetworks + * + * param networkItem: specify from which network item want to get the information + * + * return: encryption type (enum wl_enc_type) of the specified item on the networks scanned list + */ uint8_t encryptionType(uint8_t networkItem); uint8_t* BSSID(uint8_t networkItem, uint8_t* bssid); uint8_t channel(uint8_t networkItem); /* - * Return the RSSI of the networks discovered during the scanNetworks - * - * param networkItem: specify from which network item want to get the information - * - * return: signed value of RSSI of the specified item on the networks scanned list - */ + * Return the RSSI of the networks discovered during the scanNetworks + * + * param networkItem: specify from which network item want to get the information + * + * return: signed value of RSSI of the specified item on the networks scanned list + */ int32_t RSSI(uint8_t networkItem); /* - * Return Connection status. - * - * return: one of the value defined in wl_status_t - */ + * Return Connection status. + * + * return: one of the value defined in wl_status_t + */ uint8_t status(); unsigned long getTime(); From 89c7c9af36af6f95d03b5d4c829090300bfe462e Mon Sep 17 00:00:00 2001 From: pennam Date: Mon, 28 Oct 2024 12:48:02 +0100 Subject: [PATCH 6/7] SocketHelpers: fix macAddress(uint8_t* mac) reversed order --- libraries/SocketWrapper/src/SocketHelpers.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/SocketWrapper/src/SocketHelpers.cpp b/libraries/SocketWrapper/src/SocketHelpers.cpp index 25af983f3..c4f5fc5e7 100644 --- a/libraries/SocketWrapper/src/SocketHelpers.cpp +++ b/libraries/SocketWrapper/src/SocketHelpers.cpp @@ -5,7 +5,7 @@ uint8_t* arduino::MbedSocketClass::macAddress(uint8_t* mac) { for (int b = 0; b < 6; b++) { uint32_t tmp; sscanf(&mac_str[b * 2 + (b)], "%02x", (unsigned int*)&tmp); - mac[5 - b] = (uint8_t)tmp; + mac[b] = (uint8_t)tmp; } return mac; } From 5c2458ba975a765742a6bfd87867af34bfb1c056 Mon Sep 17 00:00:00 2001 From: pennam Date: Wed, 6 Nov 2024 09:51:03 +0100 Subject: [PATCH 7/7] WiFi: deprecate MACAddress --- libraries/WiFi/src/WiFi.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/WiFi/src/WiFi.h b/libraries/WiFi/src/WiFi.h index 35590cd02..2548f60bb 100644 --- a/libraries/WiFi/src/WiFi.h +++ b/libraries/WiFi/src/WiFi.h @@ -65,7 +65,7 @@ class WiFiClass : public MbedSocketClass { */ int begin(const char* ssid); - void MACAddress(uint8_t *mac_address); + void MACAddress(uint8_t *mac_address) __attribute__((deprecated("Use macAddress(uint8_t *mac_address)"))); /* Start Wifi connection with passphrase * the most secure supported mode will be automatically selected