Merge branch 'master' into dev-wifi

1.2-legacy
Jm Casler 2020-09-18 18:02:56 -07:00 zatwierdzone przez GitHub
commit 362d8cb831
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
7 zmienionych plików z 72 dodań i 13 usunięć

Wyświetl plik

@ -852,16 +852,22 @@ void DebugInfo::drawFrameWiFi(OLEDDisplay *display, OLEDDisplayUiState *state, i
// The coordinates define the left starting point of the text
display->setTextAlignment(TEXT_ALIGN_LEFT);
if ( WiFi.status() != WL_CONNECTED ) {
if (radioConfig.preferences.wifi_ap_mode) {
display->drawString(x, y, String("WiFi - Software AP"));
} else if ( WiFi.status() != WL_CONNECTED ) {
display->drawString(x, y, String("WiFi - Not Connected"));
} else {
display->drawString(x, y, String("WiFi - Connected"));
}
display->drawString(x, y + FONT_HEIGHT * 1, WiFi.localIP().toString().c_str());
if (radioConfig.preferences.wifi_ap_mode) {
display->drawString(x, y + FONT_HEIGHT * 1, "IP " + String(WiFi.softAPIP().toString().c_str()));
} else {
display->drawString(x, y + FONT_HEIGHT * 1, "IP " + String(WiFi.localIP().toString().c_str()));
}
display->drawString(x, y + FONT_HEIGHT * 2, wifiName);
display->drawString(x, y + FONT_HEIGHT * 3, wifiPsw);
display->drawString(x, y + FONT_HEIGHT * 2, "SSID " + String(wifiName));
display->drawString(x, y + FONT_HEIGHT * 3, "PWD " + String(wifiPsw));
/* Display a heartbeat pixel that blinks every time the frame is redrawn */
#ifdef SHOW_REDRAWS

Wyświetl plik

@ -423,6 +423,7 @@ void loop()
// TODO: This should go into a thread handled by FreeRTOS.
handleWebResponse();
handleDNSResponse();
delay(msecstosleep);
}

Wyświetl plik

@ -25,6 +25,7 @@ void initWebServer() {
webserver.onNotFound(handleNotFound);
//webserver.on("/", handleJSONChatHistory);
//webserver.on("/json/chat/history", handleJSONChatHistory);
webserver.on("/hotspot-detect.html", handleHotspot);
webserver.on("/", []() {
webserver.send(200, "text/plain", "Everything is awesome!");
});
@ -69,13 +70,24 @@ void handleNotFound() {
for (uint8_t i = 0; i < webserver.args(); i++) {
message += " " + webserver.argName(i) + ": " + webserver.arg(i) + "\n";
}
Serial.println(message);
webserver.send(404, "text/plain", message);
/*
*/
}
/*
This supports the Apple Captive Network Assistant (CNA) Portal
*/
void handleHotspot() {
DEBUG_MSG("Hotspot Request\n");
String out = "";
//out += "Success\n";
out += "<meta http-equiv=\"refresh\" content=\"0;url=http://meshtastic.org/\" />\n";
webserver.send ( 200, "text/html", out );
return;
}
void notifyWebUI() {
DEBUG_MSG("************ Got a message! ************\n");

Wyświetl plik

@ -13,3 +13,4 @@ void handleJSONChatHistory();
void notifyWebUI();
void handleHotspot();

Wyświetl plik

@ -4,10 +4,13 @@
#include "main.h"
#include "meshwifi/meshhttp.h"
#include <WiFi.h>
#include <DNSServer.h>
static void WiFiEvent(WiFiEvent_t event);
bool isWifiAvailable()
DNSServer dnsServer;
bool isWifiAvailable()
{
const char *wifiName = radioConfig.preferences.wifi_ssid;
const char *wifiPsw = radioConfig.preferences.wifi_password;
@ -45,15 +48,34 @@ void initWifi()
return;
}
// strcpy(radioConfig.preferences.wifi_ssid, WiFi_SSID_NAME);
// strcpy(radioConfig.preferences.wifi_password, WiFi_SSID_PASSWORD);
if (radioConfig.has_preferences) {
const char *wifiName = radioConfig.preferences.wifi_ssid;
const char *wifiPsw = radioConfig.preferences.wifi_password;
if (*wifiName) {
const char *wifiPsw = radioConfig.preferences.wifi_password;
if (1) {
radioConfig.preferences.wifi_ap_mode = 1;
strcpy(radioConfig.preferences.wifi_ssid, "MeshTest2");
strcpy(radioConfig.preferences.wifi_password, "12345678");
} else {
radioConfig.preferences.wifi_ap_mode = 0;
strcpy(radioConfig.preferences.wifi_ssid, "meshtastic");
strcpy(radioConfig.preferences.wifi_password, "meshtastic!");
}
if (*wifiName && *wifiPsw) {
if (radioConfig.preferences.wifi_ap_mode) {
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", wifiName, WiFi.softAP(wifiName, wifiPsw));
DEBUG_MSG("MY IP ADDRESS: %s\n", WiFi.softAPIP().toString().c_str());
dnsServer.start(53, "*", apIP);
} else {
WiFi.mode(WIFI_MODE_STA);
WiFi.onEvent(WiFiEvent);
@ -125,6 +147,11 @@ static void WiFiEvent(WiFiEvent_t event)
break;
case SYSTEM_EVENT_AP_START:
DEBUG_MSG("WiFi access point started\n");
Serial.println(WiFi.softAPIP());
// Start web server
initWebServer();
break;
case SYSTEM_EVENT_AP_STOP:
DEBUG_MSG("WiFi access point stopped\n");
@ -161,5 +188,12 @@ static void WiFiEvent(WiFiEvent_t event)
break;
default:
break;
}
}
void handleDNSResponse() {
if (radioConfig.preferences.wifi_ap_mode) {
dnsServer.processNextRequest();
}
}

Wyświetl plik

@ -6,10 +6,13 @@
#ifdef HAS_WIFI
#include <WiFi.h>
#include <DNSServer.h>
#endif
void initWifi();
void deinitWifi();
bool isWifiAvailable();
bool isWifiAvailable();
void WiFiEvent(WiFiEvent_t event);
void handleDNSResponse();

Wyświetl plik

@ -526,8 +526,10 @@ void setBluetoothEnable(bool on)
initWifi();
}
} else {
// shutdown wifi
deinitWifi();
// We have to totally teardown our bluetooth objects to prevent leaks
deinitWifi(); // shutdown wifi
deinitBLE();
Serial.printf("Shutdown BT: %u heap size\n", ESP.getFreeHeap());