[SYS] Add Blufi support (#1913)

* First build with IDF, tested with esp32dev-ble only.

* Fix frameworks for non-esp32 boards

* Add blufi support.

* Adds an environment to use esp-idf and Arduino as a component to facilitate incorporating blufi for onboarding and configuration.

---------

Co-authored-by: h2zero <powellperalata@gmail.com>
This commit is contained in:
h2zeroandh2zero authored and GitHub committed 2024-03-15 07:53:13 -05:00
1 parent e55431ad94
commit ffe88feddc
14 files changed
+760 -9

No files matched your search

+20 -6
View File
@@ -1133,14 +1133,14 @@ void setup() {
# ifdef ESP32_ETHERNET
setup_ethernet_esp32();
# endif
if (!failSafeMode && !ethConnected) setup_wifimanager(false);
if (!failSafeMode && !ethConnected) setupwifi(false);
} else {
# ifdef ESP32_ETHERNET
setup_ethernet_esp32();
# endif
Log.notice(F("No config in flash, launching wifi manager" CR));
// In failSafeMode we don't want to setup wifi manager as it has already been done before
if (!failSafeMode) setup_wifimanager(false);
if (!failSafeMode) setupwifi(false);
}
# endif
@@ -1362,6 +1362,13 @@ void setup() {
#if defined(ESP8266) || defined(ESP32)
// Bypass for ESP not reconnecting automaticaly the second time https://github.com/espressif/arduino-esp32/issues/2501
bool wifi_reconnect_bypass() {
# if defined(ESP32) && defined(USE_BLUFI)
extern bool omg_blufi_ble_connected;
if (omg_blufi_ble_connected) {
Log.notice(F("BLUFI is connected, bypassing wifi reconnect" CR));
return true;
}
# endif
uint8_t wifi_autoreconnect_cnt = 0;
# ifdef ESP32
while (WiFi.status() != WL_CONNECTED && wifi_autoreconnect_cnt < maxConnectionRetryNetwork) {
@@ -1628,7 +1635,7 @@ void blockingWaitForReset() {
Log.trace(F("mounted file system" CR));
if (SPIFFS.exists("/config.json")) {
Log.notice(F("Erasing ESP Config, restarting" CR));
setup_wifimanager(true);
setupwifi(true);
}
}
delay(30000);
@@ -1636,7 +1643,7 @@ void blockingWaitForReset() {
Log.notice(F("Going into failsafe mode without peripherals" CR));
// Failsafe mode enable to connect to Wifi or change the firmware without the peripherals setup
failSafeMode = true;
setup_wifimanager(false);
setupwifi(false);
}
}
}
@@ -1766,13 +1773,20 @@ bool loadConfigFromFlash() {
return result;
}
void setup_wifimanager(bool reset_settings) {
void setupwifi(bool reset_settings) {
delay(10);
WiFi.mode(WIFI_STA);
if (reset_settings)
eraseAndRestart();
# if defined(ESP32) && defined(USE_BLUFI)
if (!wifi_reconnect_bypass()) {
startBlufi();
return;
}
# endif
# ifdef USE_MAC_AS_GATEWAY_NAME
String s = WiFi.macAddress();
snprintf(WifiManager_ssid, MAC_NAME_MAX_LEN, "%s_%.2s%.2s", Gateway_Short_Name, s.c_str(), s.c_str() + 3);
@@ -2881,7 +2895,7 @@ void MQTTtoSYS(char* topicOri, JsonObject& SYSdata) { // json object decoding
ESPRestart(5);
} else if (strstr(cmd, eraseCmd) != NULL) { //erase and restart
# ifndef ESPWifiManualSetup
setup_wifimanager(true);
setupwifi(true);
# endif
} else if (strstr(cmd, statusCmd) != NULL) { //erase and restart
stateMeasures();