forked from esp8266/Arduino
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinteractive.ino
91 lines (78 loc) · 2.55 KB
/
interactive.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
/*
Interactive script meant for debugging only
Run it on serial console and keep this source file opened for the list of commands
Please configure SSID, PSK and IPAddresses below to fit with your network
Released to public domain
*/
#include "ESP8266WiFi.h"
#include "user_interface.h"
const char SSID[] = "open";
const char PSK[] = "";
IPAddress staticip(192, 168, 1, 123);
IPAddress gateway(192, 168, 1, 254);
IPAddress subnet(255, 255, 255, 0);
void setup() {
Serial.begin(115200);
Serial.setDebugOutput(true);
WiFi.mode(WIFI_STA);
WiFi.begin(SSID, PSK);
Serial.println("connecting");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println();
Serial.println(WiFi.localIP());
Serial.print(
"WL_IDLE_STATUS = 0\n"
"WL_NO_SSID_AVAIL = 1\n"
"WL_SCAN_COMPLETED = 2\n"
"WL_CONNECTED = 3\n"
"WL_CONNECT_FAILED = 4\n"
"WL_CONNECTION_LOST = 5\n"
"WL_DISCONNECTED = 6\n"
);
}
void WiFiOn() {
wifi_fpm_do_wakeup();
wifi_fpm_close();
wifi_set_opmode(STATION_MODE);
wifi_station_connect();
}
void WiFiOff() {
wifi_station_disconnect();
wifi_set_opmode(NULL_MODE);
wifi_set_sleep_type(MODEM_SLEEP_T);
wifi_fpm_open();
wifi_fpm_do_sleep(0xFFFFFFF);
}
void loop() {
#define TEST(name, var, varinit, func) \
static decltype(func) var = (varinit); \
if ((var) != (func)) { var = (func); Serial.printf("**** %s: ", name); Serial.println(var); }
#define DO(x...) Serial.println(F( #x )); x; break
TEST("Free Heap", freeHeap, 0, ESP.getFreeHeap());
TEST("WiFiStatus", status, WL_IDLE_STATUS, WiFi.status());
TEST("STA-IP", localIp, (uint32_t)0, WiFi.localIP());
TEST("AP-IP", apIp, (uint32_t)0, WiFi.softAPIP());
switch (Serial.read()) {
case 'F': DO(WiFiOff());
case 'N': DO(WiFiOn());
case '1': DO(WiFi.mode(WIFI_AP));
case '2': DO(WiFi.mode(WIFI_AP_STA));
case '3': DO(WiFi.mode(WIFI_STA));
case 'R': DO(if (((GPI >> 16) & 0xf) == 1) ESP.reset() /* else must hard reset */);
case 'd': DO(WiFi.disconnect());
case 'b': DO(WiFi.begin());
case 'B': DO(WiFi.begin(SSID, PSK));
case 'r': DO(WiFi.reconnect());
case 'c': DO(wifi_station_connect());
case 'a': DO(WiFi.setAutoReconnect(false));
case 'A': DO(WiFi.setAutoReconnect(true));
case 'n': DO(WiFi.setSleepMode(WIFI_NONE_SLEEP));
case 'l': DO(WiFi.setSleepMode(WIFI_LIGHT_SLEEP));
case 'm': DO(WiFi.setSleepMode(WIFI_MODEM_SLEEP));
case 's': DO(WiFi.config(staticip, gateway, subnet));
case 'D': DO(wifi_station_dhcpc_start());
}
}