Skip to content

Commit 3ed6403

Browse files
authored
Merge branch '2.x.x' into server_end
2 parents e1df697 + f2f5f5e commit 3ed6403

29 files changed

+2118
-175
lines changed

.github/workflows/check-arduino.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
uses: actions/checkout@v4
2020

2121
- name: Arduino Lint
22-
uses: arduino/arduino-lint-action@v1
22+
uses: arduino/arduino-lint-action@v2
2323
with:
2424
compliance: specification
2525
library-manager: update

.github/workflows/compile-examples.yml

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,80 @@ jobs:
2929

3030
env:
3131
SKETCHES_REPORTS_PATH: sketches-reports
32-
32+
UNIVERSAL_SKETCH_PATHS: |
33+
- examples/AP_SimpleWebServer
34+
- examples/ConnectNoEncryption
35+
- examples/ConnectWithWEP
36+
- examples/ConnectWithWPA
37+
- examples/ConnectWithWPA2Enterprise
38+
- examples/Prefs2Struct
39+
- examples/ScanNetworks
40+
- examples/ScanNetworksAdvanced
41+
- examples/SimpleWebServerWiFi
42+
- examples/WiFiAdvancedChatServer
43+
- examples/WiFiChatServer
44+
- examples/WiFiPing
45+
- examples/WiFiSSLClient
46+
- examples/WiFiStorage
47+
- examples/WiFiUdpNtpClient
48+
- examples/WiFiUdpSendReceiveString
49+
- examples/WiFiWebClient
50+
- examples/WiFiWebClientRepeating
51+
- examples/WiFiWebServer
3352
strategy:
3453
fail-fast: false
3554

3655
matrix:
3756
board:
3857
- fqbn: arduino:samd:mkrwifi1010
58+
platforms: |
59+
- name: arduino:samd
60+
artifact-name-suffix: arduino-samd-mkrwifi1010
3961
- fqbn: arduino:samd:mkrvidor4000
62+
platforms: |
63+
- name: arduino:samd
64+
artifact-name-suffix: arduino-samd-mkrvidor4000
4065
- fqbn: arduino:samd:nano_33_iot
66+
platforms: |
67+
- name: arduino:samd
68+
artifact-name-suffix: arduino-samd-nano_33_iot
4169
- fqbn: arduino:megaavr:uno2018:mode=on
70+
platforms: |
71+
- name: arduino:megaavr
72+
artifact-name-suffix: arduino-megaavr-uno2018
4273
- fqbn: arduino:mbed_nano:nanorp2040connect
74+
platforms: |
75+
- name: arduino:mbed_nano
76+
artifact-name-suffix: arduino-mbed_nano-nanorp2040connect
77+
78+
include:
79+
# mkrwifi1010
80+
- board:
81+
fqbn: arduino:samd:mkrwifi1010
82+
sketch-paths: |
83+
- examples/PreferencesCounter
84+
- examples/PreferencesValidation
85+
# mkrvidor4000
86+
- board:
87+
fqbn: arduino:samd:mkrvidor4000
88+
sketch-paths: |
89+
- examples/PreferencesCounter
90+
- examples/PreferencesValidation
91+
# nano_33_iot
92+
- board:
93+
fqbn: arduino:samd:nano_33_iot
94+
sketch-paths: |
95+
- examples/PreferencesCounter
96+
- examples/PreferencesValidation
97+
# uno2018
98+
- board:
99+
fqbn: arduino:megaavr:uno2018:mode=on
100+
# nanorp2040connect
101+
- board:
102+
fqbn: arduino:mbed_nano:nanorp2040connect
103+
sketch-paths: |
104+
- examples/PreferencesCounter
105+
- examples/PreferencesValidation
43106
44107
steps:
45108
- name: Checkout
@@ -56,13 +119,13 @@ jobs:
56119
# Install library dependencies.
57120
- name: VidorPeripherals
58121
sketch-paths: |
59-
- ./examples/
122+
${{ matrix.sketch-paths }}
60123
enable-deltas-report: true
61124
sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }}
62125

63126
- name: Save memory usage change report as artifact
64-
uses: actions/upload-artifact@v3
127+
uses: actions/upload-artifact@v4
65128
with:
66129
if-no-files-found: error
67-
name: ${{ env.SKETCHES_REPORTS_PATH }}
68130
path: ${{ env.SKETCHES_REPORTS_PATH }}
131+
name: sketches-report-${{ matrix.board.artifact-name-suffix }}

