Skip to content
This repository was archived by the owner on Jan 29, 2023. It is now read-only.

Commit 24dd98c

Browse files
authored
v1.8.0 to add support to AmebaD RRL8720DN
### Release v1.8.0 1. Add support to Realtek RTL8720DN, RTL8722DM and RTL8722CSM using [AmebaD core](https://github.com/ambiot/ambd_arduino) and [FlashStorage_RTL8720 library](https://github.com/khoih-prog/FlashStorage_RTL8720). RTL8720DN WiFi can use either 2.4GHz or 5GHz band. 2. Restructure library 3. Add and Update examples 4. Update `Packages' Patches`
1 parent 6f33d92 commit 24dd98c

File tree

29 files changed

+1183
-211
lines changed

29 files changed

+1183
-211
lines changed

examples/MKR1000_WiFi101/defines.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140

141141
/////////////////////////////////////////////
142142

143-
#include <WiFiManager_Generic_Lite_SAMD.h>
143+
#include <WiFiManager_Generic_Lite.h>
144144

145145
#define HOST_NAME "SAMD-Master-Controller"
146146

examples/MKR1000_WiFi101_MQTT/MKR1000_WiFi101_MQTT.ino

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,8 @@
99
Built by Khoi Hoang https://github.com/khoih-prog/WiFiManager_Generic_Lite
1010
Licensed under MIT license
1111
*****************************************************************************************************************************/
12-
/****************************************************************************************************************************
13-
You have to modify file ./libraries/Adafruit_MQTT_Library/Adafruit_MQTT.cpp as follows to avoid dtostrf error, if exists
14-
15-
#ifdef __cplusplus
16-
extern "C" {
17-
#endif
18-
extern char* itoa(int value, char *string, int radix);
19-
extern char* ltoa(long value, char *string, int radix);
20-
extern char* utoa(unsigned value, char *string, int radix);
21-
extern char* ultoa(unsigned long value, char *string, int radix);
22-
#ifdef __cplusplus
23-
} // extern "C"
24-
#endif
25-
26-
//#if defined(ARDUINO_SAMD_ZERO) || defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_ARCH_SAMD)
27-
#if !( ESP32 || ESP8266 || defined(CORE_TEENSY) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) || defined(STM32F4) || defined(STM32F7) || \
28-
( defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_ARCH_MBED) ) || ARDUINO_ARCH_SEEED_SAMD || ( defined(SEEED_WIO_TERMINAL) || defined(SEEED_XIAO_M0) || \
29-
defined(SEEED_FEMTO_M0) || defined(Wio_Lite_MG126) || defined(WIO_GPS_BOARD) || defined(SEEEDUINO_ZERO) || defined(SEEEDUINO_LORAWAN) || defined(WIO_LTE_CAT) || \
30-
defined(SEEED_GROVE_UI_WIRELESS) ) )
31-
static char *dtostrf(double val, signed char width, unsigned char prec, char *sout)
32-
{
33-
char fmt[20];
34-
sprintf(fmt, "%%%d.%df", width, prec);
35-
sprintf(sout, fmt, val);
36-
return sout;
37-
}
38-
#endif
39-
*****************************************************************************************************************************/
12+
13+
// You have to use forked and modified library https://github.com/khoih-prog/Adafruit_MQTT_Library
4014

4115
#include "defines.h"
4216
#include "Credentials.h"

examples/MKR1000_WiFi101_MQTT/defines.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140

141141
/////////////////////////////////////////////
142142

143-
#include <WiFiManager_Generic_Lite_SAMD.h>
143+
#include <WiFiManager_Generic_Lite.h>
144144

145145
#define HOST_NAME "SAMD-MQTT-Controller"
146146

examples/RP2040_WiFi/defines.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@
208208

209209
/////////////////////////////////////////////
210210

211-
#include <WiFiManager_Generic_Lite_RP2040.h>
211+
#include <WiFiManager_Generic_Lite.h>
212212

213213
#define HOST_NAME "RP2040-Master-Controller"
214214

examples/RP2040_WiFi_MQTT/RP2040_WiFi_MQTT.ino

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,7 @@
1010
Licensed under MIT license
1111
*****************************************************************************************************************************/
1212

