#560 - Partial work for Charles.

This commit is contained in:
Jm Casler 2020-12-12 18:33:52 -08:00
parent c0d94ae4ab
commit d82aaaa806
5 changed files with 43 additions and 17 deletions

View File

@ -308,6 +308,7 @@ void setup()
// BUTTON_PIN is pulled high by a 12k resistor. // BUTTON_PIN is pulled high by a 12k resistor.
if (!digitalRead(BUTTON_PIN)) { if (!digitalRead(BUTTON_PIN)) {
forceSoftAP = 1; forceSoftAP = 1;
DEBUG_MSG("-------------------- Setting forceSoftAP = 1\n");
} }
#endif #endif
@ -481,15 +482,8 @@ void setup()
} }
#endif #endif
if (forceSoftAP) {
strcpy(radioConfig.preferences.wifi_ssid, "meshtasticAdmin");
strcpy(radioConfig.preferences.wifi_password, "12345678");
radioConfig.preferences.wifi_ap_mode = true;
DEBUG_MSG("Forcing SoftAP\n");
}
// Initialize Wifi // Initialize Wifi
initWifi(); initWifi(forceSoftAP);
if (!rIf) if (!rIf)
recordCriticalError(ErrNoRadio); recordCriticalError(ErrNoRadio);

View File

@ -21,8 +21,16 @@ uint8_t wifiDisconnectReason = 0;
// Stores our hostname // Stores our hostname
char ourHost[16]; char ourHost[16];
bool forcedSoftAP = 0;
bool isWifiAvailable() bool isWifiAvailable()
{ {
// If wifi status is connected, return true regardless of the radio configuration.
if (forcedSoftAP) {
return 1;
}
const char *wifiName = radioConfig.preferences.wifi_ssid; const char *wifiName = radioConfig.preferences.wifi_ssid;
const char *wifiPsw = radioConfig.preferences.wifi_password; const char *wifiPsw = radioConfig.preferences.wifi_password;
@ -58,20 +66,44 @@ void deinitWifi()
} }
// Startup WiFi // Startup WiFi
void initWifi() void initWifi(bool forceSoftAP)
{ {
if (isWifiAvailable() == 0) {
return; if (forceSoftAP) {
// do nothing
DEBUG_MSG("----- Forcing SoftAP\n");
} else {
if (isWifiAvailable() == 0) {
return;
}
} }
forcedSoftAP = forceSoftAP;
createSSLCert(); createSSLCert();
if (radioConfig.has_preferences) { if (radioConfig.has_preferences || forceSoftAP) {
const char *wifiName = radioConfig.preferences.wifi_ssid; const char *wifiName = radioConfig.preferences.wifi_ssid;
const char *wifiPsw = radioConfig.preferences.wifi_password; const char *wifiPsw = radioConfig.preferences.wifi_password;
if (*wifiName && *wifiPsw) { if ((*wifiName && *wifiPsw) || forceSoftAP) {
if (radioConfig.preferences.wifi_ap_mode) { if (forceSoftAP) {
DEBUG_MSG("----- Forcing SoftAP\n");
const char *softAPssid = "";
const char *softAPpasswd = "";
IPAddress apIP(192, 168, 42, 1);
WiFi.onEvent(WiFiEvent);
WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
DEBUG_MSG("STARTING WIFI AP: ssid=%s, ok=%d\n", softAPssid, WiFi.softAP(softAPssid, softAPpasswd));
DEBUG_MSG("MY IP ADDRESS: %s\n", WiFi.softAPIP().toString().c_str());
dnsServer.start(53, "*", apIP);
} else if (radioConfig.preferences.wifi_ap_mode) {
IPAddress apIP(192, 168, 42, 1); IPAddress apIP(192, 168, 42, 1);
WiFi.onEvent(WiFiEvent); WiFi.onEvent(WiFiEvent);

View File

@ -9,7 +9,7 @@
#include <WiFi.h> #include <WiFi.h>
#endif #endif
void initWifi(); void initWifi(bool forceSoftAP);
void deinitWifi(); void deinitWifi();
bool isWifiAvailable(); bool isWifiAvailable();

View File

@ -545,7 +545,7 @@ void setBluetoothEnable(bool on)
if (firstTime) { if (firstTime) {
firstTime = 0; firstTime = 0;
} else { } else {
initWifi(); initWifi(0);
} }
} else { } else {

View File

@ -1,7 +1,7 @@
#include "meshwifi/meshhttp.h" #include "meshwifi/meshhttp.h"
#include "meshwifi/meshwifi.h" #include "meshwifi/meshwifi.h"
void initWifi() {} void initWifi(bool forceSoftAP) {}
void deinitWifi() {} void deinitWifi() {}