Skip to content

Commit ceb5ba7

Browse files
committed
+ interactive example (for debugging)
1 parent 2d9c545 commit ceb5ba7

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
2+
/*
3+
Interactive script meant for debugging only
4+
Run it on serial console and keep this source file opened for the list of commands
5+
Please configure SSID, PSK and IPAddresses below to fit with your network
6+
7+
Released to public domain
8+
*/
9+
10+
#include "ESP8266WiFi.h"
11+
#include "user_interface.h"
12+
13+
const char SSID[] = "open";
14+
const char PSK[] = "";
15+
16+
IPAddress staticip(192, 168, 1, 123);
17+
IPAddress gateway(192, 168, 1, 254);
18+
IPAddress subnet(255, 255, 255, 0);
19+
20+
void setup()
21+
{
22+
Serial.begin(115200);
23+
Serial.setDebugOutput(true);
24+
25+
WiFi.mode(WIFI_STA);
26+
WiFi.begin(SSID, PSK);
27+
Serial.println("connecting");
28+
while (WiFi.status() != WL_CONNECTED)
29+
{
30+
delay(500);
31+
Serial.print(".");
32+
}
33+
Serial.println();
34+
Serial.println(WiFi.localIP());
35+
Serial.print(
36+
"WL_IDLE_STATUS = 0\n"
37+
"WL_NO_SSID_AVAIL = 1\n"
38+
"WL_SCAN_COMPLETED = 2\n"
39+
"WL_CONNECTED = 3\n"
40+
"WL_CONNECT_FAILED = 4\n"
41+
"WL_CONNECTION_LOST = 5\n"
42+
"WL_DISCONNECTED = 6\n"
43+
);
44+
}
45+
46+
void WiFiOn ()
47+
{
48+
wifi_fpm_do_wakeup();
49+
wifi_fpm_close();
50+
wifi_set_opmode(STATION_MODE);
51+
wifi_station_connect();
52+
}
53+
54+
void WiFiOff ()
55+
{
56+
wifi_station_disconnect();
57+
wifi_set_opmode(NULL_MODE);
58+
wifi_set_sleep_type(MODEM_SLEEP_T);
59+
wifi_fpm_open();
60+
wifi_fpm_do_sleep(0xFFFFFFF);
61+
}
62+
63+
void loop()
64+
{
65+
#define TEST(name, var, varinit, func) \
66+
static decltype(func) var = (varinit); \
67+
if ((var) != (func)) { var = (func); Serial.printf("**** %s: ", name); Serial.println(var); }
68+
69+
#define DO(x...) Serial.println(F( #x )); x; break
70+
71+
TEST("Free Heap", freeHeap, 0, ESP.getFreeHeap());
72+
TEST("WiFiStatus", status, WL_IDLE_STATUS, WiFi.status());
73+
TEST("STA-IP", localIp, (uint32_t)0, WiFi.localIP());
74+
TEST("AP-IP", apIp, (uint32_t)0, WiFi.softAPIP());
75+
76+
switch (Serial.read())
77+
{
78+
case 'F': DO(WiFiOff());
79+
case 'N': DO(WiFiOn());
80+
case '1': DO(WiFi.mode(WIFI_AP));
81+
case '2': DO(WiFi.mode(WIFI_AP_STA));
82+
case '3': DO(WiFi.mode(WIFI_STA));
83+
case 'R': DO(if (((GPI >> 16) & 0xf) == 1) ESP.reset() /* else must hard reset */);
84+
case 'd': DO(WiFi.disconnect());
85+
case 'b': DO(WiFi.begin());
86+
case 'B': DO(WiFi.begin(SSID, PSK));
87+
case 'r': DO(WiFi.reconnect());
88+
case 'c': DO(wifi_station_connect());
89+
case 'a': DO(WiFi.setAutoReconnect(false));
90+
case 'A': DO(WiFi.setAutoReconnect(true));
91+
case 'n': DO(WiFi.setSleepMode(WIFI_NONE_SLEEP));
92+
case 'l': DO(WiFi.setSleepMode(WIFI_LIGHT_SLEEP));
93+
case 'm': DO(WiFi.setSleepMode(WIFI_MODEM_SLEEP));
94+
case 's': DO(WiFi.config(staticip, gateway, subnet));
95+
case 'D': DO(wifi_station_dhcpc_start());
96+
}
97+
}

0 commit comments

Comments
 (0)