This repository has been archived by the owner on Jan 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathRTL8720_WiFi.ino
166 lines (133 loc) · 4.25 KB
/
RTL8720_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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/****************************************************************************************************************************
RTL8720_WiFi.ino
For RTL8720DN, RTL8722DM and RTL8722CSM WiFi shields
WiFiManager_Generic_WM_Lite is a library for the Mega, Teensy, SAM DUE, SAMD and STM32 boards
(https://github.com/khoih-prog/WiFiManager_Generic_Lite) to enable store Credentials in EEPROM/LittleFS for easy
configuration/reconfiguration and autoconnect/autoreconnect of WiFi and other services without Hardcoding.
Built by Khoi Hoang https://github.com/khoih-prog/WiFiManager_Generic_Lite
Licensed under MIT license
*****************************************************************************************************************************/
#include "defines.h"
#include "Credentials.h"
#include "dynamicParams.h"
WiFiManager_Generic_Lite* WiFiManager_Generic;
void heartBeatPrint(void)
{
static int num = 1;
if (WiFiManager_Generic->isConfigMode())
Serial.print("C"); // C means in Config Mode
else
{
if (WiFi.status() == WL_CONNECTED)
{
Serial.print("H"); // H means connected to WiFi
// Bad bug or RTL8720 => if WiFi lost, WiFi.status() still is WL_CONNECTED and WiFi.RSSI() still OK.
// Similar bug in Portenta_H7 without workaround as in Portenta_H7, WiFi.RSSI() => 0
//Serial.print(WiFi.RSSI());
}
else
Serial.print("F"); // F means not connected to WiFi
}
if (num == 80)
{
Serial.println();
num = 1;
}
else if (num++ % 10 == 0)
{
Serial.print(F(" "));
}
}
void check_status()
{
static unsigned long checkstatus_timeout = 0;
//KH
#define HEARTBEAT_INTERVAL 20000L
// Print hearbeat every HEARTBEAT_INTERVAL (20) seconds.
if ((millis() > checkstatus_timeout) || (checkstatus_timeout == 0))
{
heartBeatPrint();
checkstatus_timeout = millis() + HEARTBEAT_INTERVAL;
}
}
#if USING_CUSTOMS_STYLE
const char NewCustomsStyle[] /*PROGMEM*/ = "<style>div,input{padding:5px;font-size:1em;}input{width:95%;}body{text-align: center;}\
button{background-color:blue;color:white;line-height:2.4rem;font-size:1.2rem;width:100%;}fieldset{border-radius:0.3rem;margin:0px;}</style>";
#endif
void setup()
{
// Debug console
Serial.begin(115200);
while (!Serial && millis() < 5000);
delay(200);
Serial.print(F("\nStart RTL8720_WiFi on ")); Serial.println(BOARD_NAME);
Serial.println(WIFI_MANAGER_GENERIC_LITE_VERSION);
if (WiFi.status() == WL_NO_SHIELD)
{
Serial.println(F("WiFi shield not present"));
// don't continue
while (true);
}
String fv = WiFi.firmwareVersion();
Serial.print("Current Firmware Version = "); Serial.println(fv);
if (fv != LATEST_RTL8720_FIRMWARE)
{
Serial.println("Please upgrade the firmware");
}
WiFiManager_Generic = new WiFiManager_Generic_Lite();
// Optional to change default AP IP(192.168.4.1) and channel(10)
//WiFiManager_Generic->setConfigPortalIP(IPAddress(192, 168, 120, 1));
WiFiManager_Generic->setConfigPortalChannel(0);
#if USING_CUSTOMS_STYLE
WiFiManager_Generic->setCustomsStyle(NewCustomsStyle);
#endif
#if USING_CUSTOMS_HEAD_ELEMENT
WiFiManager_Generic->setCustomsHeadElement("<style>html{filter: invert(10%);}</style>");
#endif
#if USING_CORS_FEATURE
WiFiManager_Generic->setCORSHeader("Your Access-Control-Allow-Origin");
#endif
// Set customized DHCP HostName
WiFiManager_Generic->begin(HOST_NAME);
//Or use default Hostname "SAMD-WIFI-XXXXXX"
//WiFiManager_Generic->begin();
}
#if USE_DYNAMIC_PARAMETERS
void displayCredentials()
{
Serial.println(F("\nYour stored Credentials :"));
for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++)
{
Serial.print(myMenuItems[i].displayName);
Serial.print(F(" = "));
Serial.println(myMenuItems[i].pdata);
}
}
void displayCredentialsInLoop()
{
static bool displayedCredentials = false;
if (!displayedCredentials)
{
for (int i = 0; i < NUM_MENU_ITEMS; i++)
{
if (!strlen(myMenuItems[i].pdata))
{
break;
}
if ( i == (NUM_MENU_ITEMS - 1) )
{
displayedCredentials = true;
displayCredentials();
}
}
}
}
#endif
void loop()
{
WiFiManager_Generic->run();
check_status();
#if USE_DYNAMIC_PARAMETERS
displayCredentialsInLoop();
#endif
}