-
Notifications
You must be signed in to change notification settings - Fork 0
/
BasicTest_for_connecting_to_WiFi.ino
139 lines (113 loc) · 3.4 KB
/
BasicTest_for_connecting_to_WiFi.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
WiFiEsp test: BasicTest
Performs basic connectivity test and checks.
*/
#include <WiFiEsp.h>
#include "arduino_secrets.h"
// your network SSID (name)
char ssid[] = SECRET_SSID;
// your network password
char pwd[] = SECRET_PASS;
// wrong password
char pwdErr[] = WRONG_PASS;
void setup()
{
Serial.begin(115200);
Serial1.begin(9600);
WiFi.init(&Serial1);
}
void loop()
{
assertEquals("Firmware version", WiFi.firmwareVersion(), "2.0.0");
assertEquals("Status is (WL_DISCONNECTED)", WiFi.status(), WL_DISCONNECTED);
assertEquals("Connect", WiFi.begin(ssid, pwd), WL_CONNECTED);
assertEquals("Check status (WL_CONNECTED)", WiFi.status(), WL_CONNECTED);
assertEquals("Check SSID", WiFi.SSID(), ssid);
IPAddress ip = WiFi.localIP();
assertNotEquals("Check IP Address", ip[0], 0);
Serial.print("IP Address: ");
Serial.println(ip);
byte mac[6]={0,0,0,0,0,0};
WiFi.macAddress(mac);
Serial.print("MAC: ");
Serial.print(mac[5], HEX);
Serial.print(":");
Serial.print(mac[4], HEX);
Serial.print(":");
Serial.print(mac[3], HEX);
Serial.print(":");
Serial.print(mac[2], HEX);
Serial.print(":");
Serial.print(mac[1], HEX);
Serial.print(":");
Serial.println(mac[0], HEX);
Serial.println();
assertEquals("Disconnect", WiFi.disconnect(), WL_DISCONNECTED);
assertEquals("Check status (WL_DISCONNECTED)", WiFi.status(), WL_DISCONNECTED);
assertEquals("IP Address", WiFi.localIP(), 0);
assertEquals("Check SSID", WiFi.SSID(), "");
assertEquals("Wrong pwd", WiFi.begin(ssid, pwdErr), WL_CONNECT_FAILED);
IPAddress localIp(192, 168, 168, 111);
WiFi.config(localIp);
assertEquals("Connect", WiFi.begin(ssid, pwd), WL_CONNECTED);
assertEquals("Check status (WL_CONNECTED)", WiFi.status(), WL_CONNECTED);
ip = WiFi.localIP();
assertNotEquals("Check IP Address", ip[0], 0);
Serial.println("END OF TESTS");
delay(60000);
}
////////////////////////////////////////////////////////////////////////////////////
void assertNotEquals(const char* test, int actual, int expected)
{
if(actual!=expected)
pass(test);
else
fail(test, actual, expected);
}
void assertEquals(const char* test, int actual, int expected)
{
if(actual==expected)
pass(test);
else
fail(test, actual, expected);
}
void assertEquals(const char* test, char* actual, char* expected)
{
if(strcmp(actual, expected) == 0)
pass(test);
else
fail(test, actual, expected);
}
void pass(const char* test)
{
Serial.print(F("********************************************** "));
Serial.print(test);
Serial.println(" > PASSED");
Serial.println();
}
void fail(const char* test, char* actual, char* expected)
{
Serial.print(F("********************************************** "));
Serial.print(test);
Serial.print(" > FAILED");
Serial.print(" (actual=\"");
Serial.print(actual);
Serial.print("\", expected=\"");
Serial.print(expected);
Serial.println("\")");
Serial.println();
delay(10000);
}
void fail(const char* test, int actual, int expected)
{
Serial.print(F("********************************************** "));
Serial.print(test);
Serial.print(" > FAILED");
Serial.print(" (actual=");
Serial.print(actual);
Serial.print(", expected=");
Serial.print(expected);
Serial.println(")");
Serial.println();
delay(10000);
}