.github/workflows/report-size-deltas.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ jobs:
2020
- name: Comment size deltas reports to PRs
2121
uses: arduino/report-size-deltas@v1
2222
with:
23-
# The name of the workflow artifact created by the "Compile Examples" workflow
24-
sketches-reports-source: sketches-reports
23+
# Regex matching the names of the workflow artifacts created by the "Compile Examples" workflow
24+
sketches-reports-source: ^sketches-report-.+

.github/workflows/sync-labels.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ jobs:
7070
file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/${{ matrix.filename }}
7171

7272
- name: Pass configuration files to next job via workflow artifact
73-
uses: actions/upload-artifact@v3
73+
uses: actions/upload-artifact@v4
7474
with:
7575
path: |
7676
*.yaml
@@ -108,13 +108,13 @@ jobs:
108108
uses: actions/checkout@v4
109109

110110
- name: Download configuration files artifact
111-
uses: actions/download-artifact@v3
111+
uses: actions/download-artifact@v4
112112
with:
113113
name: ${{ env.CONFIGURATIONS_ARTIFACT }}
114114
path: ${{ env.CONFIGURATIONS_FOLDER }}
115115

116116
- name: Remove unneeded artifact
117-
uses: geekyeggo/delete-artifact@v2
117+
uses: geekyeggo/delete-artifact@v5
118118
with:
119119
name: ${{ env.CONFIGURATIONS_ARTIFACT }}
120120

docs/api.md

Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1720,6 +1720,71 @@ void setup()
17201720
void loop () {}
17211721
```
17221722

1723+
### `WiFi.dnsIP()`
1724+
1725+
#### Description
1726+
1727+
Returns the DNS server IP address for the device.
1728+
1729+
1730+
#### Syntax
1731+
1732+
```
1733+
WiFi.dnsIP()
1734+
WiFi.dnsIP(n)
1735+
1736+
```
1737+
1738+
#### Parameters
1739+
optional parameter n for the number of the DNS server to get the second DNS serverv
1740+
1741+
#### Returns
1742+
- the DNS server IP address for the device (IPAddress).
1743+
1744+
#### Example
1745+
1746+
```
1747+
#include <WiFiNINA.h>
1748+
1749+
#include "arduino_secrets.h"
1750+
char ssid[] = SECRET_SSID;
1751+
char pass[] = SECRET_PASS;
1752+
1753+
IPAddress emptyIP;
1754+
1755+
void setup() {
1756+
1757+
Serial.begin(115200);
1758+
while (!Serial) {}
1759+
1760+
Serial.print("Attempting to connect to SSID: ");
1761+
Serial.println(ssid);
1762+
int status = WiFi.begin(ssid, pass);
1763+
if ( status != WL_CONNECTED) {
1764+
Serial.println("Couldn't get a WiFi connection");
1765+
while(true);
1766+
}
1767+
1768+
Serial.print("DHCP assigned DNS server: ");
1769+
IPAddress dns1 = WiFi.dnsIP();
1770+
if (dns1 == emptyIP) {
1771+
Serial.println("not set");
1772+
} else {
1773+
dns1.printTo(Serial);
1774+
Serial.println();
1775+
IPAddress dns2 = WiFi.dnsIP(1);
1776+
if (dns2 != emptyIP) {
1777+
Serial.print("DNS server2: ");
1778+
dns2.printTo(Serial);
1779+
Serial.println();
1780+
}
1781+
}
1782+
1783+
}
1784+
1785+
void loop() {
1786+
}
1787+
```
17231788
### `WiFi.getTime()`
17241789

17251790
#### Description
@@ -2764,6 +2829,63 @@ void loop() {
27642829
27652830
```
27662831

2832+
### `if(server)`
2833+
2834+
#### Description
2835+
Indicates whether the server is listening for new clients. You can use this to detect whether server.begin() was successful.
2836+
2837+
2838+
#### Syntax
2839+
2840+
```
2841+
if (server)
2842+
if (!server)
2843+
2844+
```
2845+
2846+
#### Parameters
2847+
none
2848+
2849+
#### Returns
2850+
- whether the server is listening for new clients (bool).
2851+
2852+
#### Example
2853+
2854+
```
2855+
#include <WiFiNINA.h>
2856+
2857+
char ssid[] = "Network"; // your network SSID (name)
2858+
char pass[] = "myPassword"; // your network password
2859+
2860+
WiFiServer server(23);
2861+
2862+
void setup() {
2863+
2864+
Serial.begin(115200);
2865+
while (!Serial) {}
2866+
2867+
int status = WiFi.begin(ssid, pass);
2868+
if ( status != WL_CONNECTED) {
2869+
Serial.println("Couldn't get a WiFi connection");
2870+
while(true);
2871+
}
2872+
2873+
server.begin();
2874+
if (!server) {
2875+
Serial.println("Server failed to start.");
2876+
while(true);
2877+
}
2878+
}
2879+
2880+
void loop() {
2881+
WiFiClient client = server.available();
2882+
if (client) {
2883+
String s = client.readStringUntil('\n');
2884+
server.println(s);
2885+
}
2886+
}
2887+
```
2888+
27672889
### `server.status()`
27682890

