mirror of
https://github.com/meshtastic/firmware.git
synced 2025-08-05 05:04:46 +00:00
Merge branch 'master' into dev-wifi
This commit is contained in:
commit
362d8cb831
@ -852,16 +852,22 @@ void DebugInfo::drawFrameWiFi(OLEDDisplay *display, OLEDDisplayUiState *state, i
|
|||||||
// The coordinates define the left starting point of the text
|
// The coordinates define the left starting point of the text
|
||||||
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
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"));
|
display->drawString(x, y, String("WiFi - Not Connected"));
|
||||||
} else {
|
} else {
|
||||||
display->drawString(x, y, String("WiFi - Connected"));
|
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 * 2, "SSID " + String(wifiName));
|
||||||
display->drawString(x, y + FONT_HEIGHT * 3, wifiPsw);
|
display->drawString(x, y + FONT_HEIGHT * 3, "PWD " + String(wifiPsw));
|
||||||
|
|
||||||
/* Display a heartbeat pixel that blinks every time the frame is redrawn */
|
/* Display a heartbeat pixel that blinks every time the frame is redrawn */
|
||||||
#ifdef SHOW_REDRAWS
|
#ifdef SHOW_REDRAWS
|
||||||
|
@ -423,6 +423,7 @@ void loop()
|
|||||||
|
|
||||||
// TODO: This should go into a thread handled by FreeRTOS.
|
// TODO: This should go into a thread handled by FreeRTOS.
|
||||||
handleWebResponse();
|
handleWebResponse();
|
||||||
|
handleDNSResponse();
|
||||||
|
|
||||||
delay(msecstosleep);
|
delay(msecstosleep);
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ void initWebServer() {
|
|||||||
webserver.onNotFound(handleNotFound);
|
webserver.onNotFound(handleNotFound);
|
||||||
//webserver.on("/", handleJSONChatHistory);
|
//webserver.on("/", handleJSONChatHistory);
|
||||||
//webserver.on("/json/chat/history", handleJSONChatHistory);
|
//webserver.on("/json/chat/history", handleJSONChatHistory);
|
||||||
|
webserver.on("/hotspot-detect.html", handleHotspot);
|
||||||
webserver.on("/", []() {
|
webserver.on("/", []() {
|
||||||
webserver.send(200, "text/plain", "Everything is awesome!");
|
webserver.send(200, "text/plain", "Everything is awesome!");
|
||||||
});
|
});
|
||||||
@ -69,13 +70,24 @@ void handleNotFound() {
|
|||||||
for (uint8_t i = 0; i < webserver.args(); i++) {
|
for (uint8_t i = 0; i < webserver.args(); i++) {
|
||||||
message += " " + webserver.argName(i) + ": " + webserver.arg(i) + "\n";
|
message += " " + webserver.argName(i) + ": " + webserver.arg(i) + "\n";
|
||||||
}
|
}
|
||||||
|
Serial.println(message);
|
||||||
webserver.send(404, "text/plain", 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() {
|
void notifyWebUI() {
|
||||||
DEBUG_MSG("************ Got a message! ************\n");
|
DEBUG_MSG("************ Got a message! ************\n");
|
||||||
|
@ -13,3 +13,4 @@ void handleJSONChatHistory();
|
|||||||
|
|
||||||
void notifyWebUI();
|
void notifyWebUI();
|
||||||
|
|
||||||
|
void handleHotspot();
|
||||||
|
@ -4,10 +4,13 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "meshwifi/meshhttp.h"
|
#include "meshwifi/meshhttp.h"
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
|
#include <DNSServer.h>
|
||||||
|
|
||||||
static void WiFiEvent(WiFiEvent_t event);
|
static void WiFiEvent(WiFiEvent_t event);
|
||||||
|
|
||||||
bool isWifiAvailable()
|
DNSServer dnsServer;
|
||||||
|
|
||||||
|
bool isWifiAvailable()
|
||||||
{
|
{
|
||||||
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;
|
||||||
@ -45,15 +48,34 @@ void initWifi()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// strcpy(radioConfig.preferences.wifi_ssid, WiFi_SSID_NAME);
|
|
||||||
// strcpy(radioConfig.preferences.wifi_password, WiFi_SSID_PASSWORD);
|
|
||||||
if (radioConfig.has_preferences) {
|
if (radioConfig.has_preferences) {
|
||||||
const char *wifiName = radioConfig.preferences.wifi_ssid;
|
const char *wifiName = radioConfig.preferences.wifi_ssid;
|
||||||
|
const char *wifiPsw = radioConfig.preferences.wifi_password;
|
||||||
|
|
||||||
if (*wifiName) {
|
if (1) {
|
||||||
const char *wifiPsw = radioConfig.preferences.wifi_password;
|
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) {
|
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("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 {
|
} else {
|
||||||
WiFi.mode(WIFI_MODE_STA);
|
WiFi.mode(WIFI_MODE_STA);
|
||||||
WiFi.onEvent(WiFiEvent);
|
WiFi.onEvent(WiFiEvent);
|
||||||
@ -125,6 +147,11 @@ static void WiFiEvent(WiFiEvent_t event)
|
|||||||
break;
|
break;
|
||||||
case SYSTEM_EVENT_AP_START:
|
case SYSTEM_EVENT_AP_START:
|
||||||
DEBUG_MSG("WiFi access point started\n");
|
DEBUG_MSG("WiFi access point started\n");
|
||||||
|
Serial.println(WiFi.softAPIP());
|
||||||
|
|
||||||
|
// Start web server
|
||||||
|
initWebServer();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case SYSTEM_EVENT_AP_STOP:
|
case SYSTEM_EVENT_AP_STOP:
|
||||||
DEBUG_MSG("WiFi access point stopped\n");
|
DEBUG_MSG("WiFi access point stopped\n");
|
||||||
@ -161,5 +188,12 @@ static void WiFiEvent(WiFiEvent_t event)
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleDNSResponse() {
|
||||||
|
if (radioConfig.preferences.wifi_ap_mode) {
|
||||||
|
dnsServer.processNextRequest();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,10 +6,13 @@
|
|||||||
|
|
||||||
#ifdef HAS_WIFI
|
#ifdef HAS_WIFI
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
|
#include <DNSServer.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void initWifi();
|
void initWifi();
|
||||||
|
|
||||||
void deinitWifi();
|
void deinitWifi();
|
||||||
|
bool isWifiAvailable();
|
||||||
|
|
||||||
bool isWifiAvailable();
|
void WiFiEvent(WiFiEvent_t event);
|
||||||
|
|
||||||
|
void handleDNSResponse();
|
||||||
|
@ -526,8 +526,10 @@ void setBluetoothEnable(bool on)
|
|||||||
initWifi();
|
initWifi();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// shutdown wifi
|
||||||
|
deinitWifi();
|
||||||
|
|
||||||
// We have to totally teardown our bluetooth objects to prevent leaks
|
// We have to totally teardown our bluetooth objects to prevent leaks
|
||||||
deinitWifi(); // shutdown wifi
|
|
||||||
deinitBLE();
|
deinitBLE();
|
||||||
|
|
||||||
Serial.printf("Shutdown BT: %u heap size\n", ESP.getFreeHeap());
|
Serial.printf("Shutdown BT: %u heap size\n", ESP.getFreeHeap());
|
||||||
|
Loading…
Reference in New Issue
Block a user