File tree 3 files changed +61
-0
lines changed
3 files changed +61
-0
lines changed Original file line number Diff line number Diff line change @@ -2829,6 +2829,63 @@ void loop() {
2829
2829
2830
2830
```
2831
2831
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
+
2832
2889
### ` server.status() `
2833
2890
2834
2891
#### Description
Original file line number Diff line number Diff line change @@ -94,6 +94,9 @@ uint8_t WiFiServer::status() {
94
94
}
95
95
}
96
96
97
+ WiFiServer::operator bool () {
98
+ return (_sock != NO_SOCKET_AVAIL);
99
+ }
97
100
98
101
size_t WiFiServer::write (uint8_t b)
99
102
{
Original file line number Diff line number Diff line change @@ -43,6 +43,7 @@ class WiFiServer : public Server {
43
43
virtual size_t write (uint8_t );
44
44
virtual size_t write (const uint8_t *buf, size_t size);
45
45
uint8_t status ();
46
+ explicit operator bool ();
46
47
47
48
using Print::write;
48
49
};
You can’t perform that action at this time.
0 commit comments