File tree Expand file tree Collapse file tree 3 files changed +61
-0
lines changed Expand file tree Collapse file tree 3 files changed +61
-0
lines changed Original file line number Diff line number Diff line change @@ -2764,6 +2764,63 @@ void loop() {
2764
2764
2765
2765
```
2766
2766
2767
+ ### ` if(server) `
2768
+
2769
+ #### Description
2770
+ Indicates whether the server is listening for new clients. You can use this to detect whether server.begin() was successful.
2771
+
2772
+
2773
+ #### Syntax
2774
+
2775
+ ```
2776
+ if (server)
2777
+ if (!server)
2778
+
2779
+ ```
2780
+
2781
+ #### Parameters
2782
+ none
2783
+
2784
+ #### Returns
2785
+ - whether the server is listening for new clients (bool).
2786
+
2787
+ #### Example
2788
+
2789
+ ```
2790
+ #include <WiFiNINA.h>
2791
+
2792
+ char ssid[] = "Network"; // your network SSID (name)
2793
+ char pass[] = "myPassword"; // your network password
2794
+
2795
+ WiFiServer server(23);
2796
+
2797
+ void setup() {
2798
+
2799
+ Serial.begin(115200);
2800
+ while (!Serial) {}
2801
+
2802
+ int status = WiFi.begin(ssid, pass);
2803
+ if ( status != WL_CONNECTED) {
2804
+ Serial.println("Couldn't get a WiFi connection");
2805
+ while(true);
2806
+ }
2807
+
2808
+ server.begin();
2809
+ if (!server) {
2810
+ Serial.println("Server failed to start.");
2811
+ while(true);
2812
+ }
2813
+ }
2814
+
2815
+ void loop() {
2816
+ WiFiClient client = server.available();
2817
+ if (client) {
2818
+ String s = client.readStringUntil('\n');
2819
+ server.println(s);
2820
+ }
2821
+ }
2822
+ ```
2823
+
2767
2824
### ` server.status() `
2768
2825
2769
2826
#### Description
Original file line number Diff line number Diff line change @@ -88,6 +88,9 @@ uint8_t WiFiServer::status() {
88
88
}
89
89
}
90
90
91
+ WiFiServer::operator bool () {
92
+ return (_sock != NO_SOCKET_AVAIL);
93
+ }
91
94
92
95
size_t WiFiServer::write (uint8_t b)
93
96
{
Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ class WiFiServer : public Server {
42
42
virtual size_t write (uint8_t );
43
43
virtual size_t write (const uint8_t *buf, size_t size);
44
44
uint8_t status ();
45
+ explicit operator bool ();
45
46
46
47
using Print::write;
47
48
};
You can’t perform that action at this time.
0 commit comments