diff --git a/.gitignore b/.gitignore
index bef9554fc..38b51e79b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,3 +9,4 @@ cores/arduino/mydebug.cpp.donotuse
.DS_Store?
/.vs
/.gitignore
+.vscode/settings.json
diff --git a/cores/arduino/analog.cpp b/cores/arduino/analog.cpp
index 37d3d6cc7..a457bc2a3 100644
--- a/cores/arduino/analog.cpp
+++ b/cores/arduino/analog.cpp
@@ -645,7 +645,7 @@ void analogReadResolution(int bits) {
default:
_analogRequestedReadResolution = 12;
adc.cfg.resolution = ADC_RESOLUTION_12_BIT;
- adc1.cfg.resolution = ADC_RESOLUTION_10_BIT;
+ adc1.cfg.resolution = ADC_RESOLUTION_12_BIT;
break;
}
diff --git a/extras/net/lwipopts.h b/extras/net/lwipopts.h
index 87d0d9a5c..3d8022920 100644
--- a/extras/net/lwipopts.h
+++ b/extras/net/lwipopts.h
@@ -277,7 +277,7 @@
* (requires the LWIP_RAW option)
*/
#ifndef MEMP_NUM_RAW_PCB
-#define MEMP_NUM_RAW_PCB 0
+#define MEMP_NUM_RAW_PCB 1
#endif
/**
@@ -642,7 +642,7 @@
* LWIP_RAW==1: Enable application layer to hook into the IP layer itself.
*/
#ifndef LWIP_RAW
-#define LWIP_RAW 0
+#define LWIP_RAW 1
#endif
/*
diff --git a/libraries/Ethernet/examples/EthernetPing/EthernetPing.ino b/libraries/Ethernet/examples/EthernetPing/EthernetPing.ino
new file mode 100644
index 000000000..2baadaadd
--- /dev/null
+++ b/libraries/Ethernet/examples/EthernetPing/EthernetPing.ino
@@ -0,0 +1,83 @@
+/*
+ Web ICMP Ping
+
+ This sketch pings a device based on the IP address or the hostname
+ using the Ethernet module.
+
+ created 14 February 2024
+ by paulvha
+
+ updated 27 February 2025
+ by Fabik111
+
+ */
+
+#include "EthernetC33.h"
+
+int status = WL_IDLE_STATUS;
+
+// Set the static IP address to use if the DHCP fails to assign
+IPAddress ip(10, 130, 22, 84);
+
+/* -------------------------------------------------------------------------- */
+void setup() {
+/* -------------------------------------------------------------------------- */
+ //Initialize serial and wait for port to open:
+ Serial.begin(115200);
+ while (!Serial) {
+ ; // wait for serial port to connect. Needed for native USB port only
+ }
+
+ // start the Ethernet connection:
+ if (Ethernet.begin() == 0) {
+ Serial.println("Failed to configure Ethernet using DHCP");
+ // try to configure using IP address instead of DHCP:
+ // IN THAT CASE YOU SHOULD CONFIGURE manually THE DNS or USE the IPAddress Server variable above
+ // that is what is automatically done here...
+ Ethernet.begin(ip);
+ }
+ // give the Ethernet shield a second to initialize:
+ delay(2000);
+}
+
+/* -------------------------------------------------------------------------- */
+void loop() {
+/* -------------------------------------------------------------------------- */
+
+ // Ping IP
+ const IPAddress remote_ip(140,82,121,4);
+ Serial.print("Trying to ping github.com on IP: ");
+ Serial.println(remote_ip);
+
+ // using default ping count of 1
+ int res = Ethernet.ping(remote_ip);
+
+ if (res > 0) {
+ Serial.print("Ping response time: ");
+ Serial.print(res);
+ Serial.println(" ms");
+ }
+ else {
+ Serial.println("Timeout on IP!");
+ }
+
+ // Ping Host
+ const char* remote_host = "www.google.com";
+ Serial.print("Trying to ping host: ");
+ Serial.println(remote_host);
+
+ // setting ttl to 128 and ping count to 10
+ int res1 = Ethernet.ping(remote_host);
+
+ if (res1 > 0) {
+ Serial.print("Ping average response time: ");
+ Serial.print(res1);
+ Serial.println(" ms");
+ }
+ else {
+ Serial.println("Timeout on host!");
+ }
+
+ Serial.println();
+ delay(1000);
+}
diff --git a/libraries/Ethernet/src/Ethernet.cpp b/libraries/Ethernet/src/Ethernet.cpp
index 993ea2372..35bbd4fd3 100644
--- a/libraries/Ethernet/src/Ethernet.cpp
+++ b/libraries/Ethernet/src/Ethernet.cpp
@@ -223,4 +223,27 @@ IPAddress CEthernet::dnsServerIP() {
return CLwipIf::getInstance().getDns();
}
+/* -------------------------------------------------------------------------- */
+int CEthernet::ping(IPAddress ip, uint8_t ttl) {
+/* -------------------------------------------------------------------------- */
+ return CLwipIf::getInstance().ping(ip, ttl);
+}
+
+/* -------------------------------------------------------------------------- */
+int CEthernet::ping(const String &hostname, uint8_t ttl)
+/* -------------------------------------------------------------------------- */
+{
+ return ping(hostname.c_str(), ttl);
+}
+
+/* -------------------------------------------------------------------------- */
+int CEthernet::ping(const char* host, uint8_t ttl) {
+/* -------------------------------------------------------------------------- */
+ IPAddress ip;
+ if(CLwipIf::getInstance().getHostByName(host,ip)) {
+ return CLwipIf::getInstance().ping(ip, ttl);
+ }
+ return -1;
+}
+
CEthernet Ethernet;
diff --git a/libraries/Ethernet/src/EthernetC33.h b/libraries/Ethernet/src/EthernetC33.h
index 5c684fe63..5147d0464 100644
--- a/libraries/Ethernet/src/EthernetC33.h
+++ b/libraries/Ethernet/src/EthernetC33.h
@@ -69,6 +69,12 @@ class CEthernet {
IPAddress gatewayIP();
IPAddress dnsServerIP();
+ /*
+ * PING
+ */
+ int ping(IPAddress ip, uint8_t ttl = 128);
+ int ping(const String &hostname, uint8_t ttl = 128);
+ int ping(const char* host, uint8_t ttl = 128);
friend class EthernetClient;
friend class EthernetServer;
diff --git a/libraries/RTC/examples/Test_RTC/Test_RTC.ino b/libraries/RTC/examples/Test_RTC/Test_RTC.ino
index 0fcbc5132..eca534eda 100644
--- a/libraries/RTC/examples/Test_RTC/Test_RTC.ino
+++ b/libraries/RTC/examples/Test_RTC/Test_RTC.ino
@@ -11,8 +11,8 @@
// Include the RTC library
#include "RTC.h"
-// Define the interrupt pin for LED control during interrupts
-const int LED_ON_INTERRUPT = 22;
+// Define the pin to toggle on interrupt
+const int PIN_ON_INTERRUPT = D7;
bool periodicFlag = false;
bool alarmFlag = false;
@@ -37,7 +37,7 @@ void setup() {
// Set LED pins as outputs
pinMode(LED_BUILTIN, OUTPUT);
- pinMode(LED_ON_INTERRUPT, OUTPUT);
+ pinMode(PIN_ON_INTERRUPT, OUTPUT);
// Initialize the RTC
RTC.begin();
@@ -83,10 +83,10 @@ void loop() {
// Toggle the LED based on callback state
if (clb_st) {
- digitalWrite(LED_ON_INTERRUPT, HIGH);
+ digitalWrite(PIN_ON_INTERRUPT, HIGH);
}
else {
- digitalWrite(LED_ON_INTERRUPT, LOW);
+ digitalWrite(PIN_ON_INTERRUPT, LOW);
}
clb_st = !clb_st; // Toggle callback state
diff --git a/libraries/RTC/src/RTC.cpp b/libraries/RTC/src/RTC.cpp
index 843af650c..4f5d5d240 100644
--- a/libraries/RTC/src/RTC.cpp
+++ b/libraries/RTC/src/RTC.cpp
@@ -435,6 +435,11 @@ void __attribute__((weak)) rtc_callback(rtc_callback_args_t *p_args) {
rtc_instance_ctrl_t rtc_ctrl = {
.open = 0,
+ .p_cfg = nullptr,
+ .carry_isr_triggered = false,
+ .p_callback = nullptr,
+ .p_callback_memory = nullptr,
+ .p_context = nullptr,
};
#ifndef RTC_CLOCK_SOURCE
@@ -458,6 +463,7 @@ rtc_cfg_t rtc_cfg = {
.carry_irq = FSP_INVALID_VECTOR,
.p_callback = rtc_callback,
.p_context = NULL,
+ .p_extend = NULL,
};
#ifdef __cplusplus
diff --git a/libraries/WiFi/examples/WiFiPing/WiFiPing.ino b/libraries/WiFi/examples/WiFiPing/WiFiPing.ino
new file mode 100644
index 000000000..a8f9ee979
--- /dev/null
+++ b/libraries/WiFi/examples/WiFiPing/WiFiPing.ino
@@ -0,0 +1,120 @@
+/*
+ Web ICMP Ping
+
+ This sketch pings a device based on the IP address or the hostname
+ using the WiFi module. By default the attempt is performed 5 times, but can
+ be changed to max. 255
+
+ It requires at least version 0.5.0 of USB Wifi bridge firmware and WiFiS3 library.
+
+ This example is written for a network using WPA encryption. For
+ WEP or WPA, change the WiFi.begin() call accordingly.
+
+ created 14 February 2024
+ by paulvha
+
+ updated 27 February 2025
+ by Fabik111
+
+ */
+
+#include "WiFiC3.h"
+#include "arduino_secrets.h"
+
+///////please enter your sensitive data in the Secret tab/arduino_secrets.h
+char ssid[] = SECRET_SSID; // your network SSID (name)
+char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
+int keyIndex = 0; // your network key index number (needed only for WEP)
+
+int status = WL_IDLE_STATUS;
+
+/* -------------------------------------------------------------------------- */
+void setup() {
+/* -------------------------------------------------------------------------- */
+ //Initialize serial and wait for port to open:
+ Serial.begin(115200);
+ while (!Serial) {
+ ; // wait for serial port to connect. Needed for native USB port only
+ }
+
+ // check for the WiFi module:
+ if (WiFi.status() == WL_NO_MODULE) {
+ Serial.println("Communication with WiFi module failed.");
+ // don't continue
+ while (true);
+ }
+
+ // attempt to connect to WiFi network:
+ while (status != WL_CONNECTED) {
+ Serial.print("Attempting to connect to SSID: ");
+ Serial.println(ssid);
+ // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
+ status = WiFi.begin(ssid, pass);
+
+ // wait 10 seconds for connection:
+ delay(10000);
+ }
+
+ printWifiStatus();
+}
+
+/* -------------------------------------------------------------------------- */
+void loop() {
+/* -------------------------------------------------------------------------- */
+
+ // Ping IP
+ const IPAddress remote_ip(140,82,121,4);
+ Serial.print("Trying to ping github.com on IP: ");
+ Serial.println(remote_ip);
+
+ // using default ping count of 1
+ int res = WiFi.ping(remote_ip);
+
+ if (res > 0) {
+ Serial.print("Ping response time: ");
+ Serial.print(res);
+ Serial.println(" ms");
+ }
+ else {
+ Serial.println("Timeout on IP!");
+ }
+
+ // Ping Host
+ const char* remote_host = "www.google.com";
+ Serial.print("Trying to ping host: ");
+ Serial.println(remote_host);
+
+ // setting ttl to 128 and ping count to 10
+ int res1 = WiFi.ping(remote_host);
+
+ if (res1 > 0) {
+ Serial.print("Ping average response time: ");
+ Serial.print(res1);
+ Serial.println(" ms");
+ }
+ else {
+ Serial.println("Timeout on host!");
+ }
+
+ Serial.println();
+ delay(1000);
+}
+
+/* -------------------------------------------------------------------------- */
+void printWifiStatus() {
+/* -------------------------------------------------------------------------- */
+ // print the SSID of the network you're attached to:
+ Serial.print("SSID: ");
+ Serial.println(WiFi.SSID());
+
+ // print your board's IP address:
+ IPAddress ip = WiFi.localIP();
+ Serial.print("IP Address: ");
+ Serial.println(ip);
+
+ // print the received signal strength:
+ long rssi = WiFi.RSSI();
+ Serial.print("signal strength (RSSI):");
+ Serial.print(rssi);
+ Serial.println(" dBm");
+}
diff --git a/libraries/WiFi/examples/WiFiPing/arduino_secrets.h b/libraries/WiFi/examples/WiFiPing/arduino_secrets.h
new file mode 100644
index 000000000..0c9fdd556
--- /dev/null
+++ b/libraries/WiFi/examples/WiFiPing/arduino_secrets.h
@@ -0,0 +1,2 @@
+#define SECRET_SSID ""
+#define SECRET_PASS ""
diff --git a/libraries/WiFi/src/WiFi.cpp b/libraries/WiFi/src/WiFi.cpp
index ba19f311c..fe4a7e7b1 100644
--- a/libraries/WiFi/src/WiFi.cpp
+++ b/libraries/WiFi/src/WiFi.cpp
@@ -321,12 +321,33 @@ unsigned long CWifi::getTime() {
return 0;
}
-
-
void CWifi::setTimeout(unsigned long timeout) {
(void)(timeout);
}
+/* -------------------------------------------------------------------------- */
+int CWifi::ping(IPAddress ip, uint8_t ttl) {
+/* -------------------------------------------------------------------------- */
+ return CLwipIf::getInstance().ping(ip, ttl);
+}
+
+/* -------------------------------------------------------------------------- */
+int CWifi::ping(const String &hostname, uint8_t ttl)
+/* -------------------------------------------------------------------------- */
+{
+ return ping(hostname.c_str(), ttl);
+}
+
+/* -------------------------------------------------------------------------- */
+int CWifi::ping(const char* host, uint8_t ttl) {
+/* -------------------------------------------------------------------------- */
+ IPAddress ip;
+ if(hostByName(host,ip)) {
+ return CLwipIf::getInstance().ping(ip, ttl);
+ }
+ return -1;
+}
+
CWifi WiFi;
diff --git a/libraries/WiFi/src/WiFiC3.h b/libraries/WiFi/src/WiFiC3.h
index 2995cdcf9..2ff804d42 100644
--- a/libraries/WiFi/src/WiFiC3.h
+++ b/libraries/WiFi/src/WiFiC3.h
@@ -254,7 +254,12 @@ class CWifi {
void setTimeout(unsigned long timeout);
-
+ /*
+ * PING
+ */
+ int ping(IPAddress ip, uint8_t ttl = 128);
+ int ping(const String &hostname, uint8_t ttl = 128);
+ int ping(const char* host, uint8_t ttl = 128);
};
diff --git a/libraries/WiFiS3/docs/api.md b/libraries/WiFiS3/docs/api.md
new file mode 100644
index 000000000..c2b66bd6e
--- /dev/null
+++ b/libraries/WiFiS3/docs/api.md
@@ -0,0 +1,1243 @@
+# Summary
+
+ Members | Descriptions
+--------------------------------|---------------------------------------------
+`class ` [`WiFiClient`](#class_wi_fi_client) | Represents a Wi-Fi client that connects to a remote server over a Wi-Fi network.
+`class ` [`WiFiFileSystem`](#class_wi_fi_file_system) | Class that handles the WiFi file system operations.
+`class ` [`WiFiServer`](#class_wi_fi_server) | A class that provides server functionality for WiFi-based communication.
+`class ` [`WiFiSSLClient`](#class_wi_fi_s_s_l_client) | A specialized client class for secure SSL/TLS connections.
+`class ` [`WiFiUDP`](#class_wi_fi_u_d_p) | A class for handling UDP communication over a Wi-Fi network.
+
+# class `WiFiClient`
+
+```cpp
+class WiFiClient
+ : public Client
+```
+
+Represents a Wi-Fi client that connects to a remote server over a Wi-Fi network.
+
+The [WiFiClient](#class_wi_fi_client) class allows for network communication over Wi-Fi, providing methods for establishing connections, sending and receiving data, and managing the client’s socket state. This class is used to manage client connections in a Wi-Fi network, either for communication or for network data transfer.
+
+It inherits from the Client class, providing basic socket communication functionality.
+
+## Summary
+
+ Members | Descriptions
+--------------------------------|---------------------------------------------
+| [`WiFiClient`](#class_wi_fi_client_1aa22ef0fd15a3e2b8ac45eceb0df3bc74) | Default constructor for the [WiFiClient](#class_wi_fi_client) class. |
+| [`WiFiClient`](#class_wi_fi_client_1a53ed2903b15a61a52c3b90406978be89) | Constructor to initialize a [WiFiClient](#class_wi_fi_client) object with a specific socket. |
+| [`WiFiClient`](#class_wi_fi_client_1a1b176d034c1239bdcffa6db13ef5e485) | Copy constructor for the [WiFiClient](#class_wi_fi_client) class. |
+| [`~WiFiClient`](#class_wi_fi_client_1a6410fb12d526d541c436136b18faa0db) | Destructor for the [WiFiClient](#class_wi_fi_client) class. |
+| [`connect`](#class_wi_fi_client_1a0c10a429fa90cf0589daa9742e10e0ee) | Establishes a connection to a server using an IP address and port. |
+| [`connect`](#class_wi_fi_client_1a00fe1cf5622b3d941c99c944cc2df0e8) | Establishes a connection to a server using a hostname and port. |
+| [`write`](#class_wi_fi_client_1a1bbd17136c9320c9eecb5a98a5fc1720) | Sends a single byte of data to the connected server. |
+| [`write`](#class_wi_fi_client_1a03638bc1d73e73e9cc5cddf6a4a9c320) | Writes a buffer of data to the connected server. |
+| [`available`](#class_wi_fi_client_1ae3f72b88b376090eb24f1fe1c16212d7) | Checks the number of bytes available for reading from the server. |
+| [`read`](#class_wi_fi_client_1a8207089f4496ef5b429277fa8cc2d259) | Reads a single byte of data from the server. |
+| [`read`](#class_wi_fi_client_1abd26fb1cce208783b3392507e448d0d2) | Reads multiple bytes of data from the server into a buffer. |
+| [`peek`](#class_wi_fi_client_1a892443057ba2c24ae094c5a87e50cff5) | Peeks at the next byte of incoming data without removing it from the internal buffer. |
+| [`flush`](#class_wi_fi_client_1a54739070fd04288ced179019ee212530) | Flushes the write buffer of the client. |
+| [`stop`](#class_wi_fi_client_1acb61f8e0ecd50e40ce6cbcb7106ce1b1) | Closes the connection to the server and clears the receive buffer. |
+| [`connected`](#class_wi_fi_client_1af083fe27b94aebec37f140c0b973f974) | Checks if the client is connected to a server. |
+| [`operator bool`](#class_wi_fi_client_1adaf93736006b5bb2426e9816de4207eb) | Implicit conversion operator to `bool`. |
+| [`operator==`](#class_wi_fi_client_1ac1e068fb2468d84536e93f6e1b51b099) | Equality operator for comparing two [WiFiClient](#class_wi_fi_client) objects. |
+| [`operator!=`](#class_wi_fi_client_1a31b6e43ab5ab9d6fe511778a5a1f173c) | Inequality operator for comparing two [WiFiClient](#class_wi_fi_client) objects. |
+| [`remoteIP`](#class_wi_fi_client_1a46d45c8d326b62256f85d55eaa337df0) | Retrieves the remote IP address of the server the client is connected to. |
+| [`remotePort`](#class_wi_fi_client_1a38ca1399ebf6570d2c852c9062ec92d8) | Retrieves the remote port number of the server the client is connected to. |
+| [`setConnectionTimeout`](#class_wi_fi_client_1af32938f36f09c9121e85e38338d432d7) | Sets the connection timeout for the client. |
+
+## Members
+
+### `WiFiClient`
+
+```cpp
+WiFiClient()
+```
+
+Default constructor for the [WiFiClient](#class_wi_fi_client) class.
+
+
+
+### `WiFiClient`
+
+```cpp
+WiFiClient(int s)
+```
+
+Constructor to initialize a [WiFiClient](#class_wi_fi_client) object with a specific socket.
+
+#### Parameters
+* `s` is the socket descriptor to associate with this client.
+
+
+### `WiFiClient`
+
+```cpp
+WiFiClient(const WiFiClient & c)
+```
+
+Copy constructor for the [WiFiClient](#class_wi_fi_client) class.
+
+#### Parameters
+* `c` is the [WiFiClient](#class_wi_fi_client) object to copy.
+
+
+### `~WiFiClient`
+
+```cpp
+~WiFiClient()
+```
+
+Destructor for the [WiFiClient](#class_wi_fi_client) class.
+
+
+
+### `connect`
+
+```cpp
+virtual int connect(IPAddress ip, uint16_t port)
+```
+
+Establishes a connection to a server using an IP address and port.
+
+#### Parameters
+* `ip` as the IP address of the server to connect to.
+
+* `port` as the port number on the server to connect to.
+
+#### Returns
+`1` on a successful connection, `0` on failure.
+
+
+### `connect`
+
+```cpp
+virtual int connect(const char * host, uint16_t port)
+```
+
+Establishes a connection to a server using a hostname and port.
+
+#### Parameters
+* `host` is a pointer to a null-terminated string containing the hostname of the server.
+
+* `port` is the port number on the server to connect to.
+
+#### Returns
+`1` if the connection was successful, `0` otherwise.
+
+
+### `write`
+
+```cpp
+virtual size_t write(uint8_t)
+```
+
+Sends a single byte of data to the connected server.
+
+#### Parameters
+* `b` being the byte of data to send.
+
+#### Returns
+The number of bytes successfully written, which is `1` on success or `0` on failure.
+
+
+### `write`
+
+```cpp
+virtual size_t write(const uint8_t * buf, size_t size)
+```
+
+Writes a buffer of data to the connected server.
+
+#### Parameters
+* `Takes` a pointer to a buffer `buf` containing the data to be written and the size of the buffer `size` as parameters.
+
+#### Returns
+The number of bytes successfully written, or `0` if the write operation fails.
+
+
+### `available`
+
+```cpp
+virtual int available()
+```
+
+Checks the number of bytes available for reading from the server.
+
+#### Returns
+The number of bytes available to read. Returns `0` if no data is available, or if the socket is invalid.
+
+
+### `read`
+
+```cpp
+virtual int read()
+```
+
+Reads a single byte of data from the server.
+
+#### Returns
+The byte read as an `int` (0–255). Returns `-1` if no data is available or if an error occurs.
+
+
+### `read`
+
+```cpp
+virtual int read(uint8_t * buf, size_t size)
+```
+
+Reads multiple bytes of data from the server into a buffer.
+
+This function retrieves data from the server's receive buffer and stores it into the provided array. It attempts to read up to the specified number of bytes (`size`).
+
+#### Parameters
+* `buf` is a pointer to the buffer where the data will be stored.
+
+* `size` is the maximum number of bytes to read.
+
+#### Returns
+The number of bytes successfully read into the buffer. Returns `0` if no data is available or if the socket is invalid.
+
+
+### `peek`
+
+```cpp
+virtual int peek()
+```
+
+Peeks at the next byte of incoming data without removing it from the internal buffer.
+
+#### Returns
+The next byte as an `int` (0–255). Returns `-1` if no data is available or if the socket is invalid.
+
+
+### `flush`
+
+```cpp
+virtual void flush()
+```
+
+Flushes the write buffer of the client.
+
+This function ensures that any data buffered for transmission is sent to the connected server. If there is any pending data in the send buffer, it is transmitted over the network.
+
+
+### `stop`
+
+```cpp
+virtual void stop()
+```
+
+Closes the connection to the server and clears the receive buffer.
+
+
+
+### `connected`
+
+```cpp
+virtual uint8_t connected()
+```
+
+Checks if the client is connected to a server.
+
+#### Returns
+Returns 1 if the client is connected, 0 otherwise.
+
+
+### `operator bool`
+
+```cpp
+inline virtual operator bool()
+```
+
+Implicit conversion operator to `bool`.
+
+Converts the [WiFiClient](#class_wi_fi_client) object to a `bool` value indicating whether the client is connected or not.
+
+#### Returns
+`true` if the client socket is open and valid, `false` otherwise.
+
+
+### `operator==`
+
+```cpp
+virtual bool operator==(const WiFiClient &)
+```
+
+Equality operator for comparing two [WiFiClient](#class_wi_fi_client) objects.
+
+Compares the current [WiFiClient](#class_wi_fi_client) object with another [WiFiClient](#class_wi_fi_client) object to determine if they represent the same socket connection.
+
+#### Parameters
+* `The` [WiFiClient](#class_wi_fi_client) object to compare with.
+
+#### Returns
+`true` if both [WiFiClient](#class_wi_fi_client) objects represent the same socket, `false` otherwise.
+
+
+### `operator!=`
+
+```cpp
+inline virtual bool operator!=(const WiFiClient & whs)
+```
+
+Inequality operator for comparing two [WiFiClient](#class_wi_fi_client) objects.
+
+Compares the current [WiFiClient](#class_wi_fi_client) object with another [WiFiClient](#class_wi_fi_client) object to determine if they represent different socket connections.
+
+#### Parameters
+* `whs` is the [WiFiClient](#class_wi_fi_client) object to compare with.
+
+#### Returns
+`true` if both [WiFiClient](#class_wi_fi_client) objects represent different sockets, `false` if they represent the same socket.
+
+
+### `remoteIP`
+
+```cpp
+virtual IPAddress remoteIP()
+```
+
+Retrieves the remote IP address of the server the client is connected to.
+
+#### Returns
+The IP address of the remote server. If not connected, returns IPAddress(0, 0, 0, 0).
+
+
+### `remotePort`
+
+```cpp
+virtual uint16_t remotePort()
+```
+
+Retrieves the remote port number of the server the client is connected to.
+
+#### Returns
+Returns the port number of the remote server. If not connected, returns 0.
+
+
+### `setConnectionTimeout`
+
+```cpp
+inline void setConnectionTimeout(int timeout)
+```
+
+Sets the connection timeout for the client.
+
+#### Parameters
+* `timeout` is the timeout value in milliseconds.
+
+
+# class `WiFiFileSystem`
+
+Class that handles the WiFi file system operations.
+
+This class provides functionality for managing files on a WiFi-connected device, including mounting, reading, writing, and configuring the file system.
+
+## Summary
+
+ Members | Descriptions
+--------------------------------|---------------------------------------------
+| [`WiFiFileSystem`](#class_wi_fi_file_system_1af4d9123dd9631c69853070498afb41a2) | Initializes objects of the [WiFiFileSystem](#class_wi_fi_file_system) class. |
+| [`mount`](#class_wi_fi_file_system_1aa5baed674db176f774488b50fa35c3d1) | Mounts the file system and optionally formats it on failure. |
+| [`writefile`](#class_wi_fi_file_system_1a0121ce8d9a1b9d4a53e7b7ea7ecc4c1c) | Writes data to a file in the file system. |
+| [`readfile`](#class_wi_fi_file_system_1acd3d52b7a20f5f65b7ca28dbb7b04343) | Reads a file from the file system and prints its content. |
+
+## Members
+
+### `WiFiFileSystem`
+
+```cpp
+WiFiFileSystem()
+```
+
+Initializes objects of the [WiFiFileSystem](#class_wi_fi_file_system) class.
+
+
+
+### `mount`
+
+```cpp
+void mount(bool format_on_fault)
+```
+
+Mounts the file system and optionally formats it on failure.
+
+#### Parameters
+* `If` `format_on_fault` is set to `true`, the file system will be formatted if a fault occurs during mounting.
+
+
+### `writefile`
+
+```cpp
+size_t writefile(const char * name, const char * data, size_t size, int operation)
+```
+
+Writes data to a file in the file system.
+
+#### Parameters
+* `name` is the name of the file to which the data will be written. A pointer `data` to the data that will be written to the file. `size` is the number of bytes to write from the provided data buffer. `operation` determines the type of file operation to perform (e.g., create, overwrite).
+
+#### Returns
+Returns the number of bytes successfully written. Returns 0 if the operation fails.
+
+
+### `readfile`
+
+```cpp
+void readfile(const char * name)
+```
+
+Reads a file from the file system and prints its content.
+
+It sends the read request to the modem, which fetches the data. The content is printed to the serial output in chunks, with each chunk being processed until the entire file is read.
+
+#### Parameters
+* `name` is the name of the file to be read from the file system.
+
+
+# class `WiFiServer`
+
+```cpp
+class WiFiServer
+ : public Server
+```
+
+A class that provides server functionality for WiFi-based communication.
+
+The [WiFiServer](#class_wi_fi_server) class inherits from the Server class and extends its functionality to create and manage a server over a WiFi connection. This class allows for accepting incoming client connections, handling data communication, and closing connections in a networked environment.
+
+## Summary
+
+ Members | Descriptions
+--------------------------------|---------------------------------------------
+| [`WiFiServer`](#class_wi_fi_server_1acfa8226decf3a818dfbd45ec7940280a) | Initializes objects of the [WiFiServer](#class_wi_fi_server) class. |
+| [`WiFiServer`](#class_wi_fi_server_1a63b71b18a7011b40fb86d893bc4c72fd) | Constructs a [WiFiServer](#class_wi_fi_server) object with the specified port. |
+| [`available`](#class_wi_fi_server_1abfd839b75fa3c40bd5e22c4a122ed800) | Checks if there are any incoming client connections waiting to be accepted. |
+| [`accept`](#class_wi_fi_server_1ad29b9a043c87bad43140cc3066210088) | Accepts an incoming client connection on the server. |
+| [`begin`](#class_wi_fi_server_1a52e68fa8b767579e5055de9ff072f08c) | Starts the Wi-Fi server and binds it to the specified port. |
+| [`begin`](#class_wi_fi_server_1a953b3d2a3ea0b0582be9535b6aa908d9) | Starts the Wi-Fi server and binds it to the default port. |
+| [`write`](#class_wi_fi_server_1ad3d206415f9733dee2170f136b909e54) | Writes a single byte to all connected clients. |
+| [`write`](#class_wi_fi_server_1a6bef9499519bcedd59379024c4e7b360) | Writes data to all connected clients. |
+| [`end`](#class_wi_fi_server_1a26d44e7107a4121589f96b505c73593d) | Ends the Wi-Fi server and closes the server socket. |
+| [`operator bool`](#class_wi_fi_server_1a1cca17be23aad6b7dce5fc2315226e5d) | Converts the [WiFiSSLClient](#class_wi_fi_s_s_l_client) object to a boolean value. |
+| [`operator==`](#class_wi_fi_server_1a6e3fc602a5e129d19e6fa5076419511f) | Compares two [WiFiServer](#class_wi_fi_server) objects for equality. |
+| [`operator!=`](#class_wi_fi_server_1a3b34f02716dd23e22b85585b4d648169) | Compares two [WiFiServer](#class_wi_fi_server) objects for inequality. |
+
+## Members
+
+### `WiFiServer`
+
+```cpp
+WiFiServer()
+```
+
+Initializes objects of the [WiFiServer](#class_wi_fi_server) class.
+
+
+
+### `WiFiServer`
+
+```cpp
+WiFiServer(int p)
+```
+
+Constructs a [WiFiServer](#class_wi_fi_server) object with the specified port.
+
+#### Parameters
+* `p` The port number on which the server will listen for incoming connections.
+
+
+### `available`
+
+```cpp
+WiFiClient available()
+```
+
+Checks if there are any incoming client connections waiting to be accepted.
+
+This function queries the server to check if there is a client waiting to be accepted. If a client is available, it returns a [WiFiClient](#class_wi_fi_client) object representing the client. It uses the modem to query the server for an available client socket and accepts the connection if a valid client is found.
+
+#### Returns
+Returns a [WiFiClient](#class_wi_fi_client) object representing the next client connection that is available for processing.
+
+
+### `accept`
+
+```cpp
+WiFiClient accept()
+```
+
+Accepts an incoming client connection on the server.
+
+#### Returns
+Returns a [WiFiClient](#class_wi_fi_client) object representing the accepted client.
+
+
+### `begin`
+
+```cpp
+void begin(int port)
+```
+
+Starts the Wi-Fi server and binds it to the specified port.
+
+#### Parameters
+* `port` is the port number which the server will listen to for incoming connections.
+
+
+### `begin`
+
+```cpp
+void begin()
+```
+
+Starts the Wi-Fi server and binds it to the default port.
+
+This function initializes the server and binds it to a default port.
+
+
+### `write`
+
+```cpp
+virtual size_t write(uint8_t)
+```
+
+Writes a single byte to all connected clients.
+
+#### Parameters
+* `b` is the byte to be sent to the clients.
+
+
+### `write`
+
+```cpp
+virtual size_t write(const uint8_t * buf, size_t size)
+```
+
+Writes data to all connected clients.
+
+This function sends a buffer of data to all clients connected to the server. It writes the specified number of bytes to the server socket and returns the count of successfully written bytes.
+
+#### Parameters
+* `buf` is a pointer to the buffer containing the data to be sent. `size` is the number of bytes to write from the buffer.
+
+#### Returns
+The number of bytes successfully written. Returns 0 if the data could not be sent.
+
+
+### `end`
+
+```cpp
+void end()
+```
+
+Ends the Wi-Fi server and closes the server socket.
+
+This function terminates the server by sending a command to the modem to close the server socket. It sets the server socket variable to an invalid state (`-1`) to indicate that the server is no longer active.
+
+
+### `operator bool`
+
+```cpp
+explicit operator bool()
+```
+
+Converts the [WiFiSSLClient](#class_wi_fi_s_s_l_client) object to a boolean value.
+
+This operator allows a [WiFiSSLClient](#class_wi_fi_s_s_l_client) object to be implicitly or explicitly converted to a boolean. It checks whether the client socket is valid (i.e., `_sock != -1`).
+
+#### Returns
+`true` if the server socket is valid (server is running), `false` otherwise.
+
+
+### `operator==`
+
+```cpp
+virtual bool operator==(const WiFiServer &)
+```
+
+Compares two [WiFiServer](#class_wi_fi_server) objects for equality.
+
+This virtual operator compares the underlying socket (`_sock`) of two [WiFiServer](#class_wi_fi_server) objects to determine if they refer to the same server connection.
+
+#### Parameters
+* [WiFiServer](#class_wi_fi_server) object to compare against.
+
+#### Returns
+`true` if both [WiFiServer](#class_wi_fi_server) objects have the same socket; `false` otherwise.
+
+
+### `operator!=`
+
+```cpp
+inline virtual bool operator!=(const WiFiServer & whs)
+```
+
+Compares two [WiFiServer](#class_wi_fi_server) objects for inequality.
+
+This virtual operator compares the underlying socket (`_sock`) of two [WiFiServer](#class_wi_fi_server) objects. It returns `true` if the objects do not refer to the same server connection (i.e., they have different socket values), and `false` otherwise.
+
+#### Parameters
+* `whs` The [WiFiServer](#class_wi_fi_server) object to compare against.
+
+#### Returns
+`true` if the [WiFiServer](#class_wi_fi_server) objects have different sockets; `false` otherwise.
+
+
+# class `WiFiSSLClient`
+
+```cpp
+class WiFiSSLClient
+ : public WiFiClient
+```
+
+A specialized client class for secure SSL/TLS connections.
+
+The [WiFiSSLClient](#class_wi_fi_s_s_l_client) class extends the functionality of the [WiFiClient](#class_wi_fi_client) class to provide secure communication over SSL/TLS protocols. It ensures encrypted and authenticated communication between the client and a remote server.
+
+## Summary
+
+ Members | Descriptions
+--------------------------------|---------------------------------------------
+| [`WiFiSSLClient`](#class_wi_fi_s_s_l_client_1aeecf408e130c75ca84c9e41f7cf708aa) | Initializes objects of the [WiFiSSLClient](#class_wi_fi_s_s_l_client) class. |
+| [`~WiFiSSLClient`](#class_wi_fi_s_s_l_client_1afe721b778749143fe61fdfff259218af) | |
+| [`connect`](#class_wi_fi_s_s_l_client_1a82ed27a660bb90559c0467920182c947) | Establishes a secure SSL connection to a specified IP address and port. |
+| [`connect`](#class_wi_fi_s_s_l_client_1a46375064a7f581ba072e67bdc68be494) | Establishes a secure SSL connection to a specified host and port. |
+| [`setCACert`](#class_wi_fi_s_s_l_client_1ad97df1f2253445c9fec5f4471afcdbf1) | Sets the Certificate Authority (CA) for SSL/TLS verification. |
+| [`setEccSlot`](#class_wi_fi_s_s_l_client_1a9720117b29a35bc2a43c133f76fd8f8e) | Sets the ECC (Elliptic Curve Cryptography) key slot and certificate for establishing secure SSL connections. |
+| [`write`](#class_wi_fi_s_s_l_client_1aa998458d525200ce36277d637008f87c) | Writes a single byte of data to the SSL connection. |
+| [`write`](#class_wi_fi_s_s_l_client_1afa24293a9551bbcca1b565da2607eb2b) | Writes a buffer of data to the SSL connection. |
+| [`available`](#class_wi_fi_s_s_l_client_1ae52872cae6f3aa8b53c50ebe2373eb81) | Checks the number of bytes available for reading from the SSL connection. |
+| [`read`](#class_wi_fi_s_s_l_client_1adac00db4d021b38a513c5ae97e6305ec) | Reads data from the SSL connection into the receive buffer. |
+| [`read`](#class_wi_fi_s_s_l_client_1a163b81ae7656797ed010cdcb0b576e58) | Reads a specified number of bytes from the SSL connection into a buffer. |
+| [`peek`](#class_wi_fi_s_s_l_client_1aafdaf6405d3cbc7807b0ac04fc511061) | Peeks at the next byte available from the SSL connection without removing it. |
+| [`flush`](#class_wi_fi_s_s_l_client_1ae894698f8e8b90ebd298fa66fedadd32) | Flushes the write buffer of the SSL connection. |
+| [`stop`](#class_wi_fi_s_s_l_client_1a66113af6fbc85f0dbb73f8d276b8a77a) | Terminates the SSL/TLS connection and clears the receive buffer. |
+| [`connected`](#class_wi_fi_s_s_l_client_1a5e993c746855bb67c744d27baa6cf1bb) | Checks if the SSL/TLS connection is active. |
+| [`operator bool`](#class_wi_fi_s_s_l_client_1a46888795cc1562c33fad408b57d2ad40) | Implicit conversion operator to check if the SSL client is connected. |
+| [`operator==`](#class_wi_fi_s_s_l_client_1aa0bdf11dd3e6ef48133967dc0a036004) | Comparison operator to check equality between two [WiFiSSLClient](#class_wi_fi_s_s_l_client) objects. |
+| [`operator!=`](#class_wi_fi_s_s_l_client_1a2cdd8020168fae9e08d3c6d00b30b065) | Inequality operator to compare two [WiFiSSLClient](#class_wi_fi_s_s_l_client) objects. |
+| [`remoteIP`](#class_wi_fi_s_s_l_client_1acff0aa8078124dff0c0ff3bfee7cfd83) | Retrieves the remote IP address of the WiFi SSL client. |
+| [`remotePort`](#class_wi_fi_s_s_l_client_1aea76ab94b3cdfec17ab6e73c7b169da7) | Retrieves the remote port number of the WiFi SSL client. |
+
+## Members
+
+### `WiFiSSLClient`
+
+```cpp
+WiFiSSLClient()
+```
+
+Initializes objects of the [WiFiSSLClient](#class_wi_fi_s_s_l_client) class.
+
+
+
+### `~WiFiSSLClient`
+
+```cpp
+~WiFiSSLClient()
+```
+
+
+
+### `connect`
+
+```cpp
+virtual int connect(IPAddress ip, uint16_t port)
+```
+
+Establishes a secure SSL connection to a specified IP address and port.
+
+#### Parameters
+* `It` takes an `IPAddress` object representing the IP address of the server and a `uint16_t` port number as parameters.
+
+#### Returns
+Returns a status code indicating the success or failure of the connection.
+
+
+### `connect`
+
+```cpp
+virtual int connect(const char * host, uint16_t port)
+```
+
+Establishes a secure SSL connection to a specified host and port.
+
+#### Parameters
+* `host` is the hostname or IP address of the server to connect to. `port` is the port number to connect to.
+
+#### Returns
+Returns `1` if the connection is successfully established, `0` otherwise.
+
+
+### `setCACert`
+
+```cpp
+void setCACert(const char * root_ca)
+```
+
+Sets the Certificate Authority (CA) for SSL/TLS verification.
+
+#### Parameters
+* `root_ca` is a pointer to a null-terminated string containing the root CA certificate in PEM format. If set to `nullptr`, the default root CA bundle will be used.
+
+
+### `setEccSlot`
+
+```cpp
+void setEccSlot(int ecc508KeySlot, const byte cert, int certLength)
+```
+
+Sets the ECC (Elliptic Curve Cryptography) key slot and certificate for establishing secure SSL connections.
+
+#### Parameters
+* `int` ecc508KeySlot specifies the ECC key slot to be used for the SSL connection.
+
+* `const` byte cert[] is a pointer to the certificate data in the form of an array of bytes.
+
+* `int` certLength specifies the length of the certificate data array.
+
+
+### `write`
+
+```cpp
+virtual size_t write(uint8_t)
+```
+
+Writes a single byte of data to the SSL connection.
+
+#### Parameters
+* `b` is the byte to be sent.
+
+#### Returns
+The number of bytes successfully written. Returns `1` if the byte was sent successfully, or `0` if an error occurred.
+
+
+### `write`
+
+```cpp
+virtual size_t write(const uint8_t * buf, size_t size)
+```
+
+Writes a buffer of data to the SSL connection.
+
+#### Parameters
+* `buf` is a pointer to the buffer containing the data to be sent.
+
+* `size` is the number of bytes to send from the buffer.
+
+#### Returns
+Returns `size` if the data is successfully sent, or `0` if the transmission fails or the socket is invalid.
+
+
+### `available`
+
+```cpp
+virtual int available()
+```
+
+Checks the number of bytes available for reading from the SSL connection.
+
+#### Returns
+Returns the number of bytes available to read from the SSL connection without blocking.
+
+
+### `read`
+
+```cpp
+virtual int read()
+```
+
+Reads data from the SSL connection into the receive buffer.
+
+#### Returns
+Returns the number of bytes successfully read into the buffer. Returns `0` if no data is received, or `-1` if the socket is invalid or an error occurs.
+
+
+### `read`
+
+```cpp
+virtual int read(uint8_t * buf, size_t size)
+```
+
+Reads a specified number of bytes from the SSL connection into a buffer.
+
+#### Parameters
+* `buf` is a pointer to the buffer where the read data will be stored. `size` is the maximum number of bytes to read into the buffer.
+
+#### Returns
+The number of bytes successfully read. Returns `0` if no data is available or an error occurs.
+
+
+### `peek`
+
+```cpp
+virtual int peek()
+```
+
+Peeks at the next byte available from the SSL connection without removing it.
+
+This function queries the modem to retrieve the next byte available in the SSL/TLS connection, allowing the byte to remain in the buffer for future reads.
+
+#### Returns
+The next byte available as an integer value (0–255), or `-1` if the socket is invalid or no data is available.
+
+
+### `flush`
+
+```cpp
+virtual void flush()
+```
+
+Flushes the write buffer of the SSL connection.
+
+This function clears the write buffer, ensuring that any pending data is sent over the SSL/TLS connection. It uses the modem to handle the flush operation.
+
+
+### `stop`
+
+```cpp
+virtual void stop()
+```
+
+Terminates the SSL/TLS connection and clears the receive buffer.
+
+
+
+### `connected`
+
+```cpp
+virtual uint8_t connected()
+```
+
+Checks if the SSL/TLS connection is active.
+
+This function determines if the SSL/TLS client is still connected by querying the modem for the connection status. It checks the validity of the socket before proceeding with the query.
+
+#### Returns
+Returns `1` if the client is connected, `0` otherwise.
+
+
+### `operator bool`
+
+```cpp
+inline virtual operator bool()
+```
+
+Implicit conversion operator to check if the SSL client is connected.
+
+#### Returns
+`true` if the socket is valid (i.e., connected), `false` otherwise.
+
+
+### `operator==`
+
+```cpp
+virtual bool operator==(const WiFiSSLClient &)
+```
+
+Comparison operator to check equality between two [WiFiSSLClient](#class_wi_fi_s_s_l_client) objects.
+
+#### Parameters
+* `WiFiSSLClient` object to compare.
+
+#### Returns
+`true` if both [WiFiSSLClient](#class_wi_fi_s_s_l_client) objects are equivalent (i.e., they have the same socket), `false` otherwise.
+
+
+### `operator!=`
+
+```cpp
+inline virtual bool operator!=(const WiFiSSLClient & whs)
+```
+
+Inequality operator to compare two [WiFiSSLClient](#class_wi_fi_s_s_l_client) objects.
+
+This operator compares the current [WiFiSSLClient](#class_wi_fi_s_s_l_client) object with another [WiFiSSLClient](#class_wi_fi_s_s_l_client) object to determine if they are not equal, based on their underlying socket or connection.
+
+#### Parameters
+* `whs` The [WiFiSSLClient](#class_wi_fi_s_s_l_client) object to compare with.
+
+#### Returns
+`true` if the two [WiFiSSLClient](#class_wi_fi_s_s_l_client) objects do not represent the same connection (i.e., have different sockets), `false` otherwise.
+
+
+### `remoteIP`
+
+```cpp
+virtual IPAddress remoteIP()
+```
+
+Retrieves the remote IP address of the WiFi SSL client.
+
+This function queries the modem for the remote IP address associated with the current connection.
+
+#### Returns
+The remote IP address of the client. Returns `0.0.0.0` if the socket is not valid or the query fails.
+
+
+### `remotePort`
+
+```cpp
+virtual uint16_t remotePort()
+```
+
+Retrieves the remote port number of the WiFi SSL client.
+
+This function queries the modem to obtain the remote port number associated with the current connection.
+
+#### Returns
+Returns the remote port number of the client. Returns `0` if the socket is not valid or the query fails.
+
+
+# class `WiFiUDP`
+
+```cpp
+class WiFiUDP
+ : public UDP
+```
+
+A class for handling UDP communication over a Wi-Fi network.
+
+The [WiFiUDP](#class_wi_fi_u_d_p) class is an extension of the UDP class that enables sending and receiving UDP packets over a Wi-Fi network. It provides functions for initialization, packet transmission, and reception tailored for Wi-Fi connectivity.
+
+## Summary
+
+ Members | Descriptions
+--------------------------------|---------------------------------------------
+| [`WiFiUDP`](#class_wi_fi_u_d_p_1a84c016f902e4999f74b2356d2af483ea) | Default constructor for the [WiFiUDP](#class_wi_fi_u_d_p) class. |
+| [`begin`](#class_wi_fi_u_d_p_1af48f0679da52268c8d3d74110fa56035) | Starts a UDP socket on the specified local port. |
+| [`begin`](#class_wi_fi_u_d_p_1a830cf425860621f6c71f785012b07ff6) | Starts a UDP socket bound to a specific IP address and port. |
+| [`beginMulticast`](#class_wi_fi_u_d_p_1a470bcdb3a2fffdfecf2d5945a2345789) | Starts a UDP multicast socket bound to a specific IP address and port. |
+| [`stop`](#class_wi_fi_u_d_p_1a87ee974d0e6ec204364d5e73396be9fa) | Stops the UDP socket and releases its resources. |
+| [`beginMulticastPacket`](#class_wi_fi_u_d_p_1a96258bfc994f75c2144ede2afcbc0636) | Begins constructing a multicast UDP packet for sending. |
+| [`beginPacket`](#class_wi_fi_u_d_p_1a2e51a25f349ed007b2fa7f78dca43a89) | Begins constructing a UDP packet for sending to a specific IP address and port. |
+| [`beginPacket`](#class_wi_fi_u_d_p_1a448452411940224e708b9d907d56fa74) | Begins constructing a UDP packet for sending to a specific hostname and port. |
+| [`endPacket`](#class_wi_fi_u_d_p_1ab157246011e8f79564881f68a9bd1b11) | Completes the construction of a UDP packet and sends it to the specified destination. |
+| [`write`](#class_wi_fi_u_d_p_1ab36596bdae87541922d3b2653517500b) | Sends a single byte of data to the currently opened UDP packet. |
+| [`write`](#class_wi_fi_u_d_p_1ae6a547561e192e3446f3190a429bbbd5) | Sends a buffer of data to the currently opened UDP packet. |
+| [`parsePacket`](#class_wi_fi_u_d_p_1a52641a292b2c9ea8494bc91c22bba2ac) | Start processing the next available incoming packet. |
+| [`available`](#class_wi_fi_u_d_p_1a72f5e44ece70dd7a2a96647a897951d2) | Checks if there are any available UDP packets to read. |
+| [`read`](#class_wi_fi_u_d_p_1a4474f72712418b90f2415581a4e5b9e5) | Read a single byte from the current packet. |
+| [`read`](#class_wi_fi_u_d_p_1aacde0f39adec12a6151b42a89badea02) | Reads data from the UDP receive buffer into a provided buffer. |
+| [`read`](#class_wi_fi_u_d_p_1a04e1b1de54485392307a90ae3c703529) | Reads data from the UDP receive buffer into a character buffer. |
+| [`peek`](#class_wi_fi_u_d_p_1adf9cda99b5319dd9c58a2dd50075639b) | Peeks at the next byte available in the UDP buffer without moving on to the next byte. |
+| [`flush`](#class_wi_fi_u_d_p_1acd8e5a16383d8b47c13536007ee04a71) | Finish reading the current packet. |
+| [`operator==`](#class_wi_fi_u_d_p_1a31b0064b29cee88cf5aa7eb056f2b3a8) | Compares two [WiFiUDP](#class_wi_fi_u_d_p) objects for equality. |
+| [`operator!=`](#class_wi_fi_u_d_p_1a9fc23a50af71ef9b34c73c7dee897c01) | Compares two [WiFiUDP](#class_wi_fi_u_d_p) objects for inequality. |
+| [`remoteIP`](#class_wi_fi_u_d_p_1a840ae72c440bed1c3e429f177cb41740) | Retrieves the remote IP address of the host who sent the current incoming packet. |
+| [`remotePort`](#class_wi_fi_u_d_p_1a2ebb4b0e8fc1c4c147bd5936ff7ab250) | Return the port of the host who sent the current incoming packet. |
+
+## Members
+
+### `WiFiUDP`
+
+```cpp
+WiFiUDP()
+```
+
+Default constructor for the [WiFiUDP](#class_wi_fi_u_d_p) class.
+
+
+
+### `begin`
+
+```cpp
+virtual uint8_t begin(uint16_t)
+```
+
+Starts a UDP socket on the specified local port.
+
+#### Parameters
+* `uint16_t` The local port number to bind the UDP socket to.
+
+#### Returns
+Returns `1` if the socket is successfully opened, or `0` if the socket is already in use or could not be opened.
+
+
+### `begin`
+
+```cpp
+virtual uint8_t begin(IPAddress a, uint16_t p)
+```
+
+Starts a UDP socket bound to a specific IP address and port.
+
+#### Parameters
+* `a` The local IP address to bind the UDP socket to.
+
+* `p` The local port number to bind the UDP socket to.
+
+#### Returns
+Returns `1` if the socket is successfully opened, or `0` if the socket is already in use or could not be opened.
+
+
+### `beginMulticast`
+
+```cpp
+virtual uint8_t beginMulticast(IPAddress, uint16_t)
+```
+
+Starts a UDP multicast socket bound to a specific IP address and port.
+
+#### Parameters
+* `IPAddress` The multicast IP address to bind the UDP socket to.
+
+* `uint16_t` The port number to bind the UDP socket to.
+
+#### Returns
+Returns `1` if the socket is successfully opened, or `0` if the socket is already in use or could not be opened.
+
+
+### `stop`
+
+```cpp
+virtual void stop()
+```
+
+Stops the UDP socket and releases its resources.
+
+
+
+### `beginMulticastPacket`
+
+```cpp
+virtual int beginMulticastPacket()
+```
+
+Begins constructing a multicast UDP packet for sending.
+
+#### Returns
+Returns `1` if the packet preparation is successful. Or `0` if there is an error or the socket is not initialized.
+
+
+### `beginPacket`
+
+```cpp
+virtual int beginPacket(IPAddress ip, uint16_t port)
+```
+
+Begins constructing a UDP packet for sending to a specific IP address and port.
+
+#### Parameters
+* `ip` The destination IP address as an `IPAddress` object.
+
+* `port` The destination port number.
+
+#### Returns
+Returns `1` if the packet preparation is successful. Or `0` if there is an error or the socket is not initialized.
+
+
+### `beginPacket`
+
+```cpp
+virtual int beginPacket(const char * host, uint16_t port)
+```
+
+Begins constructing a UDP packet for sending to a specific hostname and port.
+
+#### Parameters
+* `host` The destination hostname as a null-terminated string.
+
+* `port` The destination port number.
+
+#### Returns
+Returns `1` if the packet preparation is successful. Or `0` if there is an error or the socket is not initialized.
+
+
+### `endPacket`
+
+```cpp
+virtual int endPacket()
+```
+
+Completes the construction of a UDP packet and sends it to the specified destination.
+
+#### Returns
+Returns `1` if the packet is successfully transmitted. Or `0` if there is an error or the socket is not initialized.
+
+
+### `write`
+
+```cpp
+virtual size_t write(uint8_t)
+```
+
+Sends a single byte of data to the currently opened UDP packet.
+
+#### Parameters
+* `b` The byte of data to send.
+
+#### Returns
+Returns `1` if the byte was successfully written. Or `0` if there was an error or the packet was not properly initialized.
+
+
+### `write`
+
+```cpp
+virtual size_t write(const uint8_t * buffer, size_t size)
+```
+
+Sends a buffer of data to the currently opened UDP packet.
+
+#### Parameters
+* `buffer` A pointer to the buffer containing the data to send.
+
+* `size` The number of bytes from the buffer to write.
+
+#### Returns
+Returns the number of bytes successfully written if the operation is successful. Or `0` if the data was not successfully written, or if the packet was not properly initialized.
+
+
+### `parsePacket`
+
+```cpp
+virtual int parsePacket()
+```
+
+Start processing the next available incoming packet.
+
+#### Returns
+Returns the size of the incoming packet, or `0` if no packet is available.
+
+
+### `available`
+
+```cpp
+virtual int available()
+```
+
+Checks if there are any available UDP packets to read.
+
+#### Returns
+Returns the number of available bytes if packets are available, or `0` if no packets are available.
+
+
+### `read`
+
+```cpp
+virtual int read()
+```
+
+Read a single byte from the current packet.
+
+#### Returns
+Returns the number of bytes read into the buffer, or `-1` if an error occurs.
+
+
+### `read`
+
+```cpp
+virtual int read(unsigned char * buffer, size_t len)
+```
+
+Reads data from the UDP receive buffer into a provided buffer.
+
+#### Parameters
+* `buffer` A pointer to the buffer where the received data will be stored.
+
+* `size` The number of bytes to read from the UDP buffer.
+
+#### Returns
+The number of bytes successfully read into the buffer. If less than `size` bytes are read, it indicates that the buffer was exhausted early.
+
+
+### `read`
+
+```cpp
+inline virtual int read(char * buffer, size_t len)
+```
+
+Reads data from the UDP receive buffer into a character buffer.
+
+#### Parameters
+* `buffer` A pointer to the character buffer where the received data will be stored.
+
+* `len` The number of bytes to read from the UDP buffer.
+
+#### Returns
+The number of bytes successfully read into the buffer. If less than `len` bytes are read, it indicates that the buffer was exhausted early.
+
+
+### `peek`
+
+```cpp
+virtual int peek()
+```
+
+Peeks at the next byte available in the UDP buffer without moving on to the next byte.
+
+#### Returns
+The value of the next byte in the UDP buffer, or `-1` if no data is available.
+
+
+### `flush`
+
+```cpp
+virtual void flush()
+```
+
+Finish reading the current packet.
+
+
+
+### `operator==`
+
+```cpp
+virtual bool operator==(const WiFiUDP &)
+```
+
+Compares two [WiFiUDP](#class_wi_fi_u_d_p) objects for equality.
+
+This function compares two [WiFiUDP](#class_wi_fi_u_d_p) objects by checking if their associated socket values (`_sock`) are the same.
+
+#### Parameters
+* `WiFiUDP&` The [WiFiUDP](#class_wi_fi_u_d_p) object to compare with the current object.
+
+#### Returns
+`true` if the socket values are equal, `false` otherwise.
+
+
+### `operator!=`
+
+```cpp
+inline virtual bool operator!=(const WiFiUDP & whs)
+```
+
+Compares two [WiFiUDP](#class_wi_fi_u_d_p) objects for inequality.
+
+This function compares two [WiFiUDP](#class_wi_fi_u_d_p) objects by checking if their associated socket values (`_sock`) are different.
+
+#### Parameters
+* `whs` The [WiFiUDP](#class_wi_fi_u_d_p) object to compare with the current object.
+
+#### Returns
+`true` if the socket values are different, `false` otherwise.
+
+
+### `remoteIP`
+
+```cpp
+virtual IPAddress remoteIP()
+```
+
+Retrieves the remote IP address of the host who sent the current incoming packet.
+
+#### Returns
+An `IPAddress` object representing the remote IP address. If the socket is not valid or the address cannot be retrieved, it returns `IPAddress(0, 0, 0, 0).
+
+
+### `remotePort`
+
+```cpp
+virtual uint16_t remotePort()
+```
+
+Return the port of the host who sent the current incoming packet.
+
+#### Returns
+The remote port number as a `uint16_t`. If the socket is not valid or the port cannot be retrieved, it returns `0`.
+
+
diff --git a/libraries/WiFiS3/src/Modem.cpp b/libraries/WiFiS3/src/Modem.cpp
index d20b1bc7d..44303d9a3 100644
--- a/libraries/WiFiS3/src/Modem.cpp
+++ b/libraries/WiFiS3/src/Modem.cpp
@@ -289,15 +289,18 @@ ModemClass::ParseResult ModemClass::buf_read(const string &prompt, string &data_
* in case multiple parameters separated by ',' are sent, they will be present in data_res
* - if we encounter we need to wait for
* - if we encounter we need to parse the response status
- * - if we encounter '|', the next token will contain binary sized data, the current value in
+ * - if we encounter '|', the next token will contain binary sized data, the current value
* in data_res contains the length of the next token
*/
if(c == '|') { // sized read, the previous parameter is the length
- state = at_parse_state_t::Sized;
-
sized_read_size = atoi(data_res.c_str());
data_res.clear();
+ if (sized_read_size != 0) {
+ state = at_parse_state_t::Sized;
+ } else {
+ state = at_parse_state_t::Res;
+ }
} else if(c == '\r') {
state = at_parse_state_t::ResWaitLF;
} else if(c == '\n') {
diff --git a/libraries/WiFiS3/src/Modem.h b/libraries/WiFiS3/src/Modem.h
index d340dd976..566146de1 100644
--- a/libraries/WiFiS3/src/Modem.h
+++ b/libraries/WiFiS3/src/Modem.h
@@ -15,31 +15,106 @@
#define DO_NOT_CHECK_CMD "NO_CMD_CHECK"
+/**
+ * @brief A class that provides methods to interact with a modem.
+ *
+ * This class is responsible for providing an interface to communicate with
+ * a modem through serial communication. It includes methods for initialization,
+ * sending and receiving data, and handling modem configurations.
+ */
class ModemClass {
public:
+ /**
+ * @brief Constructor for the ModemClass, which initializes the modem with the specified transmit (TX) and receive (RX) pins.
+ *
+ * @param Initializes an instance of the ModemClass class with
+ * specific transmit `tx` and receive `rx` pins for communication.
+ */
ModemClass(int tx, int rx);
+
+ /**
+ * @brief Constructor for the ModemClass, which initializes the modem with the specified UART interface.
+ *
+ * @param `_serial` is a pointer to the UART object that will be used for communication with the modem.
+ */
ModemClass(UART * _serial);
+
+ /**
+ * @brief Destructor for ModemClass.
+ */
~ModemClass();
+
+ /**
+ * @brief Initializes the modem communication with a specified baud rate.
+ *
+ * @param[in] `badurate` sets the baud rate for the serial connection.
+ */
void begin(int badurate = 115200, int retry = 3);
+
+ /**
+ * @brief Ends the modem communication.
+ */
void end();
+
+
+ /**
+ * @brief Sends a formatted command string to a device and stores the response.
+ *
+ * This function formats a command string using the provided format and arguments,
+ * sends it to a device, and waits for a response, which is stored in the `str` string.
+ *
+ * @param `cmd` A string representing the command to be sent to the device.
+ * @param `str` A reference to a string that will hold the device's response.
+ * @param `fmt` A format string for constructing the command.
+ *
+ * @return `true` if the command was successfully sent and a response was received,
+ * `false` otherwise.
+ */
bool write(const std::string &cmd, std::string &str, const char * fmt, ...);
+
+ /**
+ * @brief Used to send a command to the modem without waiting for a response.
+ *
+ * @param It takes a command string `cmd`, a string `str` where the response will be stored,
+ * and a format string `fmt` along with additional arguments.
+ */
void write_nowait(const std::string &cmd, std::string &str, const char * fmt, ...);
+ /**
+ * @brief Sends binary data directly to the modem without any processing or interpretation.
+ *
+ * @param It takes a pointer to the binary `data` and the `size` of the data as arguments.
+ * Used for sending raw binary commands or data to the modem for operations that
+ * require direct communication without any additional formatting or parsing.
+ */
bool passthrough(const uint8_t *data, size_t size);
+
+ /**
+ * @brief Disables automatic trimming of results for one operation.
+ *
+ * This function disables the automatic trimming of results for one operation.
+ * After it is called, the results will not be trimmed automatically until
+ * the function is called again.
+ */
void avoid_trim_results() {
/* one shot - it works only 1 time the it is necessary to call again this
funtion */
trim_results = false;
}
+ /**
+ * @brief Enables a specific mode of reading where the size of the data
+ * to be read is considered for processing.
+ */
void read_using_size() {
// read_by_size = true; // deprecated
}
+
bool beginned;
- /* calling this function with no argument will enable debug message to be printed
+ /* Calling this function with no argument will enable debug message to be printed
on Serial
use first parameter UART *u to redirect debug output to a different serial
@@ -54,6 +129,9 @@ class ModemClass {
_debug_level = level;
}
+ /**
+ * @brief Used to disable debugging output for the modem communication.
+ */
void noDebug() {
_serial_debug = nullptr;
}
@@ -63,6 +141,11 @@ class ModemClass {
void debug(bool e) {enable_dbg = e;}
#endif
+ /**
+ * @brief Sets the timeout value for communication operations.
+ *
+ * @param Can be called with a specified timeout value in milliseconds.
+ */
void timeout(size_t timeout_ms) {_timeout = timeout_ms;}
private:
diff --git a/libraries/WiFiS3/src/StringHelpers.h b/libraries/WiFiS3/src/StringHelpers.h
index 807b2690f..f348caca0 100644
--- a/libraries/WiFiS3/src/StringHelpers.h
+++ b/libraries/WiFiS3/src/StringHelpers.h
@@ -5,16 +5,69 @@
#include
#include
+/**
+ * @brief Trims whitespace characters from the beginning of a string.
+ *
+ * @param `s` is the string from which leading whitespace characters will be removed.
+ * The function modifies this string directly.
+ */
void ltrim(std::string &s);
-// trim from end (in place)
+/**
+ * @brief Trims trailing whitespace characters from a string.
+ *
+ * @param `s` the string from which trailing whitespace characters will be removed.
+ * The function modifies this string directly.
+ */
void rtrim(std::string &s);
-// trim from both ends (in place)
+
+/**
+ * @brief Trims whitespace characters from both ends of a string.
+ *
+ * This function removes any leading and trailing whitespace characters (spaces,
+ * tabs, etc.) from the given string. It modifies the string in place, erasing
+ * whitespace from both the beginning and the end of the string.
+ *
+ * @param `s` is the string from which both leading and trailing whitespace characters
+ * will be removed. The function modifies this string directly.
+ */
void trim(std::string &s);
+/**
+ * @brief Takes a string and splits it into substrings.
+ *
+ * This function splits a string into multiple substrings, storing each substring
+ * as an element in the `res` vector. The string is split at each occurrence of
+ * the specified delimiter. Optionally, the function can trim whitespace from
+ * each token before storing it in the result vector.
+ *
+ * @param `res` is a reference to a vector of strings where the resulting tokens
+ * will be stored.
+ * @param `str` is the string to be split. This string will be modified as it is
+ * split.
+ * @param `delimiter` is the delimiter string that separates the tokens in `str`.
+ * @param `_trim` is a boolean flag indicating whether to trim whitespace from each
+ * token. If true, leading and trailing whitespace will be removed from each token. Defaults to true.
+ */
void split(std::vector &res, std::string &str, const std::string &delimiter, bool _trim = true);
+/**
+ * @brief Removes a specified substring from the beginning of a string.
+ *
+ * This function attempts to remove the first occurrence of the specified substring
+ * (`what`) from the beginning of the string (`str`). Before performing the removal,
+ * it trims leading whitespace from the string. If the substring is found at the
+ * beginning of the string, it is removed, and the function returns `true`. Otherwise the
+ * function returns `false`.
+ *
+ * @param `str` is a reference to the string from which the substring will be removed.
+ * The string is modified if the substring is removed.
+ * @param `what` is the substring to be removed from the beginning of `str`.
+ *
+ * @return `true` if the substring was found and removed from the beginning of
+ * the string, `false` otherwise.
+ */
bool removeAtBegin(std::string &str, const std::string &what);
#endif
\ No newline at end of file
diff --git a/libraries/WiFiS3/src/WiFi.cpp b/libraries/WiFiS3/src/WiFi.cpp
index 7e73b94f1..35fa33d68 100644
--- a/libraries/WiFiS3/src/WiFi.cpp
+++ b/libraries/WiFiS3/src/WiFi.cpp
@@ -1,5 +1,7 @@
#include "WiFi.h"
+#define WIFI_MAX_BSSID_STRING_LENGTH 17
+
using namespace std;
/* -------------------------------------------------------------------------- */
@@ -256,6 +258,42 @@ uint8_t* CWifi::macAddress(uint8_t* _mac) {
return _mac;
}
+/* -------------------------------------------------------------------------- */
+void CWifi::_sortAPlist(uint8_t num) {
+/* -------------------------------------------------------------------------- */
+ for(uint8_t i = 0; i < num; i++) {
+ for(uint8_t j = i+1; j < num; j++) {
+ if(access_points[j].rssi > access_points[i].rssi) {
+ CAccessPoint temp = access_points[i];
+ access_points[i] = access_points[j];
+ access_points[j] = temp;
+ }
+ }
+ }
+}
+
+static uint8_t Encr2wl_enc(string e) {
+ if (e == string("open")) {
+ return ENC_TYPE_NONE;
+ } else if (e == string("WEP")) {
+ return ENC_TYPE_WEP;
+ } else if (e == string("WPA")) {
+ return ENC_TYPE_WPA;
+ } else if (e == string("WPA2")) {
+ return ENC_TYPE_WPA2;
+ } else if (e == string("WPA+WPA2")) {
+ return ENC_TYPE_WPA2;
+ } else if (e == string("WPA2-EAP")) {
+ return ENC_TYPE_WPA2_ENTERPRISE;
+ } else if (e == string("WPA2+WPA3")) {
+ return ENC_TYPE_WPA3;
+ } else if (e == string("WPA3")) {
+ return ENC_TYPE_WPA3;
+ } else {
+ return ENC_TYPE_UNKNOWN;
+ }
+}
+
/* -------------------------------------------------------------------------- */
int8_t CWifi::scanNetworks() {
/* -------------------------------------------------------------------------- */
@@ -264,30 +302,60 @@ int8_t CWifi::scanNetworks() {
modem.avoid_trim_results();
modem.read_using_size();
- access_points.clear();
+ memset(access_points,0x00,sizeof(access_points));
+ _apsFound = 0;
string res;
-
- vector aps;
if(modem.write(string(PROMPT(_WIFISCAN)),res,CMD(_WIFISCAN))) {
+ char *startAp = (char*)res.c_str();
+ char *endAP = strstr(startAp, "\r\n");
+ for(; endAP != NULL; startAp = endAP + 2, endAP = strstr(startAp, "\r\n")) {
+ /* split the modem response in multiple lines and parse once at time.
+ * The output will be something like:
+ * SSID | BSSID | RSSI | CHANNEL | SECURITY
+ */
+ *endAP = '\0'; // Replace \r with \0
+
+ char *token[5];
+ uint8_t i = 1;
+ token[0] = startAp;
+ for(; i < 5; i++){
+ char *endToken = strstr(token[i-1], " | ");
+ if(endToken == NULL){
+ break;
+ }
+ memset(endToken, '\0', 3);
+ token[i] = endToken + 3;
+ }
+
+ if(i < 5 || strlen(token[0]) == 0 || strlen(token[0]) > WL_SSID_MAX_LENGTH ||
+ strlen(token[1]) != WIFI_MAX_BSSID_STRING_LENGTH ||
+ strlen(token[2]) == 0 || strlen(token[3]) == 0 || strlen(token[4]) == 0){
+ /* Skip the row and process the next one */
+ continue;
+ }
- split(aps, res, string("\r\n"));
- for(uint16_t i = 0; i < aps.size(); i++) {
CAccessPoint ap;
- vector tokens;
- split(tokens, aps[i], string("|"));
- if(tokens.size() >= 5) {
- ap.ssid = tokens[0];
- ap.bssid = tokens[1];
- macStr2macArray(ap.uint_bssid, ap.bssid.c_str());
- ap.rssi = tokens[2];
- ap.channel = tokens[3];
- ap.encryption_mode = tokens[4];
- access_points.push_back(ap);
+ strcpy(ap.ssid, token[0]);
+ macStr2macArray(ap.uint_bssid, token[1]);
+ ap.rssi = atoi(token[2]);
+ ap.channel = atoi(token[3]);
+ ap.encryption_mode = Encr2wl_enc(token[4]);
+
+ // insert in list
+ if( _apsFound < WIFI_MAX_SSID_COUNT ){
+ access_points[_apsFound] = ap;
+ _apsFound++;
+ _sortAPlist(_apsFound);
+ }else{
+ if (ap.rssi > access_points[WIFI_MAX_SSID_COUNT-1].rssi){
+ access_points[WIFI_MAX_SSID_COUNT-1] = ap;
+ _sortAPlist(WIFI_MAX_SSID_COUNT);
+ }
}
}
}
- return (int8_t)access_points.size();
+ return _apsFound;
}
/* -------------------------------------------------------------------------- */
@@ -329,30 +397,20 @@ IPAddress CWifi::localIP() {
/* -------------------------------------------------------------------------- */
modem.begin();
string res = "";
- int attempts = 0;
IPAddress local_IP(0,0,0,0);
- do {
- delay(100);
- if(modem.write(string(PROMPT(_MODE)),res, "%s" , CMD_READ(_MODE))) {
- if(atoi(res.c_str()) == 1) {
- if(modem.write(string(PROMPT(_IPSTA)),res, "%s%d\r\n" , CMD_WRITE(_IPSTA), IP_ADDR)) {
-
- local_IP.fromString(res.c_str());
-
- }
+ if(modem.write(string(PROMPT(_MODE)),res, "%s" , CMD_READ(_MODE))) {
+ if(atoi(res.c_str()) == 1) {
+ if(modem.write(string(PROMPT(_IPSTA)),res, "%s%d\r\n" , CMD_WRITE(_IPSTA), IP_ADDR)) {
+ local_IP.fromString(res.c_str());
}
- else if(atoi(res.c_str()) == 2) {
- if(modem.write(string(PROMPT(_IPSOFTAP)),res, CMD(_IPSOFTAP))) {
-
- local_IP.fromString(res.c_str());
- }
+ }
+ else if(atoi(res.c_str()) == 2) {
+ if(modem.write(string(PROMPT(_IPSOFTAP)),res, CMD(_IPSOFTAP))) {
+ local_IP.fromString(res.c_str());
}
}
- attempts++;
}
- while(local_IP == IPAddress(0,0,0,0) && attempts < 50);
-
return local_IP;
}
@@ -385,8 +443,8 @@ IPAddress CWifi::gatewayIP() {
/* -------------------------------------------------------------------------- */
const char* CWifi::SSID(uint8_t networkItem) {
/* -------------------------------------------------------------------------- */
- if(networkItem < access_points.size()) {
- return access_points[networkItem].ssid.c_str();
+ if(networkItem < _apsFound) {
+ return access_points[networkItem].ssid;
}
return nullptr;
}
@@ -394,42 +452,20 @@ const char* CWifi::SSID(uint8_t networkItem) {
/* -------------------------------------------------------------------------- */
int32_t CWifi::RSSI(uint8_t networkItem) {
/* -------------------------------------------------------------------------- */
- if(networkItem < access_points.size()) {
- return atoi(access_points[networkItem].rssi.c_str());
+ if(networkItem < _apsFound) {
+ return access_points[networkItem].rssi;
}
return -1000;
}
-static uint8_t Encr2wl_enc(string e) {
- if (e == string("open")) {
- return ENC_TYPE_NONE;
- } else if (e == string("WEP")) {
- return ENC_TYPE_WEP;
- } else if (e == string("WPA")) {
- return ENC_TYPE_WPA;
- } else if (e == string("WPA2")) {
- return ENC_TYPE_WPA2;
- } else if (e == string("WPA+WPA2")) {
- return ENC_TYPE_WPA2;
- } else if (e == string("WPA2-EAP")) {
- return ENC_TYPE_WPA2_ENTERPRISE;
- } else if (e == string("WPA2+WPA3")) {
- return ENC_TYPE_WPA3;
- } else if (e == string("WPA3")) {
- return ENC_TYPE_WPA3;
- } else {
- return ENC_TYPE_UNKNOWN;
- }
-}
-
/* -------------------------------------------------------------------------- */
uint8_t CWifi::encryptionType() {
/* -------------------------------------------------------------------------- */
scanNetworks();
string myssid(SSID());
- for(unsigned int i = 0; i < access_points.size(); i++) {
+ for(unsigned int i = 0; i < _apsFound; i++) {
if(myssid == access_points[i].ssid) {
- return Encr2wl_enc(access_points[i].encryption_mode);
+ return access_points[i].encryption_mode;
}
}
return ENC_TYPE_UNKNOWN;
@@ -438,8 +474,8 @@ uint8_t CWifi::encryptionType() {
/* -------------------------------------------------------------------------- */
uint8_t CWifi::encryptionType(uint8_t networkItem) {
/* -------------------------------------------------------------------------- */
- if(networkItem < access_points.size()) {
- return Encr2wl_enc(access_points[networkItem].encryption_mode);
+ if(networkItem < _apsFound) {
+ return access_points[networkItem].encryption_mode;
}
return 0;
}
@@ -447,7 +483,7 @@ uint8_t CWifi::encryptionType(uint8_t networkItem) {
/* -------------------------------------------------------------------------- */
uint8_t* CWifi::BSSID(uint8_t networkItem, uint8_t* bssid) {
/* -------------------------------------------------------------------------- */
- if(networkItem < access_points.size()) {
+ if(networkItem < _apsFound) {
for(int i = 0; i < 6; i++) {
*(bssid + i) = access_points[networkItem].uint_bssid[i];
}
@@ -459,8 +495,8 @@ uint8_t* CWifi::BSSID(uint8_t networkItem, uint8_t* bssid) {
/* -------------------------------------------------------------------------- */
uint8_t CWifi::channel(uint8_t networkItem) {
/* -------------------------------------------------------------------------- */
- if(networkItem < access_points.size()) {
- return atoi(access_points[networkItem].channel.c_str());
+ if(networkItem < _apsFound) {
+ return access_points[networkItem].channel;
}
return 0;
}
diff --git a/libraries/WiFiS3/src/WiFi.h b/libraries/WiFiS3/src/WiFi.h
index 0e2999b7c..eb7f5940f 100644
--- a/libraries/WiFiS3/src/WiFi.h
+++ b/libraries/WiFiS3/src/WiFi.h
@@ -19,24 +19,52 @@
#define WIFI_FIRMWARE_LATEST_VERSION "0.5.2"
+#ifndef WIFI_MAX_SSID_COUNT
+ #define WIFI_MAX_SSID_COUNT 10
+#endif
+
class CAccessPoint {
public:
- std::string ssid;
- std::string bssid;
+ CAccessPoint() {}
+ CAccessPoint(const CAccessPoint &obj)
+ {
+ strcpy(ssid, obj.ssid);
+ rssi = obj.rssi;
+ channel = obj.channel;
+ encryption_mode = obj.encryption_mode;
+ memcpy(uint_bssid, obj.uint_bssid, sizeof(uint_bssid));
+ }
+ CAccessPoint &operator=(const CAccessPoint &obj) {
+ strcpy(ssid, obj.ssid);
+ rssi = obj.rssi;
+ channel = obj.channel;
+ encryption_mode = obj.encryption_mode;
+ memcpy(uint_bssid, obj.uint_bssid, sizeof(uint_bssid));
+ return *this;
+ }
+ char ssid[WL_SSID_MAX_LENGTH + 1]; // +1 for null terminator
uint8_t uint_bssid[6];
- std::string rssi;
- std::string channel;
- std::string encryption_mode;
+ int rssi;
+ uint8_t channel;
+ uint8_t encryption_mode;
};
-
-
+/**
+ * @brief Class to manage Wi-Fi connectivity and operations.
+ *
+ * The CWifi class provides an interface to manage Wi-Fi operations such as connecting
+ * to networks, setting up an access point, retrieving network information, and more.
+ * It interfaces with a modem to execute commands related to Wi-Fi functionality and manages
+ * connection settings such as IP address, DNS, and other network configurations.
+ */
class CWifi {
private:
void _config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1, IPAddress dns2);
+ void _sortAPlist(uint8_t num);
unsigned long _timeout;
- std::vector access_points;
+ CAccessPoint access_points[WIFI_MAX_SSID_COUNT];
+ uint8_t _apsFound = 0;
std::string ssid;
std::string apssid;
@@ -49,10 +77,13 @@ class CWifi {
public:
+ /**
+ * @brief Default constructor for the CWifi class.
+ */
CWifi();
- /*
- * Get firmware version
+ /**
+ * @brief Get firmware version
*/
static const char* firmwareVersion();
/*
@@ -71,233 +102,366 @@ class CWifi {
int ping(const String &hostname, uint8_t ttl = 128, uint8_t count = 1);
int ping(const char* host, uint8_t ttl = 128, uint8_t count = 1);
- /*
- * Start WiFi connection for OPEN networks
- * param ssid: Pointer to the SSID string.
+ /**
+ * @brief Start WiFi connection for OPEN networks.
+ *
+ * @param `ssid` a pointer to the SSID string.
*/
int begin(const char* ssid);
-
-
/* 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).
+ * @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);
- /* connect as Access Point with a standard passphrase */
+ /**
+ * @brief Starts a Wi-Fi Access Point with the specified SSID.
+ *
+ * This function initializes a Wi-Fi Access Point (AP) with the given SSID.
+ * It defaults to an open network (no password) and uses channel 1 for the AP.
+ *
+ * @param `ssid` The SSID (network name) of the Access Point.
+ *
+ * @return `1` if the Access Point is successfully started. `0` if the Access Point initialization failed.
+ */
uint8_t beginAP(const char *ssid);
+
+ /**
+ * @brief Starts a Wi-Fi Access Point (AP) with the specified SSID and channel.
+ *
+ * This function initializes a Wi-Fi Access Point (AP) with the provided SSID
+ * and channel. It defaults to using no password (open network).
+ *
+ * @param `ssid` The SSID (name) of the Wi-Fi Access Point.
+ * @param `channel` The channel on which the Access Point will operate.
+ *
+ * @return `1` if the Access Point is successfully started. `0` if the Access Point failed to start.
+ */
uint8_t beginAP(const char *ssid, uint8_t channel);
+
+ /**
+ * @brief Starts a Wi-Fi Access Point (AP) with the specified SSID and passphrase.
+ *
+ * This function initializes a Wi-Fi Access Point (AP) using the provided SSID
+ * and passphrase, defaulting to channel 1.
+ *
+ * @param `ssid` The SSID (name) of the Wi-Fi Access Point.
+ * @param `passphrase` The passphrase for securing the Access Point. If empty, the
+ * network will be open (no password).
+ *
+ * @return `1` if the Access Point is successfully started. `0` if the Access Point failed to start.
+ */
uint8_t beginAP(const char *ssid, const char* passphrase);
+
+ /**
+ * @brief Initializes a Wi-Fi Access Point (AP) with the specified SSID, passphrase, and channel.
+ *
+ * This function configures the device as a Wi-Fi Access Point (AP) with the provided parameters.
+ * It sets the mode to AP and attempts to start the network.
+ *
+ * @param `ssid` The SSID (name) of the Wi-Fi Access Point.
+ * @param `passphrase` The passphrase for securing the Access Point. If empty, the network will be open.
+ * @param `channel` The Wi-Fi channel on which the Access Point will operate (1-14, depending on region).
+ *
+ * @return `WL_AP_LISTENING` if the Access Point is successfully started. `WL_AP_FAILED` if the Access Point failed to start.
+ */
uint8_t beginAP(const char *ssid, const char* passphrase, uint8_t channel);
- /* Change IP configuration settings disabling the DHCP client
- *
- * param local_ip: Static IP configuration
- */
+ /**
+ * @brief Change IP configuration settings disabling the DHCP client
+ *
+ * @param `local_ip` The static IP address to assign to the device.
+ */
void config(IPAddress 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
- */
+ /**
+ * @brief Configures the network settings for the Wi-Fi connection with a specified DNS server.
+ *
+ * Sets the device's IP configuration using the specified local IP address and DNS server.
+ * The gateway and subnet mask are set to default values based on the provided local IP.
+ *
+ * @param `local_ip` The static IP address to assign to the device.
+ * @param `dns_server` The primary DNS server to use for domain name resolution.
+ */
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
- */
+ /**
+ * @brief Configures the network settings for the Wi-Fi connection with a specified gateway and DNS server.
+ *
+ *
+ * @param `local_ip` The static IP address to assign to the device.
+ * @param `dns_server` The primary DNS server to use for domain name resolution.
+ * @param `gateway` The Static gateway used for 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
- */
+ /**
+ * @brief Configures the network settings for the Wi-Fi connection with a specified subnet mask, gateway, and DNS server.
+ *
+ *
+ * @param `local_ip` The static IP address to assign to the device.
+ * @param `dns_server` The primary DNS server to use for domain name resolution.
+ * @param `gateway` The static gateway used for configuration.
+ * @param `subnet` The static subnet mask to use for the network.
+ */
void config(IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet);
- /* Change DNS IP configuration
+ /**
+ * @brief Sets the primary DNS server for the Wi-Fi connection.
*
- * param dns_server1: IP configuration for DNS server 1
+ * @param `dns_server1` The primary DNS server to use for domain name resolution.
*/
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
+ /**
+ * @brief Sets the primary and secondary DNS servers for the Wi-Fi connection.
*
+ * @param `dns_server1` sets the IP configuration for DNS server 1
+ * @param `dns_server2` sets the IP configuration for DNS server 2
*/
void setDNS(IPAddress dns_server1, IPAddress dns_server2);
-
- /* Set the hostname used for DHCP requests
- *
- * param name: hostname to set
+ /**
+ * @brief Sets the hostname for for DHCP requests.
*
+ * @param `name` sets the hostname.
*/
void setHostname(const char* name);
- /*
- * Disconnect from the network
+ /**
+ * @brief Disconnects from the current Wi-Fi network.
*
- * return: one value of wl_status_t enum
+ * @return `1` if the disconnection was successful, `0` otherwise.
*/
int disconnect(void);
+ /**
+ * @brief Resets and disables the Wi-Fi module.
+ */
void end(void);
- /*
- * Get the interface MAC address.
- *
- * return: pointer to uint8_t array with length WL_MAC_ADDR_LENGTH
- *
- * the value returned by this function is meaningfull only if called
- * afert a begin (both begin or beginAP) or a ScanNetwork function
- * otherwise an empty mac address is returned
+ /**
+ * @brief Retrieves the MAC address of the device.
+ *
+ * This function retrieves the MAC address of the device based on its current operating mode.
+ * The value returned by this function is meaningfull only if called afert a
+ * begin (both begin or beginAP) or a ScanNetwork function otherwise
+ * an empty mac address is returned.
+ *
+ * @param `_mac` A pointer to a uint8_t array where the MAC address will be stored.
+ *
+ * @return uint8_t* The pointer to the array with length WL_MAC_ADDR_LENGTH.
*/
uint8_t* macAddress(uint8_t* mac);
- /*
- * Get the interface IP address.
- *
- * return: IP address value
+ /**
+ * @brief Retrieves the local IP address of the device.
+ *
+ * This function retrieves the local IP address of the device. It checks the current mode (station or soft AP)
+ * and retrieves the appropriate IP address based on the mode.
+ *
+ * @return `IPAddress` The local IP address of the device.
*/
IPAddress localIP();
- /*
- * Get the interface subnet mask address.
- *
- * return: subnet mask address value
+ /**
+ * @brief Retrieves the subnet mask of the device.
+ *
+ * This function retrieves the subnet mask of the device by querying the modem for the subnet information.
+ * It sends a command to the modem to fetch the subnet mask and returns it as an `IPAddress` object.
+ *
+ * @return `IPAddress` The subnet mask address value of the device.
*/
IPAddress subnetMask();
- /*
- * Get the gateway IP address.
- *
- * return: gateway IP address value
- */
- IPAddress gatewayIP();
-
- IPAddress dnsIP(int n = 0);
-
- /*
- * Get the interface the AP IP address.
- *
- * return: IP address value
+ /**
+ * @brief Retrieves the gateway IP address of the device.
+ *
+ * This function retrieves the gateway IP address of the device by querying the modem for the gateway
+ * information. It sends a command to the modem to fetch the gateway IP address and returns it as an
+ * `IPAddress` object.
+ *
+ * @return `IPAddress` The gateway IP address value of the device.
+ */
+ IPAddress gatewayIP();
+
+ /**
+ * @brief Retrieves the DNS IP address.
+ *
+ * @param `n` The index of the DNS server to retrieve, `0` for the primary DNS server
+ * and `1` for the secondary DNS server.
+ *
+ * @return `IPAddress` The DNS IP address as an `IPAddress` object, or `0.0.0.0` if not found.
+ */
+ IPAddress dnsIP(int n = 0);
+
+ /**
+ * @brief Retrieves the IP address of the soft access point (AP).
+ *
+ * @return `IPAddress` The IP address of the soft AP as an `IPAddress` object, or `0.0.0.0` if not found.
*/
IPAddress softAPIP();
- /*
- * Return the current SSID associated with the network
- *
- * return: ssid string
+ /**
+ * @brief Retrieves the SSID of the current Wi-Fi connection or SoftAP.
+ *
+ * @return The SSID of the current Wi-Fi connection or SoftAP as a string.
+ * If unable to retrieve the SSID, returns an empty string.
*/
const char* SSID();
- /*
- * Return the current BSSID associated with the network.
- *
- * return: pointer to uint8_t array with length WL_MAC_ADDR_LENGTH
- */
+ /**
+ * @brief Retrieves the BSSID (MAC address) of the currently connected Wi-Fi network.
+ *
+ * @param `bssid` A pointer to an array where the BSSID will be stored. The array must be large enough to hold the MAC address.
+ *
+ * @return A pointer to the `bssid` array containing the retrieved BSSID. If the BSSID cannot be retrieved, returns `nullptr`.
+ */
uint8_t* BSSID(uint8_t* bssid);
- /*
- * Return the current RSSI/Received Signal Strength in dBm)
- * associated with the network
- *
- * return: signed value
- */
+ /**
+ * @brief Retrieves the RSSI (Received Signal Strength Indicator) of the currently connected Wi-Fi network.
+ *
+ * @return The RSSI value representing the signal strength. A higher (less negative) value indicates a stronger signal.
+ * If the RSSI cannot be retrieved, returns 0.
+ */
int32_t RSSI();
- /*
- * Return the current SSID associated with to the soft AP
- *
- * return: ssid string
+ /**
+ * @brief Retrieves the SSID (Service Set Identifier) of the SoftAP (Software Access Point) mode.
+ *
+ * @return The SSID of the SoftAP. If the SSID cannot be retrieved, an empty string is returned.
*/
const char* softAPSSID();
-
- /*
- * Start scan WiFi networks available
- *
- * return: Number of discovered networks
+ /**
+ * @brief Scans for available Wi-Fi networks and stores the information in the `access_points` list.
+ *
+ * This function initiates a scan for nearby Wi-Fi networks and retrieves details such as SSID, BSSID,
+ * RSSI (signal strength), channel, and encryption mode for each detected access point.
+ *
+ * @return The number of networks found during the scan. Returns a negative value in case of an error.
*/
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
+ /**
+ * @brief Retrieves the SSID of a specific Wi-Fi network from the scan results.
+ *
+ * @param `networkItem` The index of the network in the list of scanned access points.
+ *
+ * @return The SSID of the specified network, or `nullptr` if the index is out of bounds.
*/
const 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
-
-
-
+ /**
+ * @brief Returns the encryption type for a specified network.
+ *
+ * This function retrieves the encryption type of a specific Wi-Fi access point
+ * based on its index in the list of scanned networks.
+ *
+ * @param `networkItem` The index of the network in the list of available access points.
+ *
+ * @return The encryption type in numeric form (e.g., 0 for no encryption,
+ * 1 for WEP, 2 for WPA, etc.). Returns 0 if the network item index is invalid.
*/
uint8_t encryptionType(uint8_t networkItem);
+
+ /**
+ * @brief Returns the encryption type of the currently connected Wi-Fi network.
+ *
+ * @return The encryption type in numeric form (e.g., 0 for no encryption, 1 for WEP, 2 for WPA, etc.).
+ * Returns `ENC_TYPE_UNKNOWN` if the encryption type cannot be determined.
+ */
uint8_t encryptionType();
+ /**
+ * @brief Retrieves the BSSID of a specific Wi-Fi network.
+ *
+ * This function retrieves the BSSID (MAC address) of the Wi-Fi network at the specified
+ * index from the list of available networks. The BSSID is stored in the provided
+ * array of 6 bytes.
+ *
+ * @param `networkItem` The index of the Wi-Fi network in the list of available networks.
+ * @param `bssid` A pointer to a byte array (of size 6) where the BSSID will be stored.
+ *
+ * @return A pointer to the `bssid` array if the BSSID is successfully retrieved,
+ * or `nullptr` if the network index is out of range.
+ */
uint8_t* BSSID(uint8_t networkItem, uint8_t* bssid);
+
+ /**
+ * @brief Retrieves the channel number of a specific Wi-Fi network.
+ *
+ * @param `networkItem` The index of the Wi-Fi network in the list of available networks.
+ *
+ * @return The channel number of the specified network, or `0` if the network index
+ * is out of range.
+ */
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
+ /**
+ * @brief Retrieves the RSSI (Received Signal Strength Indicator) of the networks discovered during the scanNetworks.
+ *
+ * @param `networkItem` The index of the Wi-Fi network in the list of available networks.
+ *
+ * @return The RSSI value of the specified network in dBm, or `-1000` if the network index
+ * is out of range.
*/
int32_t RSSI(uint8_t networkItem);
- /*
- * Return Connection status.
- *
- * return: one of the value defined in wl_status_t
+ /**
+ * @brief Retrieves the current connection status of the Wi-Fi connection.
+ *
+ * @return One of the values defined in wl_status_t
*/
uint8_t status();
- /*
- * Return The deauthentication reason code.
+ /**
+ * @brief Retrieves The deauthentication reason code.
*
- * return: the deauthentication reason code
+ * @return The deauthentication reason code.
*/
uint8_t reasonCode();
- /*
- * Resolve the given hostname to an IP address.
- * param aHostname: Name to be resolved
- * param aResult: IPAddress structure to store the returned IP address
- * result: 1 if aIPAddrString was successfully converted to an IP address,
- * else error code
+ /**
+ * @brief Resolves a hostname to an IP address.
+ *
+ * @param `aHostname` The hostname to resolve (e.g., "www.example.com").
+ * @param `aResult` IPAddress structure to store the returned IP address result:
+ * 1 if aIPAddrString was successfully converted to an IP address, else error code
+ *
+ * @return Returns `1` if the hostname was successfully resolved, `0` otherwise.
*/
int hostByName(const char* aHostname, IPAddress& aResult);
+ /**
+ * @brief Retrieves the current time from the modem.
+ *
+ * @return The current time value in seconds, or `0` if the time could not be retrieved.
+ */
unsigned long getTime();
+ /**
+ * @brief Sets the timeout value for the WiFi connection.
+ *
+ * @param `timeout` The timeout value in milliseconds.
+ */
void setTimeout(unsigned long timeout);
};
+/**
+ * @brief Global instance of the CWifi class.
+ *
+ * This external declaration provides access to a global instance of the `CWifi` class, which
+ * facilitates interaction with the WiFi module.
+ */
extern CWifi WiFi;
diff --git a/libraries/WiFiS3/src/WiFiClient.h b/libraries/WiFiS3/src/WiFiClient.h
index e670b594f..32803a746 100644
--- a/libraries/WiFiS3/src/WiFiClient.h
+++ b/libraries/WiFiS3/src/WiFiClient.h
@@ -30,42 +30,220 @@
#include "FifoBuffer.h"
#include
+
+/**
+ * @brief Represents a Wi-Fi client that connects to a remote server over a Wi-Fi network.
+ *
+ * The WiFiClient class allows for network communication over Wi-Fi, providing methods
+ * for establishing connections, sending and receiving data, and managing the client’s
+ * socket state. This class is used to manage client connections in a Wi-Fi network,
+ * either for communication or for network data transfer.
+ *
+ * It inherits from the Client class, providing basic socket communication functionality.
+ */
class WiFiClient : public Client {
public:
+ /**
+ * @brief Default constructor for the WiFiClient class.
+ */
WiFiClient();
+
/* this constructor is not intended to be called outside of the Server class */
+ /**
+ * @brief Constructor to initialize a WiFiClient object with a specific socket.
+ *
+ * @param `s` is the socket descriptor to associate with this client.
+ */
WiFiClient(int s);
+
+ /**
+ * @brief Copy constructor for the WiFiClient class.
+ *
+ * @param `c` is the `WiFiClient` object to copy.
+ */
WiFiClient(const WiFiClient& c);
+
+ /**
+ * @brief Destructor for the WiFiClient class.
+ */
~WiFiClient();
+
+ /**
+ * @brief Establishes a connection to a server using an IP address and port.
+ *
+ * @param `ip` as the IP address of the server to connect to.
+ * @param `port` as the port number on the server to connect to.
+ *
+ * @return `1` on a successful connection, `0` on failure.
+ */
virtual int connect(IPAddress ip, uint16_t port);
+
+ /**
+ * @brief Establishes a connection to a server using a hostname and port.
+ *
+ * @param `host` is a pointer to a null-terminated string containing the hostname of the server.
+ * @param `port` is the port number on the server to connect to.
+ *
+ * @return `1` if the connection was successful, `0` otherwise.
+ */
virtual int connect(const char *host, uint16_t port);
+
+ /**
+ * @brief Sends a single byte of data to the connected server.
+ *
+ * @param `b` being the byte of data to send.
+ *
+ * @return The number of bytes successfully written, which is `1` on success or `0` on failure.
+ */
virtual size_t write(uint8_t);
+
+ /**
+ * @brief Writes a buffer of data to the connected server.
+ *
+ * @param Takes a pointer to a buffer `buf` containing the data to be written
+ * and the size of the buffer `size` as parameters.
+ *
+ * @return The number of bytes successfully written, or `0` if the write operation fails.
+ */
virtual size_t write(const uint8_t *buf, size_t size);
+
+ /**
+ * @brief Checks the number of bytes available for reading from the server.
+ *
+ * @return The number of bytes available to read. Returns `0` if no data is
+ * available, or if the socket is invalid.
+ */
virtual int available();
+
+ /**
+ * @brief Reads a single byte of data from the server.
+ *
+ * @return The byte read as an `int` (0–255). Returns `-1` if no data is available
+ * or if an error occurs.
+ */
virtual int read();
+
+ /**
+ * @brief Reads multiple bytes of data from the server into a buffer.
+ *
+ * This function retrieves data from the server's receive buffer and stores it
+ * into the provided array. It attempts to read up to the specified number of
+ * bytes (`size`).
+ *
+ * @param[out] `buf` is a pointer to the buffer where the data will be stored.
+ * @param[in] `size` is the maximum number of bytes to read.
+ *
+ * @return The number of bytes successfully read into the buffer.
+ * Returns `0` if no data is available or if the socket is invalid.
+ */
virtual int read(uint8_t *buf, size_t size);
+
+ /**
+ * @brief Peeks at the next byte of incoming data without removing it from the internal buffer.
+ *
+ * @return The next byte as an `int` (0–255). Returns `-1` if no data is available
+ * or if the socket is invalid.
+ */
virtual int peek();
+
+ /**
+ * @brief Flushes the write buffer of the client.
+ *
+ * This function ensures that any data buffered for transmission is sent to the
+ * connected server. If there is any pending data in the send buffer, it is
+ * transmitted over the network.
+ */
virtual void flush();
+
+ /**
+ * @brief Closes the connection to the server and clears the receive buffer.
+ */
virtual void stop();
+
+ /**
+ * @brief Checks if the client is connected to a server.
+ *
+ * @return Returns 1 if the client is connected, 0 otherwise.
+ */
virtual uint8_t connected();
+
+ /**
+ * @brief Implicit conversion operator to `bool`.
+ *
+ * Converts the `WiFiClient` object to a `bool` value indicating whether the client
+ * is connected or not.
+ *
+ * @return `true` if the client socket is open and valid, `false` otherwise.
+ */
virtual operator bool() {
return _sock != -1;
}
+
+ /**
+ * @brief Equality operator for comparing two `WiFiClient` objects.
+ *
+ * Compares the current `WiFiClient` object with another `WiFiClient` object
+ * to determine if they represent the same socket connection.
+ *
+ * @param The `WiFiClient` object to compare with.
+ * @return `true` if both `WiFiClient` objects represent the same socket,
+ * `false` otherwise.
+ */
virtual bool operator==(const WiFiClient&);
+
+ /**
+ * @brief Inequality operator for comparing two `WiFiClient` objects.
+ *
+ * Compares the current `WiFiClient` object with another `WiFiClient` object
+ * to determine if they represent different socket connections.
+ *
+ * @param `whs` is the `WiFiClient` object to compare with.
+ * @return `true` if both WiFiClient objects represent different sockets,
+ * `false` if they represent the same socket.
+ */
virtual bool operator!=(const WiFiClient& whs)
{
return !this->operator==(whs);
};
+
+ /**
+ * @brief Retrieves the remote IP address of the server the client is connected to.
+ *
+ * @return The IP address of the remote server. If not connected, returns IPAddress(0, 0, 0, 0).
+ */
virtual IPAddress remoteIP();
+
+ /**
+ * @brief Retrieves the remote port number of the server the client is connected to.
+ *
+ * @return Returns the port number of the remote server. If not connected, returns 0.
+ */
virtual uint16_t remotePort();
+ /**
+ * @brief Sets the connection timeout for the client.
+ *
+ * @param `timeout` is the timeout value in milliseconds.
+ */
void setConnectionTimeout(int timeout) {
_connectionTimeout = timeout;
}
+ /**
+ * @brief Declares WiFiServer as a friend class.
+ *
+ * This allows the WiFiServer class to access private and protected members
+ * of the WiFiClient class.
+ */
friend class WiFiServer;
+ /**
+ * @brief Inherits the `write` method from the `Print` class.
+ *
+ * This allows the WiFiSSLClient class to use the `write` method defined in the
+ * `Print` class.
+ */
using Print::write;
protected:
diff --git a/libraries/WiFiS3/src/WiFiFileSystem.h b/libraries/WiFiS3/src/WiFiFileSystem.h
index 3f92425c2..e03157654 100644
--- a/libraries/WiFiS3/src/WiFiFileSystem.h
+++ b/libraries/WiFiS3/src/WiFiFileSystem.h
@@ -24,12 +24,49 @@
#include "WiFiCommands.h"
#include "Modem.h"
+/**
+ * @brief Class that handles the WiFi file system operations.
+ *
+ * This class provides functionality for managing files on a WiFi-connected
+ * device, including mounting, reading, writing, and configuring the file system.
+ */
class WiFiFileSystem {
public:
+ /**
+ * @brief Initializes objects of the WiFiFileSystem class.
+ */
WiFiFileSystem();
+
+ /**
+ * @brief Mounts the file system and optionally formats it on failure.
+ *
+ * @param If `format_on_fault` is set to `true`,
+ * the file system will be formatted if a fault occurs during mounting.
+ */
void mount(bool format_on_fault = false);
+
+ /**
+ * @brief Writes data to a file in the file system.
+ *
+ * @param `name` is the name of the file to which the data will be written.
+ * A pointer `data` to the data that will be written to the file.
+ * `size` is the number of bytes to write from the provided data buffer.
+ * `operation` determines the type of file operation to perform (e.g., create, overwrite).
+ *
+ * @return Returns the number of bytes successfully written. Returns 0 if the operation fails.
+ */
size_t writefile(const char* name, const char* data, size_t size, int operation = WIFI_FILE_WRITE);
+
+ /**
+ * @brief Reads a file from the file system and prints its content.
+ *
+ * It sends the read request to the modem, which fetches the data. The content
+ * is printed to the serial output in chunks, with each chunk being processed
+ * until the entire file is read.
+ *
+ * @param `name` is the name of the file to be read from the file system.
+ */
void readfile(const char* name);
};
diff --git a/libraries/WiFiS3/src/WiFiSSLClient.h b/libraries/WiFiS3/src/WiFiSSLClient.h
index 6bdbf9687..2642c3d42 100644
--- a/libraries/WiFiS3/src/WiFiSSLClient.h
+++ b/libraries/WiFiS3/src/WiFiSSLClient.h
@@ -25,38 +25,215 @@
#include "Modem.h"
#include "WiFiFileSystem.h"
-
+/**
+ * @brief A specialized client class for secure SSL/TLS connections.
+ *
+ * The WiFiSSLClient class extends the functionality of the WiFiClient class to provide secure
+ * communication over SSL/TLS protocols. It ensures encrypted and authenticated communication
+ * between the client and a remote server.
+ */
class WiFiSSLClient : public WiFiClient {
public:
+ /**
+ * @brief Initializes objects of the WiFiSSLClient class.
+ */
WiFiSSLClient();
~WiFiSSLClient();
+
+ /**
+ * @brief Establishes a secure SSL connection to a specified IP address and port.
+ *
+ * @param It takes an `IPAddress` object representing the IP address of the server
+ * and a `uint16_t` port number as parameters.
+ *
+ * @return Returns a status code indicating the success or failure of the
+ * connection.
+ */
virtual int connect(IPAddress ip, uint16_t port);
+
+ /**
+ * @brief Establishes a secure SSL connection to a specified host and port.
+ *
+ * @param `host` is the hostname or IP address of the server to connect to.
+ * `port` is the port number to connect to.
+ *
+ * @return Returns `1` if the connection is successfully established, `0` otherwise.
+ */
virtual int connect(const char* host, uint16_t port);
+
+ /**
+ * @brief Sets the Certificate Authority (CA) for SSL/TLS verification.
+ *
+ * @param `root_ca` is a pointer to a null-terminated string containing the root
+ * CA certificate in PEM format. If set to `nullptr`, the default root
+ * CA bundle will be used.
+ */
void setCACert(const char* root_ca);
+
+ /**
+ * @brief Sets the ECC (Elliptic Curve Cryptography) key slot and
+ * certificate for establishing secure SSL connections.
+ *
+ * @param `int ecc508KeySlot` specifies the ECC key slot to be used for the SSL connection.
+ * @param `const byte cert[]` is a pointer to the certificate data in the form of an array of bytes.
+ * @param `int certLength` specifies the length of the certificate data array.
+ */
void setEccSlot(int ecc508KeySlot, const byte cert[], int certLength);
+
+ /**
+ * @brief Writes a single byte of data to the SSL connection.
+ *
+ * @param `b` is the byte to be sent.
+ *
+ * @return The number of bytes successfully written. Returns `1` if the byte
+ * was sent successfully, or `0` if an error occurred.
+ */
virtual size_t write(uint8_t);
+
+ /**
+ * @brief Writes a buffer of data to the SSL connection.
+ *
+ * @param `buf` is a pointer to the buffer containing the data to be sent.
+ * @param `size` is the number of bytes to send from the buffer.
+ *
+ * @return Returns `size` if the data is successfully sent,
+ * or `0` if the transmission fails or the socket is invalid.
+ */
virtual size_t write(const uint8_t *buf, size_t size);
+
+ /**
+ * @brief Checks the number of bytes available for reading from the SSL connection.
+ *
+ * @return Returns the number of bytes available to read from the SSL connection without blocking.
+ */
virtual int available();
+
+ /**
+ * @brief Reads data from the SSL connection into the receive buffer.
+ *
+ * @return Returns the number of bytes successfully read into the buffer. Returns
+ * `0` if no data is received, or `-1` if the socket is invalid or an error occurs.
+ */
virtual int read();
+
+ /**
+ * @brief Reads a specified number of bytes from the SSL connection into a buffer.
+ *
+ * @param `buf` is a pointer to the buffer where the read data will be stored.
+ * `size` is the maximum number of bytes to read into the buffer.
+ *
+ * @return The number of bytes successfully read. Returns `0` if no data is
+ * available or an error occurs.
+ */
virtual int read(uint8_t *buf, size_t size);
+
+ /**
+ * @brief Peeks at the next byte available from the SSL connection without removing it.
+ *
+ * This function queries the modem to retrieve the next byte available in the
+ * SSL/TLS connection, allowing the byte to remain in the buffer for future reads.
+ *
+ * @return The next byte available as an integer value (0–255), or `-1` if
+ * the socket is invalid or no data is available.
+ */
virtual int peek();
+
+ /**
+ * @brief Flushes the write buffer of the SSL connection.
+ *
+ * This function clears the write buffer, ensuring that any pending data is sent
+ * over the SSL/TLS connection. It uses the modem to handle the flush operation.
+ */
virtual void flush();
+
+ /**
+ * @brief Terminates the SSL/TLS connection and clears the receive buffer.
+ */
virtual void stop();
+
+ /**
+ * @brief Checks if the SSL/TLS connection is active.
+ *
+ * This function determines if the SSL/TLS client is still connected by querying
+ * the modem for the connection status. It checks the validity of the socket
+ * before proceeding with the query.
+ *
+ * @return Returns `1` if the client is connected, `0` otherwise.
+ */
virtual uint8_t connected();
+
+ /**
+ * @brief Implicit conversion operator to check if the SSL client is connected.
+ *
+ * @return `true` if the socket is valid (i.e., connected), `false` otherwise.
+ */
virtual operator bool() {
return _sock != -1;
}
+
+ /**
+ * @brief Comparison operator to check equality between two `WiFiSSLClient` objects.
+ *
+ * @param `WiFiSSLClient` object to compare.
+ *
+ * @return `true` if both WiFiSSLClient objects are equivalent (i.e., they have the same socket),
+ * `false` otherwise.
+ */
virtual bool operator==(const WiFiSSLClient&);
+
+ /**
+ * @brief Inequality operator to compare two `WiFiSSLClient` objects.
+ *
+ * This operator compares the current `WiFiSSLClient` object with another `WiFiSSLClient` object
+ * to determine if they are not equal, based on their underlying socket or connection.
+ *
+ * @param `whs` The WiFiSSLClient object to compare with.
+ * @return `true` if the two WiFiSSLClient objects do not represent the same connection (i.e., have different sockets),
+ * `false` otherwise.
+ */
virtual bool operator!=(const WiFiSSLClient& whs)
{
return !this->operator==(whs);
};
+
+ /**
+ * @brief Retrieves the remote IP address of the WiFi SSL client.
+ *
+ * This function queries the modem for the remote IP address associated with
+ * the current connection.
+ *
+ * @return The remote IP address of the client. Returns `0.0.0.0` if the
+ * socket is not valid or the query fails.
+ */
virtual IPAddress remoteIP();
+
+ /**
+ * @brief Retrieves the remote port number of the WiFi SSL client.
+ *
+ * This function queries the modem to obtain the remote port number associated
+ * with the current connection.
+ *
+ * @return Returns the remote port number of the client. Returns `0` if the socket
+ * is not valid or the query fails.
+ */
virtual uint16_t remotePort();
+
+ /**
+ * @brief Declares WiFiServer as a friend class.
+ *
+ * This allows the WiFiServer class to access private and protected members
+ * of the WiFiSSLClient class.
+ */
friend class WiFiServer;
+ /**
+ * @brief Inherits the `write` method from the Print class.
+ *
+ * This allows the WiFiSSLClient class to use the `write` method defined in the
+ * Print class.
+ */
using Print::write;
private:
diff --git a/libraries/WiFiS3/src/WiFiServer.h b/libraries/WiFiS3/src/WiFiServer.h
index eb749330b..fe212a246 100644
--- a/libraries/WiFiS3/src/WiFiServer.h
+++ b/libraries/WiFiS3/src/WiFiServer.h
@@ -26,7 +26,14 @@
#include "WiFiClient.h"
-
+/**
+ * @brief A class that provides server functionality for WiFi-based communication.
+ *
+ * The WiFiServer class inherits from the Server class and extends its functionality
+ * to create and manage a server over a WiFi connection. This class allows for accepting
+ * incoming client connections, handling data communication, and closing connections
+ * in a networked environment.
+ */
class WiFiServer : public Server {
private:
int _sock;
@@ -34,24 +41,133 @@ class WiFiServer : public Server {
WiFiClient client;
public:
+ /**
+ * @brief Initializes objects of the WiFiServer class.
+ */
WiFiServer();
+
+ /**
+ * @brief Constructs a WiFiServer object with the specified port.
+ *
+ * @param `p` The port number on which the server will listen for incoming connections.
+ */
WiFiServer(int p);
+
+ /**
+ * @brief Checks if there are any incoming client connections waiting to be accepted.
+ *
+ * This function queries the server to check if there is a client waiting to be
+ * accepted. If a client is available, it returns a `WiFiClient` object representing
+ * the client. It uses the modem to query the server for an available client
+ * socket and accepts the connection if a valid client is found.
+ *
+ * @return Returns a WiFiClient object representing the next client connection that is available
+ * for processing.
+ */
WiFiClient available();
+
+ /**
+ * @brief Accepts an incoming client connection on the server.
+ *
+ * @return Returns a WiFiClient object representing the accepted client.
+ */
WiFiClient accept();
+
+ /**
+ * @brief Starts the Wi-Fi server and binds it to the specified port.
+ *
+ * @param `port` is the port number which the server will listen to for incoming connections.
+ */
void begin(int port);
+
+ /**
+ * @brief Starts the Wi-Fi server and binds it to the default port.
+ *
+ * This function initializes the server and binds it to a default port.
+ */
void begin();
+
+ /**
+ * @brief Writes a single byte to all connected clients.
+ *
+ * @param `b` is the byte to be sent to the clients.
+ */
virtual size_t write(uint8_t);
+
+ /**
+ * @brief Writes data to all connected clients.
+ *
+ * This function sends a buffer of data to all clients connected to the server.
+ * It writes the specified number of bytes to the server
+ * socket and returns the count of successfully written bytes.
+ *
+ * @param `buf` is a pointer to the buffer containing the data to be sent.
+ * `size` is the number of bytes to write from the buffer.
+ *
+ * @return The number of bytes successfully written. Returns 0 if the
+ * data could not be sent.
+ */
virtual size_t write(const uint8_t *buf, size_t size);
+
+ /**
+ * @brief Ends the Wi-Fi server and closes the server socket.
+ *
+ * This function terminates the server by sending a command to the modem to
+ * close the server socket. It sets the server socket variable to an invalid
+ * state (`-1`) to indicate that the server is no longer active.
+ *
+ */
void end();
+
+ /**
+ * @brief Converts the WiFiSSLClient object to a boolean value.
+ *
+ * This operator allows a WiFiSSLClient object to be implicitly or explicitly
+ * converted to a boolean. It checks whether the client socket is valid (i.e.,
+ * `_sock != -1`).
+ *
+ * @return `true` if the server socket is valid (server is running), `false` otherwise.
+ */
explicit operator bool();
+
+ /**
+ * @brief Compares two WiFiServer objects for equality.
+ *
+ * This virtual operator compares the underlying socket (`_sock`) of two `WiFiServer`
+ * objects to determine if they refer to the same server connection.
+ *
+ * @param WiFiServer object to compare against.
+ *
+ * @return `true` if both WiFiServer objects have the same socket; `false` otherwise.
+ */
virtual bool operator==(const WiFiServer&);
+
+ /**
+ * @brief Compares two WiFiServer objects for inequality.
+ *
+ * This virtual operator compares the underlying socket (`_sock`) of two WiFiServer
+ * objects. It returns `true` if the objects do not refer to the same server connection
+ * (i.e., they have different socket values), and `false` otherwise.
+ *
+ * @param `whs` The WiFiServer object to compare against.
+ * @return `true` if the WiFiServer objects have different sockets; `false` otherwise.
+ */
virtual bool operator!=(const WiFiServer& whs)
{
return !this->operator==(whs);
};
+ /**
+ * @brief Inherits the `write` method from the `Print` class.
+ *
+ * This allows the WiFiSSLClient class to use the `write` method defined in the
+ * `Print` class.
+ */
using Print::write;
+ /**
+ * @brief Grants WiFiClient class access to private and protected members of WiFiServer.
+ */
friend class WiFiClient;
};
diff --git a/libraries/WiFiS3/src/WiFiUdp.h b/libraries/WiFiS3/src/WiFiUdp.h
index a6d7c6026..d042efea1 100644
--- a/libraries/WiFiS3/src/WiFiUdp.h
+++ b/libraries/WiFiS3/src/WiFiUdp.h
@@ -30,6 +30,13 @@
#include "Modem.h"
#include "FifoBuffer.h"
+/**
+ * @brief A class for handling UDP communication over a Wi-Fi network.
+ *
+ * The WiFiUDP class is an extension of the UDP class that enables sending and receiving UDP packets
+ * over a Wi-Fi network. It provides functions for initialization, packet transmission, and reception
+ * tailored for Wi-Fi connectivity.
+ */
class WiFiUDP : public UDP {
private:
int _sock;
@@ -41,57 +48,212 @@ class WiFiUDP : public UDP {
virtual void read_if_needed(size_t s);
public:
- WiFiUDP(); // Constructor
- virtual uint8_t begin(uint16_t); // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use
+ /**
+ * @brief Default constructor for the WiFiUDP class.
+ */
+ WiFiUDP();
+
+ /**
+ * @brief Starts a UDP socket on the specified local port.
+ *
+ * @param `uint16_t` The local port number to bind the UDP socket to.
+ *
+ * @return Returns `1` if the socket is successfully opened, or
+ * `0` if the socket is already in use or could not be opened.
+ */
+ virtual uint8_t begin(uint16_t);
+
+ /**
+ * @brief Starts a UDP socket bound to a specific IP address and port.
+ *
+ * @param `a` The local IP address to bind the UDP socket to.
+ * @param `p` The local port number to bind the UDP socket to.
+ *
+ * @return Returns `1` if the socket is successfully opened, or
+ * `0` if the socket is already in use or could not be opened.
+ */
virtual uint8_t begin(IPAddress a, uint16_t p);
- virtual uint8_t beginMulticast(IPAddress, uint16_t); // initialize, start listening on specified multicast IP address and port. Returns 1 if successful, 0 if there are no sockets available to use
- virtual void stop(); // Finish with the UDP socket
+
+ /**
+ * @brief Starts a UDP multicast socket bound to a specific IP address and port.
+ *
+ * @param `IPAddress` The multicast IP address to bind the UDP socket to.
+ * @param `uint16_t` The port number to bind the UDP socket to.
+ *
+ * @return Returns `1` if the socket is successfully opened, or
+ * `0` if the socket is already in use or could not be opened.
+ */
+ virtual uint8_t beginMulticast(IPAddress, uint16_t);
+
+ /**
+ * @brief Stops the UDP socket and releases its resources.
+ */
+ virtual void stop();
- // Sending UDP packets
+ /**
+ * @brief Begins constructing a multicast UDP packet for sending.
+ *
+ * @return Returns `1` if the packet preparation is successful.
+ * Or `0` if there is an error or the socket is not initialized.
+ */
virtual int beginMulticastPacket();
- // Start building up a packet to send to the remote host specific in ip and port
- // Returns 1 if successful, 0 if there was a problem with the supplied IP address or port
+
+ /**
+ * @brief Begins constructing a UDP packet for sending to a specific IP address and port.
+ *
+ * @param `ip` The destination IP address as an `IPAddress` object.
+ * @param `port` The destination port number.
+ *
+ * @return Returns `1` if the packet preparation is successful.
+ * Or `0` if there is an error or the socket is not initialized.
+ */
virtual int beginPacket(IPAddress ip, uint16_t port);
- // Start building up a packet to send to the remote host specific in host and port
- // Returns 1 if successful, 0 if there was a problem resolving the hostname or port
+
+ /**
+ * @brief Begins constructing a UDP packet for sending to a specific hostname and port.
+ *
+ * @param `host` The destination hostname as a null-terminated string.
+ * @param `port` The destination port number.
+ *
+ * @return Returns `1` if the packet preparation is successful.
+ * Or `0` if there is an error or the socket is not initialized.
+ */
virtual int beginPacket(const char *host, uint16_t port);
- // Finish off this packet and send it
- // Returns 1 if the packet was sent successfully, 0 if there was an error
+
+ /**
+ * @brief Completes the construction of a UDP packet and sends it to the specified destination.
+ *
+ * @return Returns `1` if the packet is successfully transmitted.
+ * Or `0` if there is an error or the socket is not initialized.
+ */
virtual int endPacket();
- // Write a single byte into the packet
+
+ /**
+ * @brief Sends a single byte of data to the currently opened UDP packet.
+ *
+ * @param `b` The byte of data to send.
+ *
+ * @return Returns `1` if the byte was successfully written.
+ * Or `0` if there was an error or the packet was not properly initialized.
+ */
virtual size_t write(uint8_t);
- // Write size bytes from buffer into the packet
+
+ /**
+ * @brief Sends a buffer of data to the currently opened UDP packet.
+ *
+ * @param `buffer` A pointer to the buffer containing the data to send.
+ * @param `size` The number of bytes from the buffer to write.
+ *
+ * @return Returns the number of bytes successfully written if the operation is successful.
+ * Or `0` if the data was not successfully written, or if the packet was not properly initialized.
+ */
virtual size_t write(const uint8_t *buffer, size_t size);
+ /**
+ * @brief Inherits the `write` method from the Print class.
+ *
+ * This allows the WiFiSSLClient class to use the `write` method defined in the
+ * `Print` class.
+ */
using Print::write;
- // Start processing the next available incoming packet
- // Returns the size of the packet in bytes, or 0 if no packets are available
+ /**
+ * @brief Start processing the next available incoming packet
+ *
+ * @return Returns the size of the incoming packet, or `0` if no packet is available.
+ */
virtual int parsePacket();
- // Number of bytes remaining in the current packet
+
+ /**
+ * @brief Checks if there are any available UDP packets to read.
+ *
+ * @return Returns the number of available bytes if packets are available, or `0` if no packets are available.
+ */
virtual int available();
- // Read a single byte from the current packet
+
+ /**
+ * @brief Read a single byte from the current packet
+ *
+ * @return Returns the number of bytes read into the buffer, or `-1` if an error occurs.
+ */
virtual int read();
- // Read up to len bytes from the current packet and place them into buffer
- // Returns the number of bytes read, or 0 if none are available
+
+ /**
+ * @brief Reads data from the UDP receive buffer into a provided buffer.
+ *
+ * @param `buffer` A pointer to the buffer where the received data will be stored.
+ * @param `size` The number of bytes to read from the UDP buffer.
+ *
+ * @return The number of bytes successfully read into the buffer.
+ * If less than `size` bytes are read, it indicates that the buffer was exhausted early.
+ */
virtual int read(unsigned char* buffer, size_t len);
- // Read up to len characters from the current packet and place them into buffer
- // Returns the number of characters read, or 0 if none are available
+
+
+ /**
+ * @brief Reads data from the UDP receive buffer into a character buffer.
+ *
+ * @param `buffer` A pointer to the character buffer where the received data will be stored.
+ * @param `len` The number of bytes to read from the UDP buffer.
+ *
+ * @return The number of bytes successfully read into the buffer.
+ * If less than `len` bytes are read, it indicates that the buffer was exhausted early.
+ */
virtual int read(char* buffer, size_t len) { return read((unsigned char*)buffer, len); };
- // Return the next byte from the current packet without moving on to the next byte
+
+ /**
+ * @brief Peeks at the next byte available in the UDP buffer without moving on to the next byte.
+ *
+ * @return The value of the next byte in the UDP buffer, or `-1` if no data is available.
+ */
virtual int peek();
+
+ /**
+ * @brief Finish reading the current packet
+ */
virtual void flush(); // Finish reading the current packet
+
+ /**
+ * @brief Compares two WiFiUDP objects for equality.
+ *
+ * This function compares two `WiFiUDP` objects by checking if their associated
+ * socket values (`_sock`) are the same.
+ *
+ * @param `WiFiUDP&` The WiFiUDP object to compare with the current object.
+ *
+ * @return `true` if the socket values are equal, `false` otherwise.
+ */
virtual bool operator==(const WiFiUDP&);
+
+ /**
+ * @brief Compares two WiFiUDP objects for inequality.
+ *
+ * This function compares two `WiFiUDP` objects by checking if their associated
+ * socket values (`_sock`) are different.
+ *
+ * @param `whs` The WiFiUDP object to compare with the current object.
+ * @return `true` if the socket values are different, `false` otherwise.
+ */
virtual bool operator!=(const WiFiUDP& whs)
{
return !this->operator==(whs);
};
- // Return the IP address of the host who sent the current incoming packet
+ /**
+ * @brief Retrieves the remote IP address of the host who sent the current incoming packet.
+ *
+ * @return An `IPAddress` object representing the remote IP address. If the socket
+ * is not valid or the address cannot be retrieved, it returns `IPAddress(0, 0, 0, 0)`.
+ */
virtual IPAddress remoteIP();
- // Return the port of the host who sent the current incoming packet
+
+ /**
+ * @brief Return the port of the host who sent the current incoming packet.
+ *
+ * @return The remote port number as a `uint16_t`. If the socket is not valid or
+ * the port cannot be retrieved, it returns `0`.
+ */
virtual uint16_t remotePort();
-
};
diff --git a/libraries/lwIpWrapper/src/CNetIf.cpp b/libraries/lwIpWrapper/src/CNetIf.cpp
index 810b14075..ca1495f50 100644
--- a/libraries/lwIpWrapper/src/CNetIf.cpp
+++ b/libraries/lwIpWrapper/src/CNetIf.cpp
@@ -1,5 +1,9 @@
#include "CNetIf.h"
#include
+#include "lwip/include/lwip/raw.h"
+#include "lwip/include/lwip/icmp.h"
+#include "lwip/include/lwip/ip_addr.h"
+#include "lwip/include/lwip/inet_chksum.h"
IPAddress CNetIf::default_ip("192.168.0.10");
IPAddress CNetIf::default_nm("255.255.255.0");
@@ -14,6 +18,33 @@ bool CLwipIf::pending_eth_rx = false;
FspTimer CLwipIf::timer;
+static u8_t icmp_receive_callback(void *arg, struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *addr)
+{
+ struct icmp_echo_hdr *iecho;
+ (void)(pcb);
+ (void)(addr);
+ LWIP_ASSERT("p != NULL", p != NULL);
+
+ recv_callback_data* request = (recv_callback_data*)arg;
+ if ((p->tot_len < (PBUF_IP_HLEN + sizeof(struct icmp_echo_hdr))) ||
+ pbuf_remove_header(p, PBUF_IP_HLEN) != 0) {
+ return 0; /* don't consume the packet */
+ }
+
+ iecho = (struct icmp_echo_hdr *)p->payload;
+
+ if(iecho->id != 0xAFAF || iecho->seqno != lwip_htons(request->seqNum)) {
+ /* not eaten, restore original packet */
+ pbuf_add_header(p, PBUF_IP_HLEN);
+ return 0;
+ }
+
+ /* do some ping result processing */
+ request->endMillis = millis();
+ pbuf_free(p);
+ return 1; /* consume the packet */
+}
+
ip_addr_t* u8_to_ip_addr(uint8_t* ipu8, ip_addr_t* ipaddr)
{
IP_ADDR4(ipaddr, ipu8[0], ipu8[1], ipu8[2], ipu8[3]);
@@ -120,6 +151,81 @@ void CLwipIf::lwip_task()
}
}
+
+int CLwipIf::ping(IPAddress ip, uint8_t ttl)
+{
+ /* ttl is not supported. Default value used is 255 */
+ (void)ttl;
+ ip_addr_t addr;
+ addr.addr = ip;
+
+ /* ICMP ping callback data structure */
+ static recv_callback_data requestCbkData;
+
+ /* initialize callback data for a new request */
+ memset(&requestCbkData, 0, sizeof(recv_callback_data));
+ requestCbkData.seqNum = (uint16_t)random(0xffff);
+
+ /* Create a raw socket */
+ struct raw_pcb* s = raw_new(IP_PROTO_ICMP);
+ if (!s) {
+ return -1;
+ }
+
+ raw_recv(s, icmp_receive_callback, (void*)&requestCbkData);
+ raw_bind(s, IP_ADDR_ANY);
+
+ struct pbuf *p;
+ struct icmp_echo_hdr *iecho;
+ size_t ping_size = sizeof(struct icmp_echo_hdr) + 32;
+
+ p = pbuf_alloc(PBUF_IP, (u16_t)ping_size, PBUF_RAM);
+ if (!p) {
+ raw_remove(s);
+ return -1;
+ }
+
+ if ((p->len == p->tot_len) && (p->next == NULL)) {
+ iecho = (struct icmp_echo_hdr *)p->payload;
+
+ size_t i;
+ size_t data_len = ping_size - sizeof(struct icmp_echo_hdr);
+
+ ICMPH_TYPE_SET(iecho, ICMP_ECHO);
+ ICMPH_CODE_SET(iecho, 0);
+ iecho->chksum = 0;
+ iecho->id = 0xAFAF;
+ iecho->seqno = lwip_htons(requestCbkData.seqNum);
+
+ /* fill the additional data buffer with some data */
+ for(i = 0; i < data_len; i++) {
+ ((char*)iecho)[sizeof(struct icmp_echo_hdr) + i] = (char)i;
+ }
+
+ iecho->chksum = inet_chksum(iecho, ping_size);
+ requestCbkData.startMillis = millis();
+ raw_sendto(s, p, &addr);
+
+ }
+ pbuf_free(p);
+
+ CLwipIf::getInstance().startSyncRequest();
+
+ while (!requestCbkData.endMillis && (millis() - requestCbkData.startMillis) <= 5000) {
+ CLwipIf::getInstance().lwip_task();
+ }
+
+ CLwipIf::getInstance().restartAsyncRequest();
+
+ raw_remove(s);
+
+ if (!requestCbkData.endMillis) {
+ return -1;
+ }
+
+ return requestCbkData.endMillis - requestCbkData.startMillis;
+}
+
/* -------------------------------------------------------------------------- */
/* GET INSTANCE SINGLETONE FUNCTION */
/* -------------------------------------------------------------------------- */
diff --git a/libraries/lwIpWrapper/src/CNetIf.h b/libraries/lwIpWrapper/src/CNetIf.h
index 407501b72..21a1ebaf9 100644
--- a/libraries/lwIpWrapper/src/CNetIf.h
+++ b/libraries/lwIpWrapper/src/CNetIf.h
@@ -131,6 +131,12 @@ ip_addr_t* u8_to_ip_addr(uint8_t* ipu8, ip_addr_t* ipaddr);
uint32_t ip_addr_to_u32(ip_addr_t* ipaddr);
+struct recv_callback_data{
+ u32_t startMillis;
+ u32_t endMillis;
+ u16_t seqNum;
+};
+
/* Base class implements DHCP, derived class will switch it on or off */
/* -------------------------------------------------------------------------- */
class CNetIf {
@@ -436,6 +442,10 @@ class CLwipIf {
int setWifiMode(WifiMode_t mode);
void lwip_task();
+ /*
+ * PING
+ */
+ int ping(IPAddress ip, uint8_t ttl = 128);
};
#endif
diff --git a/libraries/lwIpWrapper/src/cortex-m33/liblwIP.a b/libraries/lwIpWrapper/src/cortex-m33/liblwIP.a
index adaabfb1c..687e03a87 100644
Binary files a/libraries/lwIpWrapper/src/cortex-m33/liblwIP.a and b/libraries/lwIpWrapper/src/cortex-m33/liblwIP.a differ
diff --git a/libraries/lwIpWrapper/src/lwipopts.h b/libraries/lwIpWrapper/src/lwipopts.h
index 505a5b57b..790512f25 100644
--- a/libraries/lwIpWrapper/src/lwipopts.h
+++ b/libraries/lwIpWrapper/src/lwipopts.h
@@ -273,7 +273,7 @@
* (requires the LWIP_RAW option)
*/
#ifndef MEMP_NUM_RAW_PCB
-#define MEMP_NUM_RAW_PCB 0
+#define MEMP_NUM_RAW_PCB 1
#endif
/**
@@ -633,7 +633,7 @@
* LWIP_RAW==1: Enable application layer to hook into the IP layer itself.
*/
#ifndef LWIP_RAW
-#define LWIP_RAW 0
+#define LWIP_RAW 1
#endif
/*
diff --git a/platform.txt b/platform.txt
index 19740871b..7acc348c8 100644
--- a/platform.txt
+++ b/platform.txt
@@ -3,7 +3,7 @@
# https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5---3rd-party-Hardware-specification
name=Arduino Renesas fsp Boards
-version=1.3.2
+version=1.4.1
# Compile variables
# ------------------------