Merge branch 'master' into master

1.2-legacy
Jm Casler 2021-12-24 13:52:25 -08:00 zatwierdzone przez GitHub
commit caa4f3cd71
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
8 zmienionych plików z 53 dodań i 106 usunięć

Wyświetl plik

@ -1204,7 +1204,7 @@ void DebugInfo::drawFrameWiFi(OLEDDisplay *display, OLEDDisplayUiState *state, i
if (radioConfig.preferences.wifi_ap_mode || isSoftAPForced()) { if (radioConfig.preferences.wifi_ap_mode || isSoftAPForced()) {
display->drawString(x, y + FONT_HEIGHT_SMALL * 1, "IP: " + String(WiFi.softAPIP().toString().c_str())); display->drawString(x, y + FONT_HEIGHT_SMALL * 1, "IP: " + String(WiFi.softAPIP().toString().c_str()));
// Number of connections to the AP. Default mmax for the esp32 is 4 // Number of connections to the AP. Default max for the esp32 is 4
display->drawString(x + SCREEN_WIDTH - display->getStringWidth("(" + String(WiFi.softAPgetStationNum()) + "/4)"), display->drawString(x + SCREEN_WIDTH - display->getStringWidth("(" + String(WiFi.softAPgetStationNum()) + "/4)"),
y + FONT_HEIGHT_SMALL * 1, "(" + String(WiFi.softAPgetStationNum()) + "/4)"); y + FONT_HEIGHT_SMALL * 1, "(" + String(WiFi.softAPgetStationNum()) + "/4)");
} else { } else {

Wyświetl plik

@ -608,6 +608,7 @@ void setup()
) * 1000; ) * 1000;
DEBUG_MSG("myNodeInfo.bitrate = %f bytes / sec\n", myNodeInfo.bitrate); DEBUG_MSG("myNodeInfo.bitrate = %f bytes / sec\n", myNodeInfo.bitrate);
// This must be _after_ service.init because we need our preferences loaded from flash to have proper timeout values // This must be _after_ service.init because we need our preferences loaded from flash to have proper timeout values
PowerFSM_setup(); // we will transition to ON in a couple of seconds, FIXME, only do this for cold boots, not waking from SDS PowerFSM_setup(); // we will transition to ON in a couple of seconds, FIXME, only do this for cold boots, not waking from SDS
powerFSMthread = new PowerFSMThread(); powerFSMthread = new PowerFSMThread();

Wyświetl plik

@ -53,19 +53,6 @@ char contentTypes[][2][32] = {{".txt", "text/plain"}, {".html", "text/html"}
// Our API to handle messages to and from the radio. // Our API to handle messages to and from the radio.
HttpAPI webAPI; HttpAPI webAPI;
uint32_t numberOfRequests = 0;
uint32_t timeSpeedUp = 0;
uint32_t getTimeSpeedUp()
{
return timeSpeedUp;
}
void setTimeSpeedUp()
{
timeSpeedUp = millis();
}
void registerHandlers(HTTPServer *insecureServer, HTTPSServer *secureServer) void registerHandlers(HTTPServer *insecureServer, HTTPSServer *secureServer)
{ {
@ -105,8 +92,6 @@ void registerHandlers(HTTPServer *insecureServer, HTTPSServer *secureServer)
secureServer->registerNode(nodeJsonReport); secureServer->registerNode(nodeJsonReport);
secureServer->registerNode(nodeRoot); secureServer->registerNode(nodeRoot);
secureServer->addMiddleware(&middlewareSpeedUp240);
// Insecure nodes // Insecure nodes
insecureServer->registerNode(nodeAPIv1ToRadioOptions); insecureServer->registerNode(nodeAPIv1ToRadioOptions);
insecureServer->registerNode(nodeAPIv1ToRadio); insecureServer->registerNode(nodeAPIv1ToRadio);
@ -122,42 +107,6 @@ void registerHandlers(HTTPServer *insecureServer, HTTPSServer *secureServer)
insecureServer->registerNode(nodeJsonReport); insecureServer->registerNode(nodeJsonReport);
insecureServer->registerNode(nodeRoot); insecureServer->registerNode(nodeRoot);
insecureServer->addMiddleware(&middlewareSpeedUp160);
}
void middlewareSpeedUp240(HTTPRequest *req, HTTPResponse *res, std::function<void()> next)
{
// We want to print the response status, so we need to call next() first.
next();
// Phone (or other device) has contacted us over WiFi. Keep the radio turned on.
// TODO: This should go into its own middleware layer separate from the speedup.
powerFSM.trigger(EVENT_CONTACT_FROM_PHONE);
setCpuFrequencyMhz(240);
setTimeSpeedUp();
numberOfRequests++;
}
void middlewareSpeedUp160(HTTPRequest *req, HTTPResponse *res, std::function<void()> next)
{
// We want to print the response status, so we need to call next() first.
next();
// Phone (or other device) has contacted us over WiFi. Keep the radio turned on.
// TODO: This should go into its own middleware layer separate from the speedup.
powerFSM.trigger(EVENT_CONTACT_FROM_PHONE);
// If the frequency is 240mhz, we have recently gotten a HTTPS request.
// In that case, leave the frequency where it is and just update the
// countdown timer (timeSpeedUp).
if (getCpuFrequencyMhz() != 240) {
setCpuFrequencyMhz(160);
}
setTimeSpeedUp();
numberOfRequests++;
} }
void handleAPIv1FromRadio(HTTPRequest *req, HTTPResponse *res) void handleAPIv1FromRadio(HTTPRequest *req, HTTPResponse *res)
@ -403,10 +352,6 @@ void handleFormUpload(HTTPRequest *req, HTTPResponse *res)
DEBUG_MSG("Form Upload - Disabling keep-alive\n"); DEBUG_MSG("Form Upload - Disabling keep-alive\n");
res->setHeader("Connection", "close"); res->setHeader("Connection", "close");
DEBUG_MSG("Form Upload - Set frequency to 240mhz\n");
// The upload process is very CPU intensive. Let's speed things up a bit.
setCpuFrequencyMhz(240);
// First, we need to check the encoding of the form that we have received. // First, we need to check the encoding of the form that we have received.
// The browser will set the Content-Type request header, so we can use it for that purpose. // The browser will set the Content-Type request header, so we can use it for that purpose.
// Then we select the body parser based on the encoding. // Then we select the body parser based on the encoding.
@ -605,7 +550,6 @@ void handleReport(HTTPRequest *req, HTTPResponse *res)
res->println("\"wifi\": {"); res->println("\"wifi\": {");
res->printf("\"web_request_count\": %d,\n", numberOfRequests);
res->println("\"rssi\": " + String(WiFi.RSSI()) + ","); res->println("\"rssi\": " + String(WiFi.RSSI()) + ",");
if (radioConfig.preferences.wifi_ap_mode || isSoftAPForced()) { if (radioConfig.preferences.wifi_ap_mode || isSoftAPForced()) {
@ -736,15 +680,11 @@ void handleScanNetworks(HTTPRequest *req, HTTPResponse *res)
for (int i = 0; i < n; ++i) { for (int i = 0; i < n; ++i) {
char ssidArray[50]; char ssidArray[50];
String ssidString = String(WiFi.SSID(i)); String ssidString = String(WiFi.SSID(i));
// String ssidString = String(WiFi.SSID(i)).toCharArray(ssidArray, WiFi.SSID(i).length());
ssidString.replace("\"", "\\\""); ssidString.replace("\"", "\\\"");
ssidString.toCharArray(ssidArray, 50); ssidString.toCharArray(ssidArray, 50);
if (WiFi.encryptionType(i) != WIFI_AUTH_OPEN) { if (WiFi.encryptionType(i) != WIFI_AUTH_OPEN) {
// res->println("{\"ssid\": \"%s\",\"rssi\": -75}, ", String(WiFi.SSID(i).c_str() );
res->printf("{\"ssid\": \"%s\",\"rssi\": %d}", ssidArray, WiFi.RSSI(i)); res->printf("{\"ssid\": \"%s\",\"rssi\": %d}", ssidArray, WiFi.RSSI(i));
// WiFi.RSSI(i)
if (i != n - 1) { if (i != n - 1) {
res->printf(","); res->printf(",");
} }

Wyświetl plik

@ -18,10 +18,6 @@ void handleReport(HTTPRequest *req, HTTPResponse *res);
void middlewareSpeedUp240(HTTPRequest *req, HTTPResponse *res, std::function<void()> next); void middlewareSpeedUp240(HTTPRequest *req, HTTPResponse *res, std::function<void()> next);
void middlewareSpeedUp160(HTTPRequest *req, HTTPResponse *res, std::function<void()> next); void middlewareSpeedUp160(HTTPRequest *req, HTTPResponse *res, std::function<void()> next);
uint32_t getTimeSpeedUp();
void setTimeSpeedUp();
// Interface to the PhoneAPI to access the protobufs with messages // Interface to the PhoneAPI to access the protobufs with messages
class HttpAPI : public PhoneAPI class HttpAPI : public PhoneAPI
{ {

Wyświetl plik

@ -63,16 +63,7 @@ static void handleWebResponse()
if(secureServer) if(secureServer)
secureServer->loop(); secureServer->loop();
insecureServer->loop(); insecureServer->loop();
}
/*
Slow down the CPU if we have not received a request within the last few
seconds.
*/
if (millis() - getTimeSpeedUp() >= (25 * 1000)) {
setCpuFrequencyMhz(80);
setTimeSpeedUp();
} }
} }
} }
@ -112,8 +103,6 @@ static void taskCreateCert(void *parameter)
} else { } else {
setCPUFast(true);
DEBUG_MSG("Creating the certificate. This may take a while. Please wait...\n"); DEBUG_MSG("Creating the certificate. This may take a while. Please wait...\n");
yield(); yield();
cert = new SSLCert(); cert = new SSLCert();
@ -145,9 +134,6 @@ static void taskCreateCert(void *parameter)
prefs.putBytes("PK", (uint8_t *)cert->getPKData(), cert->getPKLength()); prefs.putBytes("PK", (uint8_t *)cert->getPKData(), cert->getPKLength());
prefs.putBytes("cert", (uint8_t *)cert->getCertData(), cert->getCertLength()); prefs.putBytes("cert", (uint8_t *)cert->getCertData(), cert->getCertLength());
} }
setCPUFast(false);
} }
isCertReady = true; isCertReady = true;