27692891
#### Description
@@ -2973,6 +3095,112 @@ void loop() {
29733095
29743096
```
29753097

3098+
### `server.accept()`
3099+
3100+
#### Description
3101+
3102+
The traditional server.available() function would only tell you of a new client after it sent data, which makes some protocols like FTP impossible to properly implement.
3103+
3104+
The intention is programs will use either available() or accept(), but not both. With available(), the client connection continues to be managed by WiFiServer. You don’t need to keep a client object, since calling available() will give you whatever client has sent data. Simple servers can be written with very little code using available().
3105+
3106+
With accept(), WiFiServer gives you the client only once, regardless of whether it has sent any data. You must keep track of the connected clients. This requires more code, but you gain more control.
3107+
3108+
3109+
#### Syntax
3110+
3111+
```
3112+
server.accept()
3113+
3114+
```
3115+
3116+
#### Parameters
3117+
none
3118+
3119+
#### Returns
3120+
- a Client object. If no client has data available for reading, this object will evaluate to false in an if-statement. (WiFiClient).
3121+
3122+
#### Example
3123+
3124+
```
3125+
#include <SPI.h>
3126+
#include <WiFiNINA.h>
3127+
3128+
char ssid[] = "Network"; // your network SSID (name)
3129+
char pass[] = "myPassword"; // your network password
3130+
3131+
int status = WL_IDLE_STATUS;
3132+
3133+
// telnet defaults to port 23
3134+
WiFiServer server(23);
3135+
3136+
WiFiClient clients[8];
3137+
3138+
void setup() {
3139+
//Initialize serial and wait for port to open:
3140+
Serial.begin(9600);
3141+
while (!Serial) {
3142+
; // wait for serial port to connect. Needed for native USB port only
3143+
}
3144+
3145+
// attempt to connect to WiFi network:
3146+
status = WiFi.begin(ssid, pass);
3147+
if ( status != WL_CONNECTED) {
3148+
Serial.println("Couldn't get a WiFi connection");
3149+
while(true);
3150+
}
3151+
3152+
// start the server:
3153+
server.begin();
3154+
3155+
Serial.print("Chat server address:");
3156+
Serial.println(WiFi.localIP());
3157+
}
3158+
3159+
void loop() {
3160+
// check for any new client connecting, and say hello (before any incoming data)
3161+
WiFiClient newClient = server.accept();
3162+
if (newClient) {
3163+
for (byte i=0; i < 8; i++) {
3164+
if (!clients[i]) {
3165+
Serial.print("We have a new client #");
3166+
Serial.println(i);
3167+
newClient.print("Hello, client number: ");
3168+
newClient.println(i);
3169+
// Once we "accept", the client is no longer tracked by WiFiServer
3170+
// so we must store it into our list of clients
3171+
clients[i] = newClient;
3172+
break;
3173+
}
3174+
}
3175+
}
3176+
3177+
// check for incoming data from all clients
3178+
for (byte i=0; i < 8; i++) {
3179+
if (clients[i] && clients[i].available() > 0) {
3180+
// read bytes from a client
3181+
byte buffer[80];
3182+
int count = clients[i].read(buffer, 80);
3183+
// write the bytes to all other connected clients
3184+
for (byte j=0; j < 8; j++) {
3185+
if (j != i && clients[j].connected()) {
3186+
clients[j].write(buffer, count);
3187+
}
3188+
}
3189+
}
3190+
}
3191+
3192+
// stop any clients which disconnect
3193+
for (byte i=0; i < 8; i++) {
3194+
if (clients[i] && !clients[i].connected()) {
3195+
Serial.print("disconnect client #");
3196+
Serial.println(i);
3197+
clients[i].stop();
3198+
}
3199+
}
3200+
3201+
}
3202+
```
3203+
29763204
### `server.peek()`
29773205

29783206
#### Description

0 commit comments

Comments
 (0)