forked from esp8266/Arduino
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_sw_WiFiServer.ino
58 lines (50 loc) · 1.16 KB
/
test_sw_WiFiServer.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiClient.h>
#include <BSTest.h>
BS_ENV_DECLARE();
void setup()
{
Serial.begin(115200);
BS_RUN(Serial);
}
bool pretest()
{
WiFi.persistent(false);
WiFi.begin(getenv("STA_SSID"), getenv("STA_PASS"));
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
MDNS.begin("esp8266-wfs-test");
return true;
}
TEST_CASE("Simple echo server", "[WiFiServer]")
{
const uint32_t timeout = 10000;
const uint16_t port = 5000;
const int maxRequests = 5;
const int minRequestLength = 128;
WiFiServer server(port);
server.begin();
auto start = millis();
int replyCount = 0;
while (millis() - start < timeout) {
MDNS.update();
WiFiClient client = server.available();
if (!client) {
continue;
}
String request = client.readStringUntil('\n');
CHECK(request.length() >= minRequestLength);
client.print(request);
client.print('\n');
if (++replyCount == maxRequests) {
break;
}
}
CHECK(replyCount == maxRequests);
}
void loop()
{
}