Wyświetl plik

@ -103,6 +103,8 @@ void deinitWifi()
saving on the 2.4g transceiver. saving on the 2.4g transceiver.
*/ */
DEBUG_MSG("WiFi deinit\n");
if (isWifiAvailable()) { if (isWifiAvailable()) {
WiFi.mode(WIFI_MODE_NULL); WiFi.mode(WIFI_MODE_NULL);
DEBUG_MSG("WiFi Turned Off\n"); DEBUG_MSG("WiFi Turned Off\n");
@ -140,6 +142,14 @@ static void onNetworkConnected()
// Startup WiFi // Startup WiFi
bool initWifi(bool forceSoftAP) bool initWifi(bool forceSoftAP)
{ {
if (forceSoftAP) {
DEBUG_MSG("WiFi ... Forced AP Mode\n");
} else if (radioConfig.preferences.wifi_ap_mode) {
DEBUG_MSG("WiFi ... AP Mode\n");
} else {
DEBUG_MSG("WiFi ... Client Mode\n");
}
forcedSoftAP = forceSoftAP; forcedSoftAP = forceSoftAP;
if ((radioConfig.has_preferences && radioConfig.preferences.wifi_ssid[0]) || forceSoftAP) { if ((radioConfig.has_preferences && radioConfig.preferences.wifi_ssid[0]) || forceSoftAP) {
@ -152,30 +162,28 @@ bool initWifi(bool forceSoftAP)
wifiPsw = NULL; wifiPsw = NULL;
if (*wifiName || forceSoftAP) { if (*wifiName || forceSoftAP) {
if (forceSoftAP) { if (radioConfig.preferences.wifi_ap_mode || forceSoftAP) {
DEBUG_MSG("Forcing SoftAP\n");
const char *softAPssid = "meshtasticAdmin";
const char *softAPpasswd = "12345678";
IPAddress apIP(192, 168, 42, 1); IPAddress apIP(192, 168, 42, 1);
WiFi.onEvent(WiFiEvent); WiFi.onEvent(WiFiEvent);
WiFi.mode(WIFI_AP);
if (forcedSoftAP) {
const char *softAPssid = "meshtasticAdmin";
const char *softAPpasswd = "12345678";
DEBUG_MSG("Starting (Forced) WIFI AP: ssid=%s, ok=%d\n", softAPssid, WiFi.softAP(softAPssid, softAPpasswd));
} else {
DEBUG_MSG("Starting WIFI AP: ssid=%s, ok=%d\n", wifiName, WiFi.softAP(wifiName, wifiPsw));
}
WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0)); 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 AP ADDRESS: %s\n", WiFi.softAPIP().toString().c_str());
DEBUG_MSG("MY IP ADDRESS: %s\n", WiFi.softAPIP().toString().c_str());
dnsServer.start(53, "*", apIP); // This is needed to improve performance.
esp_wifi_set_ps(WIFI_PS_NONE); // Disable radio power saving
} else 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); dnsServer.start(53, "*", apIP);
@ -184,14 +192,13 @@ bool initWifi(bool forceSoftAP)
getMacAddr(dmac); getMacAddr(dmac);
sprintf(ourHost, "Meshtastic-%02x%02x", dmac[4], dmac[5]); sprintf(ourHost, "Meshtastic-%02x%02x", dmac[4], dmac[5]);
Serial.println(ourHost);
WiFi.mode(WIFI_MODE_STA); WiFi.mode(WIFI_MODE_STA);
WiFi.setHostname(ourHost); WiFi.setHostname(ourHost);
WiFi.onEvent(WiFiEvent); WiFi.onEvent(WiFiEvent);
// esp_wifi_set_ps(WIFI_PS_NONE); // Disable power saving
// WiFiEventId_t eventID = WiFi.onEvent( // This is needed to improve performance.
esp_wifi_set_ps(WIFI_PS_NONE); // Disable radio power saving
WiFi.onEvent( WiFi.onEvent(
[](WiFiEvent_t event, WiFiEventInfo_t info) { [](WiFiEvent_t event, WiFiEventInfo_t info) {
Serial.print("\nWiFi lost connection. Reason: "); Serial.print("\nWiFi lost connection. Reason: ");
@ -250,7 +257,7 @@ static void WiFiEvent(WiFiEvent_t event)
DEBUG_MSG("Authentication mode of access point has changed\n"); DEBUG_MSG("Authentication mode of access point has changed\n");
break; break;
case SYSTEM_EVENT_STA_GOT_IP: case SYSTEM_EVENT_STA_GOT_IP:
DEBUG_MSG("Obtained IP address: \n"); DEBUG_MSG("Obtained IP address: ");
Serial.println(WiFi.localIP()); Serial.println(WiFi.localIP());
onNetworkConnected(); onNetworkConnected();
break; break;
@ -271,7 +278,7 @@ 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());
onNetworkConnected(); onNetworkConnected();
break; break;
case SYSTEM_EVENT_AP_STOP: case SYSTEM_EVENT_AP_STOP:
@ -305,7 +312,7 @@ static void WiFiEvent(WiFiEvent_t event)
DEBUG_MSG("Ethernet disconnected\n"); DEBUG_MSG("Ethernet disconnected\n");
break; break;
case SYSTEM_EVENT_ETH_GOT_IP: case SYSTEM_EVENT_ETH_GOT_IP:
DEBUG_MSG("Obtained IP address\n"); DEBUG_MSG("Obtained IP address (SYSTEM_EVENT_ETH_GOT_IP)\n");
break; break;
default: default:
break; break;
@ -314,7 +321,7 @@ static void WiFiEvent(WiFiEvent_t event)
void handleDNSResponse() void handleDNSResponse()
{ {
if (radioConfig.preferences.wifi_ap_mode) { if (radioConfig.preferences.wifi_ap_mode || isSoftAPForced()) {
dnsServer.processNextRequest(); dnsServer.processNextRequest();
} }
} }

Wyświetl plik

@ -556,7 +556,7 @@ void setBluetoothEnable(bool on)
bluetoothOn = on; bluetoothOn = on;
if (on) { if (on) {
if (!initWifi(isSoftAPForced())) // if we are using wifi, don't turn on bluetooth also if (! isWifiAvailable() )
{ {
Serial.printf("Pre BT: %u heap size\n", ESP.getFreeHeap()); Serial.printf("Pre BT: %u heap size\n", ESP.getFreeHeap());
// ESP_ERROR_CHECK( heap_trace_start(HEAP_TRACE_LEAKS) ); // ESP_ERROR_CHECK( heap_trace_start(HEAP_TRACE_LEAKS) );

Wyświetl plik

@ -14,6 +14,7 @@
#include "rom/rtc.h" #include "rom/rtc.h"
#include <driver/rtc_io.h> #include <driver/rtc_io.h>
#include <driver/uart.h> #include <driver/uart.h>
#include "mesh/http/WiFiAPClient.h"
#include "nimble/BluetoothUtil.h" #include "nimble/BluetoothUtil.h"
@ -48,6 +49,22 @@ RTC_DATA_ATTR int bootCount = 0;
void setCPUFast(bool on) void setCPUFast(bool on)
{ {
#ifndef NO_ESP32 #ifndef NO_ESP32
if (isWifiAvailable()) {
/*
*
* There's a newly introduced bug in the espressif framework where WiFi is
* unstable when the frequency is less than 240mhz.
*
* This mostly impacts WiFi AP mode but we'll bump the frequency for
* all WiFi use cases.
* (Added: Dec 23, 2021 by Jm Casler)
*/
DEBUG_MSG("Setting CPU to 240mhz because WiFi is in use.\n");
setCpuFrequencyMhz(240);
return;
}
setCpuFrequencyMhz(on ? 240 : 80); setCpuFrequencyMhz(on ? 240 : 80);
#endif #endif
} }