13-
/****************************************************************************************************************************
14-
You have to modify file ./libraries/Adafruit_MQTT_Library/Adafruit_MQTT.cpp as follows to avoid dtostrf error, if exists
15-
16-
#ifdef __cplusplus
17-
extern "C" {
18-
#endif
19-
extern char* itoa(int value, char *string, int radix);
20-
extern char* ltoa(long value, char *string, int radix);
21-
extern char* utoa(unsigned value, char *string, int radix);
22-
extern char* ultoa(unsigned long value, char *string, int radix);
23-
#ifdef __cplusplus
24-
} // extern "C"
25-
#endif
26-
27-
//#if defined(ARDUINO_SAMD_ZERO) || defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_ARCH_SAMD)
28-
#if !( ESP32 || ESP8266 || defined(CORE_TEENSY) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) || defined(STM32F4) || defined(STM32F7) || \
29-
( defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_ARCH_MBED) ) || ARDUINO_ARCH_SEEED_SAMD || ( defined(SEEED_WIO_TERMINAL) || defined(SEEED_XIAO_M0) || \
30-
defined(SEEED_FEMTO_M0) || defined(Wio_Lite_MG126) || defined(WIO_GPS_BOARD) || defined(SEEEDUINO_ZERO) || defined(SEEEDUINO_LORAWAN) || defined(WIO_LTE_CAT) || \
31-
defined(SEEED_GROVE_UI_WIRELESS) ) )
32-
static char *dtostrf(double val, signed char width, unsigned char prec, char *sout)
33-
{
34-
char fmt[20];
35-
sprintf(fmt, "%%%d.%df", width, prec);
36-
sprintf(sout, fmt, val);
37-
return sout;
38-
}
39-
#endif
40-
*****************************************************************************************************************************/
13+
// You have to use forked and modified library https://github.com/khoih-prog/Adafruit_MQTT_Library
4114

4215
#include "defines.h"
4316
#include "Credentials.h"

examples/RP2040_WiFi_MQTT/defines.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@
215215

216216
/////////////////////////////////////////////
217217

218-
#include <WiFiManager_Generic_Lite_RP2040.h>
218+
#include <WiFiManager_Generic_Lite.h>
219219

220220
#define HOST_NAME "RP2040-MQTT-Controller"
221221

