disable bluetooth while using wifi (esp32 drops networks otherwise)

This commit is contained in:
Kevin Hester 2021-08-17 16:58:21 -07:00
parent 0d758347af
commit 189889489b
6 changed files with 26 additions and 53 deletions

View File

@ -2,8 +2,11 @@
You probably don't care about this section - skip to the next one.
* send debug info 'in-band'
* disable bluetooth while wifi is active
* failed adding https service
* fix wifi connections for mqtt
* send debug info 'in-band'
* usb lora dongle from pine64
* turn on watchdog reset if app hangs on nrf52 or esp32
* list portduino on platformio

View File

@ -337,9 +337,10 @@ void setup()
digitalWrite(RESET_OLED, 1);
#endif
bool forceSoftAP = 0;
#ifdef BUTTON_PIN
#ifndef NO_ESP32
bool forceSoftAP = 0;
// If the button is connected to GPIO 12, don't enable the ability to use
// meshtasticAdmin on the device.
@ -536,10 +537,10 @@ void setup()
}
#endif
#ifndef NO_ESP32
// Initialize Wifi
initWifi(forceSoftAP);
#ifndef NO_ESP32
// Start web server thread.
webServerThread = new WebServerThread();
#endif

View File

@ -81,15 +81,6 @@ bool isWifiAvailable()
const char *wifiName = radioConfig.preferences.wifi_ssid;
// strcpy(radioConfig.preferences.wifi_ssid, "meshtastic");
// strcpy(radioConfig.preferences.wifi_password, "meshtastic!");
// strcpy(radioConfig.preferences.wifi_ssid, "meshtasticAdmin");
// strcpy(radioConfig.preferences.wifi_password, "12345678");
// radioConfig.preferences.wifi_ap_mode = true;
// radioConfig.preferences.wifi_ap_mode = false;
if (*wifiName) {
return true;
} else {
@ -119,26 +110,16 @@ void deinitWifi()
}
// Startup WiFi
void initWifi(bool forceSoftAP)
bool initWifi(bool forceSoftAP)
{
if (forceSoftAP) {
// do nothing
// DEBUG_MSG("----- Forcing SoftAP\n");
} else {
if (isWifiAvailable() == 0) {
return;
}
}
forcedSoftAP = forceSoftAP;
createSSLCert();
if (radioConfig.has_preferences || forceSoftAP) {
if ((radioConfig.has_preferences && radioConfig.preferences.wifi_ssid) || forceSoftAP) {
const char *wifiName = radioConfig.preferences.wifi_ssid;
const char *wifiPsw = radioConfig.preferences.wifi_password;
createSSLCert();
if (!*wifiPsw) // Treat empty password as no password
wifiPsw = NULL;
@ -215,9 +196,11 @@ void initWifi(bool forceSoftAP)
DEBUG_MSG("mDNS Host: Meshtastic.local\n");
MDNS.addService("http", "tcp", 80);
MDNS.addService("https", "tcp", 443);
} else
return true;
} else {
DEBUG_MSG("Not using WIFI\n");
return false;
}
}
// Called by the Espressif SDK to

View File

@ -9,7 +9,9 @@
#include <WiFi.h>
#endif
void initWifi(bool forceSoftAP);
/// @return true if wifi is now in use
bool initWifi(bool forceSoftAP);
void deinitWifi();
bool isWifiAvailable();

View File

@ -539,7 +539,6 @@ void reinitBluetooth()
}
bool bluetoothOn;
bool firstTime = 1;
// Enable/disable bluetooth.
void setBluetoothEnable(bool on)
@ -549,32 +548,15 @@ void setBluetoothEnable(bool on)
bluetoothOn = on;
if (on) {
Serial.printf("Pre BT: %u heap size\n", ESP.getFreeHeap());
// ESP_ERROR_CHECK( heap_trace_start(HEAP_TRACE_LEAKS) );
reinitBluetooth();
// Don't try to reconnect wifi before bluetooth is configured.
// WiFi is initialized from main.cpp in setup() .
if (firstTime) {
firstTime = 0;
} else {
#ifndef NO_ESP32
initWifi(0);
#endif
if (!initWifi(0)) // if we are using wifi, don't turn on bluetooth also
{
Serial.printf("Pre BT: %u heap size\n", ESP.getFreeHeap());
// ESP_ERROR_CHECK( heap_trace_start(HEAP_TRACE_LEAKS) );
reinitBluetooth();
}
} else {
/*
// If WiFi is in use, disable shutting down the radio.
if (isWifiAvailable()) {
return;
}
*/
// shutdown wifi
#ifndef NO_ESP32
deinitWifi();
#endif
// We have to totally teardown our bluetooth objects to prevent leaks
deinitBLE();

View File

@ -5,7 +5,9 @@
//#include "mesh/wifi/WiFiAPClient.h"
void initWifi(bool forceSoftAP) {}
bool initWifi(bool forceSoftAP) {
return false;
}
void deinitWifi() {}