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

Commit

Permalink
v1.8.0 to add support to AmebaD RRL8720DN
Browse files Browse the repository at this point in the history
### 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`
  • Loading branch information
khoih-prog committed May 19, 2022
1 parent 6f33d92 commit 24dd98c
Show file tree
Hide file tree
Showing 29 changed files with 1,183 additions and 211 deletions.
2 changes: 1 addition & 1 deletion examples/MKR1000_WiFi101/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@

/////////////////////////////////////////////

#include <WiFiManager_Generic_Lite_SAMD.h>
#include <WiFiManager_Generic_Lite.h>

#define HOST_NAME "SAMD-Master-Controller"

Expand Down
30 changes: 2 additions & 28 deletions examples/MKR1000_WiFi101_MQTT/MKR1000_WiFi101_MQTT.ino
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,8 @@
Built by Khoi Hoang https://github.com/khoih-prog/WiFiManager_Generic_Lite
Licensed under MIT license
*****************************************************************************************************************************/
/****************************************************************************************************************************
You have to modify file ./libraries/Adafruit_MQTT_Library/Adafruit_MQTT.cpp as follows to avoid dtostrf error, if exists
#ifdef __cplusplus
extern "C" {
#endif
extern char* itoa(int value, char *string, int radix);
extern char* ltoa(long value, char *string, int radix);
extern char* utoa(unsigned value, char *string, int radix);
extern char* ultoa(unsigned long value, char *string, int radix);
#ifdef __cplusplus
} // extern "C"
#endif
//#if defined(ARDUINO_SAMD_ZERO) || defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_ARCH_SAMD)
#if !( ESP32 || ESP8266 || defined(CORE_TEENSY) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) || defined(STM32F4) || defined(STM32F7) || \
( defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_ARCH_MBED) ) || ARDUINO_ARCH_SEEED_SAMD || ( defined(SEEED_WIO_TERMINAL) || defined(SEEED_XIAO_M0) || \
defined(SEEED_FEMTO_M0) || defined(Wio_Lite_MG126) || defined(WIO_GPS_BOARD) || defined(SEEEDUINO_ZERO) || defined(SEEEDUINO_LORAWAN) || defined(WIO_LTE_CAT) || \
defined(SEEED_GROVE_UI_WIRELESS) ) )
static char *dtostrf(double val, signed char width, unsigned char prec, char *sout)
{
char fmt[20];
sprintf(fmt, "%%%d.%df", width, prec);
sprintf(sout, fmt, val);
return sout;
}
#endif
*****************************************************************************************************************************/

// You have to use forked and modified library https://github.com/khoih-prog/Adafruit_MQTT_Library

#include "defines.h"
#include "Credentials.h"
Expand Down
2 changes: 1 addition & 1 deletion examples/MKR1000_WiFi101_MQTT/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@

/////////////////////////////////////////////

#include <WiFiManager_Generic_Lite_SAMD.h>
#include <WiFiManager_Generic_Lite.h>

#define HOST_NAME "SAMD-MQTT-Controller"

Expand Down
2 changes: 1 addition & 1 deletion examples/RP2040_WiFi/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@

/////////////////////////////////////////////

#include <WiFiManager_Generic_Lite_RP2040.h>
#include <WiFiManager_Generic_Lite.h>

#define HOST_NAME "RP2040-Master-Controller"

Expand Down
29 changes: 1 addition & 28 deletions examples/RP2040_WiFi_MQTT/RP2040_WiFi_MQTT.ino
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,7 @@
Licensed under MIT license
*****************************************************************************************************************************/