examples/RTL8720_WiFi/Credentials.h

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/****************************************************************************************************************************
2+
Credentials.h
3+
For RTL8720DN, RTL8722DM and RTL8722CSM WiFi shields
4+
5+
WiFiManager_Generic_WM_Lite is a library for the Mega, Teensy, SAM DUE, SAMD and STM32 boards
6+
(https://github.com/khoih-prog/WiFiManager_Generic_Lite) to enable store Credentials in EEPROM/LittleFS for easy
7+
configuration/reconfiguration and autoconnect/autoreconnect of WiFi and other services without Hardcoding.
8+
9+
Built by Khoi Hoang https://github.com/khoih-prog/WiFiManager_Generic_Lite
10+
Licensed under MIT license
11+
*****************************************************************************************************************************/
12+
13+
#ifndef Credentials_h
14+
#define Credentials_h
15+
16+
#include "defines.h"
17+
18+
/// Start Default Config Data //////////////////
19+
20+
/*
21+
#define SSID_MAX_LEN 32
22+
//From v1.0.3, WPA2 passwords can be up to 63 characters long.
23+
#define PASS_MAX_LEN 64
24+
25+
typedef struct
26+
{
27+
char wifi_ssid[SSID_MAX_LEN];
28+
char wifi_pw [PASS_MAX_LEN];
29+
} WiFi_Credentials;
30+
31+
#define NUM_WIFI_CREDENTIALS 2
32+
33+
// Configurable items besides fixed Header, just add board_name
34+
#define NUM_CONFIGURABLE_ITEMS ( ( 2 * NUM_WIFI_CREDENTIALS ) + 1 )
35+
////////////////
36+
37+
typedef struct Configuration
38+
{
39+
char header [16];
40+
WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS];
41+
char board_name [24];
42+
int checkSum;
43+
} WIFI_GENERIC_Configuration;
44+
*/
45+
46+
#define TO_LOAD_DEFAULT_CONFIG_DATA false
47+
48+
#if TO_LOAD_DEFAULT_CONFIG_DATA
49+
50+
// This feature is primarily used in development to force a known set of values as Config Data
51+
// It will NOT force the Config Portal to activate. Use DRD or erase Config Data with Blynk.clearConfigData()
52+
53+
// Used mostly for development and debugging. FORCES default values to be loaded each run.
54+
// Config Portal data input will be ignored and overridden by DEFAULT_CONFIG_DATA
55+
//bool LOAD_DEFAULT_CONFIG_DATA = true;
56+
57+
// Used mostly once debugged. Assumes good data already saved in device.
58+
// Config Portal data input will be override DEFAULT_CONFIG_DATA
59+
bool LOAD_DEFAULT_CONFIG_DATA = false;
60+
61+
62+
WIFI_GENERIC_Configuration defaultConfig =
63+
{
64+
//char header[16], dummy, not used
65+
"WIFI_GENERIC",
66+
// WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS];
67+
// WiFi_Credentials.wifi_ssid and WiFi_Credentials.wifi_pw
68+
"SSID1", "password1",
69+
"SSID2", "password2",
70+
//char board_name [24];
71+
"SAMD-Control",
72+
// terminate the list
73+
//int checkSum, dummy, not used
74+
0
75+
/////////// End Default Config Data /////////////
76+
};
77+
78+
#else
79+
80+
bool LOAD_DEFAULT_CONFIG_DATA = false;
81+
82+
WIFI_GENERIC_Configuration defaultConfig;
83+
84+
#endif // TO_LOAD_DEFAULT_CONFIG_DATA
85+
86+
/////////// End Default Config Data /////////////
87+
88+
89+
#endif //Credentials_h
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
/****************************************************************************************************************************
2+
RTL8720_WiFi.ino
3+
4+
For RTL8720DN, RTL8722DM and RTL8722CSM WiFi shields
5+
6+
WiFiManager_Generic_WM_Lite is a library for the Mega, Teensy, SAM DUE, SAMD and STM32 boards
7+
(https://github.com/khoih-prog/WiFiManager_Generic_Lite) to enable store Credentials in EEPROM/LittleFS for easy
8+
configuration/reconfiguration and autoconnect/autoreconnect of WiFi and other services without Hardcoding.
9+
10+
Built by Khoi Hoang https://github.com/khoih-prog/WiFiManager_Generic_Lite
11+
Licensed under MIT license
12+
*****************************************************************************************************************************/
13+
14+
#include "defines.h"
15+
#include "Credentials.h"
16+
#include "dynamicParams.h"
17+
18+
WiFiManager_Generic_Lite* WiFiManager_Generic;
19+
20+
void heartBeatPrint(void)
21+
{
22+
static int num = 1;
23+
24+
if (WiFiManager_Generic->isConfigMode())
25+
Serial.print("C"); // C means in Config Mode
26+
else
27+
{
28+
if (WiFi.status() == WL_CONNECTED)
29+
{
30+
Serial.print("H"); // H means connected to WiFi
31+
// Bad bug or RTL8720 => if WiFi lost, WiFi.status() still is WL_CONNECTED and WiFi.RSSI() still OK.
32+
// Similar bug in Portenta_H7 without workaround as in Portenta_H7, WiFi.RSSI() => 0
33+
//Serial.print(WiFi.RSSI());
34+
}
35+
else
36+
Serial.print("F"); // F means not connected to WiFi
37+
}
38+
39+
if (num == 80)
40+
{
41+
Serial.println();
42+
num = 1;
43+
}
44+
else if (num++ % 10 == 0)
45+
{
46+
Serial.print(F(" "));
47+
}
48+
}
49+
50+
void check_status()
51+
{
52+
static unsigned long checkstatus_timeout = 0;
53+
54+
//KH
55+
#define HEARTBEAT_INTERVAL 20000L
56+
// Print hearbeat every HEARTBEAT_INTERVAL (20) seconds.
57+
if ((millis() > checkstatus_timeout) || (checkstatus_timeout == 0))
58+
{
59+
heartBeatPrint();
60+
checkstatus_timeout = millis() + HEARTBEAT_INTERVAL;
61+
}
62+
}
63+
64+
#if USING_CUSTOMS_STYLE
65+
const char NewCustomsStyle[] /*PROGMEM*/ = "<style>div,input{padding:5px;font-size:1em;}input{width:95%;}body{text-align: center;}\
66+
button{background-color:blue;color:white;line-height:2.4rem;font-size:1.2rem;width:100%;}fieldset{border-radius:0.3rem;margin:0px;}</style>";
67+
#endif
68+
69+
void setup()
70+
{
71+
// Debug console
72+
Serial.begin(115200);
73+
while (!Serial && millis() < 5000);
74+
75+
delay(200);
76+
77+
Serial.print(F("\nStart RTL8720_WiFi on ")); Serial.println(BOARD_NAME);
78+
Serial.println(WIFI_MANAGER_GENERIC_LITE_VERSION);
79+
80+
if (WiFi.status() == WL_NO_SHIELD)
81+
{
82+
Serial.println(F("WiFi shield not present"));
83+
// don't continue
84+
while (true);
85+
}
86+
87+
String fv = WiFi.firmwareVersion();
88+
89+
Serial.print("Current Firmware Version = "); Serial.println(fv);
90+
91+
if (fv != LATEST_RTL8720_FIRMWARE)
92+
{
93+
Serial.println("Please upgrade the firmware");
94+
}
95+
96+
WiFiManager_Generic = new WiFiManager_Generic_Lite();
97+
98+
// Optional to change default AP IP(192.168.4.1) and channel(10)
99+
//WiFiManager_Generic->setConfigPortalIP(IPAddress(192, 168, 120, 1));
100+
WiFiManager_Generic->setConfigPortalChannel(0);
101+
102+
#if USING_CUSTOMS_STYLE
103+
WiFiManager_Generic->setCustomsStyle(NewCustomsStyle);
104+
#endif
105+
106+
#if USING_CUSTOMS_HEAD_ELEMENT
107+
WiFiManager_Generic->setCustomsHeadElement("<style>html{filter: invert(10%);}</style>");
108+
#endif
109+
110+
#if USING_CORS_FEATURE
111+
WiFiManager_Generic->setCORSHeader("Your Access-Control-Allow-Origin");
112+
#endif
113+
114+
// Set customized DHCP HostName
115+
WiFiManager_Generic->begin(HOST_NAME);
116+
//Or use default Hostname "SAMD-WIFI-XXXXXX"
117+
//WiFiManager_Generic->begin();
118+
119+
}
120+
121+
#if USE_DYNAMIC_PARAMETERS
122+
void displayCredentials()
123+
{
124+
Serial.println(F("\nYour stored Credentials :"));
125+
126+
for (uint16_t i = 0; i < NUM_MENU_ITEMS; i++)
127+
{
128+
Serial.print(myMenuItems[i].displayName);
129+
Serial.print(F(" = "));
130+
Serial.println(myMenuItems[i].pdata);
131+
}
132+
}
133+
134+
void displayCredentialsInLoop()
135+
{
136+
static bool displayedCredentials = false;
137+
138+
if (!displayedCredentials)
139+
{
140+
for (int i = 0; i < NUM_MENU_ITEMS; i++)
141+
{
142+
if (!strlen(myMenuItems[i].pdata))
143+
{
144+
break;
145+
}
146+
147+
if ( i == (NUM_MENU_ITEMS - 1) )
148+
{
149+
displayedCredentials = true;
150+
displayCredentials();
151+
}
152+
}
153+
}
154+
}
155+
156+
#endif
157+
158+
void loop()
159+
{
160+
WiFiManager_Generic->run();
161+
check_status();
162+
163+
#if USE_DYNAMIC_PARAMETERS
164+
displayCredentialsInLoop();
165+
#endif
166+
}

0 commit comments

Comments
 (0)