-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwifi.cpp
137 lines (91 loc) · 2.61 KB
/
wifi.cpp
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
#include <Arduino.h>
#include <WiFiUdp.h>
#include <user_interface.h>
#include "wifi.h"
#include "oled.h"
#include "lua.h"
wl_status_t wifi_status = WL_IDLE_STATUS;
static String softAPSSID() {
struct softap_config config;
wifi_softap_get_config(&config);
const char* name = reinterpret_cast<const char*>(config.ssid);
char ssid[sizeof(config.ssid) + 1];
memcpy(ssid, name, sizeof(config.ssid));
ssid[sizeof(config.ssid)] = '\0';
return String(ssid);
}
static String softAPPSK() {
struct softap_config config;
wifi_softap_get_config(&config);
const char* pass = reinterpret_cast<const char*>(config.password);
char psk[sizeof(config.password) + 1];
memcpy(psk, pass, sizeof(config.password));
psk[sizeof(config.password)] = '\0';
return String(psk);
}
void wifi_setup() {
}
void wifi_display() {
//Prep OLED for display
oled.clearDisplay();
oled.setTextColor(WHITE);
oled.setTextSize(1);
bool ap = false;
oled.setCursor(0,0);
switch (WiFi.getMode()) {
case WIFI_OFF: oled.print(F("--: ")); break;
case WIFI_STA : oled.print(F("ST: ")); break;
case WIFI_AP : oled.print(F("AP: ")); ap=true; break;
case WIFI_AP_STA: oled.print(F("EX: ")); ap=true; break;
default: oled.print(F("??: ")); break;
}
oled.print(ap ? softAPSSID() : WiFi.SSID());
oled.setCursor(0,12);
oled.print(F("PW: "));
oled.print(ap ? softAPPSK() : WiFi.psk());
oled.setCursor(0,24);
oled.print(F("IP: "));
oled.print(ap ? WiFi.softAPIP() : WiFi.localIP());
//Show final render on OLED
oled.display();
}
/*
WL_NO_SHIELD = 255, // for compatibility with WiFi Shield library
WL_IDLE_STATUS = 0,
WL_NO_SSID_AVAIL = 1,
WL_SCAN_COMPLETED = 2,
WL_CONNECTED = 3,
WL_CONNECT_FAILED = 4,
WL_CONNECTION_LOST = 5,
WL_DISCONNECTED = 6
*/
//TODO: DO SOMETHING HERE
void pingFault (void) {}
void wifi_connected() {
startPingAlive();
//TODO: FIND A WAY TO TURN PING ALIVE OFF ONCE CONNECTION IS LOST
Serial.println(F("\nWifi connection established"));
Serial.print(F("\tNetwork:\t"));
Serial.println(WiFi.SSID());
Serial.print(F("\tIP address:\t"));
Serial.println(WiFi.localIP());
Serial.print(F("\tSubnet mask:\t"));
Serial.println(WiFi.subnetMask());
Serial.print(F("\tGateway:\t"));
Serial.println(WiFi.gatewayIP());
Serial.print(F("\tDNS:\t\t"));
Serial.println(WiFi.dnsIP());
Serial.print(F("\tHostname:\t"));
Serial.println(WiFi.hostname());
Serial.println(F(""));
}
void wifi_loop() {
wl_status_t status = WiFi.status();
if (unlikely(status != wifi_status)) {
wifi_status = status;
wifi_display();
if (wifi_status == WL_CONNECTED) {
wifi_connected();
}
}
}