#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.
if (!digitalRead(BUTTON_PIN)) {
forceSoftAP = 1;
DEBUG_MSG("-------------------- Setting forceSoftAP = 1\n");
}
#endif
@ -481,15 +482,8 @@ void setup()
}
#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
initWifi();
initWifi(forceSoftAP);
if (!rIf)
recordCriticalError(ErrNoRadio);

View File

@ -21,8 +21,16 @@ uint8_t wifiDisconnectReason = 0;
// Stores our hostname
char ourHost[16];
bool forcedSoftAP = 0;
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 *wifiPsw = radioConfig.preferences.wifi_password;
@ -58,20 +66,44 @@ void deinitWifi()
}
// 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();
if (radioConfig.has_preferences) {
if (radioConfig.has_preferences || forceSoftAP) {
const char *wifiName = radioConfig.preferences.wifi_ssid;
const char *wifiPsw = radioConfig.preferences.wifi_password;
if (*wifiName && *wifiPsw) {
if (radioConfig.preferences.wifi_ap_mode) {
if ((*wifiName && *wifiPsw) || forceSoftAP) {
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);
WiFi.onEvent(WiFiEvent);

View File

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

View File

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

View File

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