/****************************************************************************************************************************
You have to modify file ./libraries/Adafruit_MQTT_Library/Adafruit_MQTT.cpp as follows to avoid dtostrf error, if exists
#ifdef __cplusplus
extern "C" {
#endif
extern char* itoa(int value, char *string, int radix);
extern char* ltoa(long value, char *string, int radix);
extern char* utoa(unsigned value, char *string, int radix);
extern char* ultoa(unsigned long value, char *string, int radix);
#ifdef __cplusplus
} // extern "C"
#endif
//#if defined(ARDUINO_SAMD_ZERO) || defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_ARCH_SAMD)
#if !( ESP32 || ESP8266 || defined(CORE_TEENSY) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) || defined(STM32F4) || defined(STM32F7) || \
( defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_ARCH_MBED) ) || ARDUINO_ARCH_SEEED_SAMD || ( defined(SEEED_WIO_TERMINAL) || defined(SEEED_XIAO_M0) || \
defined(SEEED_FEMTO_M0) || defined(Wio_Lite_MG126) || defined(WIO_GPS_BOARD) || defined(SEEEDUINO_ZERO) || defined(SEEEDUINO_LORAWAN) || defined(WIO_LTE_CAT) || \
defined(SEEED_GROVE_UI_WIRELESS) ) )
static char *dtostrf(double val, signed char width, unsigned char prec, char *sout)
{
char fmt[20];
sprintf(fmt, "%%%d.%df", width, prec);
sprintf(sout, fmt, val);
return sout;
}
#endif
*****************************************************************************************************************************/
// You have to use forked and modified library https://github.com/khoih-prog/Adafruit_MQTT_Library

#include "defines.h"
#include "Credentials.h"
Expand Down
2 changes: 1 addition & 1 deletion examples/RP2040_WiFi_MQTT/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@

/////////////////////////////////////////////

#include <WiFiManager_Generic_Lite_RP2040.h>
#include <WiFiManager_Generic_Lite.h>

#define HOST_NAME "RP2040-MQTT-Controller"

Expand Down
89 changes: 89 additions & 0 deletions examples/RTL8720_WiFi/Credentials.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/****************************************************************************************************************************
Credentials.h
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
*****************************************************************************************************************************/

#ifndef Credentials_h
#define Credentials_h

#include "defines.h"

/// Start Default Config Data //////////////////

/*
#define SSID_MAX_LEN 32
//From v1.0.3, WPA2 passwords can be up to 63 characters long.
#define PASS_MAX_LEN 64
typedef struct
{
char wifi_ssid[SSID_MAX_LEN];
char wifi_pw [PASS_MAX_LEN];
} WiFi_Credentials;
#define NUM_WIFI_CREDENTIALS 2
// Configurable items besides fixed Header, just add board_name
#define NUM_CONFIGURABLE_ITEMS ( ( 2 * NUM_WIFI_CREDENTIALS ) + 1 )
////////////////
typedef struct Configuration
{
char header [16];
WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS];
char board_name [24];
int checkSum;
} WIFI_GENERIC_Configuration;
*/

#define TO_LOAD_DEFAULT_CONFIG_DATA false

#if TO_LOAD_DEFAULT_CONFIG_DATA

// This feature is primarily used in development to force a known set of values as Config Data
// It will NOT force the Config Portal to activate. Use DRD or erase Config Data with Blynk.clearConfigData()

// Used mostly for development and debugging. FORCES default values to be loaded each run.
// Config Portal data input will be ignored and overridden by DEFAULT_CONFIG_DATA
//bool LOAD_DEFAULT_CONFIG_DATA = true;

// Used mostly once debugged. Assumes good data already saved in device.
// Config Portal data input will be override DEFAULT_CONFIG_DATA
bool LOAD_DEFAULT_CONFIG_DATA = false;


WIFI_GENERIC_Configuration defaultConfig =
{
//char header[16], dummy, not used
"WIFI_GENERIC",
// WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS];
// WiFi_Credentials.wifi_ssid and WiFi_Credentials.wifi_pw
"SSID1", "password1",
"SSID2", "password2",
//char board_name [24];
"SAMD-Control",
// terminate the list
//int checkSum, dummy, not used
0
/////////// End Default Config Data /////////////
};

#else

bool LOAD_DEFAULT_CONFIG_DATA = false;

WIFI_GENERIC_Configuration defaultConfig;

#endif // TO_LOAD_DEFAULT_CONFIG_DATA

/////////// End Default Config Data /////////////


#endif //Credentials_h
166 changes: 166 additions & 0 deletions examples/RTL8720_WiFi/RTL8720_WiFi.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,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
}
Loading

0 comments on commit 24dd98c

Please sign in to comment.