Skip to content

Commit 3d2085c

Browse files
committed
WiFiServer activation moved from constructor to maintain
1 parent 9402128 commit 3d2085c

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

examples/StandardFirmataWiFi/StandardFirmataWiFi.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,7 @@ void setup()
918918
*/
919919
while (!streamConnected && ++connectionAttempts <= MAX_CONN_ATTEMPTS) {
920920
delay(500);
921+
DEBUG_PRINT(".");
921922
streamConnected = stream.maintain();
922923
}
923924
if (streamConnected) {

utility/WiFiServerStream.h

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
See file LICENSE.txt for further informations on licensing terms.
1616
1717
Parts of this class are based on
18-
18+
1919
- WiFiStream - Copyright (C) 2015-2016 Jesse Frush. All rights reserved.
20-
20+
2121
published under the same license.
2222
23-
Last updated April 15th, 2016
23+
Last updated April 16th, 2016
2424
*/
2525

2626
#ifndef WIFI_SERVER_STREAM_H
@@ -46,21 +46,21 @@ class WiFiServerStream : public WiFiStream
4646
{
4747
stop();
4848
}
49-
49+
5050
// passive TCP connect (accept)
51-
WiFiClient newClient = _server.available();
51+
WiFiClient newClient = _server.available();
5252
if( !_client ) return false; // could this work on all platforms? if( !(_client && _client.connected()) ) return false;
5353
_client = newClient;
54-
54+
5555
return true;
5656
}
57-
57+
5858
public:
5959
/**
6060
* create a WiFi stream with a TCP server
6161
*/
62-
WiFiServerStream(uint16_t server_port) : WiFiStream(server_port), _server(WiFiServer(server_port)) {}
63-
62+
WiFiServerStream(uint16_t server_port) : WiFiStream(server_port) {}
63+
6464
/**
6565
* maintain WiFi and TCP connection
6666
* @return true if WiFi and TCP connection are established
@@ -70,14 +70,15 @@ class WiFiServerStream : public WiFiStream
7070
if( connect_client() ) return true;
7171

7272
stop();
73-
73+
7474
if( !_listening && WiFi.status() == WL_CONNECTED )
7575
{
7676
// start TCP server after first WiFi connect
77+
_server = WiFiServer(_port);
7778
_server.begin();
7879
_listening = true;
7980
}
80-
81+
8182
return false;
8283
}
8384

@@ -92,7 +93,7 @@ class WiFiServerStream : public WiFiStream
9293
}
9394
_connected = false;
9495
}
95-
96+
9697
};
9798

9899
#endif //WIFI_SERVER_STREAM_H

0 commit comments

Comments
 (0)