mirror of
https://github.com/meshtastic/firmware.git
synced 2025-04-26 18:09:04 +00:00
Increase CPU frequency on HTTPS requests. Clock back down after a period of time.
This commit is contained in:
parent
ca48079545
commit
3d3f7869d4
@ -124,7 +124,6 @@ static void powerEnter()
|
||||
{
|
||||
screen->setOn(true);
|
||||
setBluetoothEnable(true);
|
||||
setCPUFast(true); // Set CPU to 240mhz when we're plugged in to wall power.
|
||||
}
|
||||
|
||||
static void onEnter()
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "configuration.h"
|
||||
#include "main.h"
|
||||
#include "meshwifi/meshwifi.h"
|
||||
#include "sleep.h"
|
||||
#include <WebServer.h>
|
||||
#include <WiFi.h>
|
||||
|
||||
@ -30,6 +31,8 @@ Preferences prefs;
|
||||
#include <HTTPServer.hpp>
|
||||
#include <SSLCert.hpp>
|
||||
|
||||
#define HEADER_LEN 4
|
||||
|
||||
// The HTTPS Server comes in a separate namespace. For easier use, include it here.
|
||||
using namespace httpsserver;
|
||||
|
||||
@ -37,16 +40,25 @@ SSLCert *cert;
|
||||
HTTPSServer *secureServer;
|
||||
HTTPServer *insecureServer;
|
||||
|
||||
// Our API to handle messages to and from the radio.
|
||||
httpAPI webAPI;
|
||||
|
||||
// Declare some handler functions for the various URLs on the server
|
||||
void handleAPIv1FromRadio(HTTPRequest *req, HTTPResponse *res);
|
||||
void handleAPIv1ToRadio(HTTPRequest *req, HTTPResponse *res);
|
||||
void handleStyleCSS(HTTPRequest *req, HTTPResponse *res);
|
||||
void handleJSONChatHistoryDummy(HTTPRequest *req, HTTPResponse *res);
|
||||
void handleHotspot(HTTPRequest *req, HTTPResponse *res);
|
||||
void handleRoot(HTTPRequest *req, HTTPResponse *res);
|
||||
void handle404(HTTPRequest *req, HTTPResponse *res);
|
||||
|
||||
void middlewareLogging(HTTPRequest *req, HTTPResponse *res, std::function<void()> next);
|
||||
|
||||
bool isWebServerReady = 0;
|
||||
bool isCertReady = 0;
|
||||
|
||||
uint32_t timeSpeedUp = 0;
|
||||
|
||||
void handleWebResponse()
|
||||
{
|
||||
if (isWifiAvailable() == 0) {
|
||||
@ -61,6 +73,14 @@ void handleWebResponse()
|
||||
secureServer->loop();
|
||||
insecureServer->loop();
|
||||
}
|
||||
|
||||
// Slow down the CPU if we have not received a request within the last
|
||||
// 2 minutes.
|
||||
if (millis () - timeSpeedUp >= (2 * 60 * 1000)) {
|
||||
setCPUFast(false); // Set CPU to 80mhz
|
||||
timeSpeedUp = millis();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void taskCreateCert(void *parameter)
|
||||
@ -87,10 +107,10 @@ void taskCreateCert(void *parameter)
|
||||
DEBUG_MSG("Creating the certificate. This may take a while. Please wait...\n");
|
||||
|
||||
cert = new SSLCert();
|
||||
//disableCore1WDT();
|
||||
// disableCore1WDT();
|
||||
int createCertResult = createSelfSignedCert(*cert, KEYSIZE_2048, "CN=meshtastic.local,O=Meshtastic,C=US",
|
||||
"20190101000000", "20300101000000");
|
||||
//enableCore1WDT();
|
||||
// enableCore1WDT();
|
||||
|
||||
if (createCertResult != 0) {
|
||||
DEBUG_MSG("Creating the certificate failed\n");
|
||||
@ -188,6 +208,8 @@ void initWebServer()
|
||||
// For every resource available on the server, we need to create a ResourceNode
|
||||
// The ResourceNode links URL and HTTP method to a handler function
|
||||
|
||||
ResourceNode *nodeAPIv1ToRadio = new ResourceNode("/api/v1/toradio", "GET", &handleAPIv1ToRadio);
|
||||
ResourceNode *nodeAPIv1FromRadio = new ResourceNode("/api/v1/fromradio", "GET", &handleAPIv1FromRadio);
|
||||
ResourceNode *nodeCSS = new ResourceNode("/css/style.css", "GET", &handleStyleCSS);
|
||||
ResourceNode *nodeJS = new ResourceNode("/scripts/script.js", "GET", &handleJSONChatHistoryDummy);
|
||||
ResourceNode *nodeHotspot = new ResourceNode("/hotspot-detect.html", "GET", &handleHotspot);
|
||||
@ -195,13 +217,19 @@ void initWebServer()
|
||||
ResourceNode *node404 = new ResourceNode("", "GET", &handle404);
|
||||
|
||||
// Secure nodes
|
||||
secureServer->registerNode(nodeAPIv1ToRadio);
|
||||
secureServer->registerNode(nodeAPIv1FromRadio);
|
||||
secureServer->registerNode(nodeCSS);
|
||||
secureServer->registerNode(nodeJS);
|
||||
secureServer->registerNode(nodeHotspot);
|
||||
secureServer->registerNode(nodeRoot);
|
||||
secureServer->setDefaultNode(node404);
|
||||
|
||||
secureServer->addMiddleware(&middlewareLogging);
|
||||
|
||||
// Insecure nodes
|
||||
insecureServer->registerNode(nodeAPIv1ToRadio);
|
||||
insecureServer->registerNode(nodeAPIv1FromRadio);
|
||||
insecureServer->registerNode(nodeCSS);
|
||||
insecureServer->registerNode(nodeJS);
|
||||
insecureServer->registerNode(nodeHotspot);
|
||||
@ -217,6 +245,16 @@ void initWebServer()
|
||||
}
|
||||
}
|
||||
|
||||
void middlewareLogging(HTTPRequest *req, HTTPResponse *res, std::function<void()> next)
|
||||
{
|
||||
// We want to print the response status, so we need to call next() first.
|
||||
next();
|
||||
|
||||
setCPUFast(true); // Set CPU to 240mhz when we're plugged in to wall power.
|
||||
timeSpeedUp = millis();
|
||||
|
||||
}
|
||||
|
||||
void handle404(HTTPRequest *req, HTTPResponse *res)
|
||||
{
|
||||
|
||||
@ -261,6 +299,40 @@ void handleHotspot(HTTPRequest *req, HTTPResponse *res)
|
||||
res->println("<meta http-equiv=\"refresh\" content=\"0;url=http://meshtastic.org/\" />\n");
|
||||
}
|
||||
|
||||
void handleAPIv1FromRadio(HTTPRequest *req, HTTPResponse *res)
|
||||
{
|
||||
DEBUG_MSG("+++++++++++++++ webAPI handleAPIv1FromRadio\n");
|
||||
|
||||
/*
|
||||
http://10.10.30.198/api/v1/fromradio
|
||||
|
||||
*/
|
||||
|
||||
// Status code is 200 OK by default.
|
||||
// We want to deliver a simple HTML page, so we send a corresponding content type:
|
||||
res->setHeader("Content-Type", "application/x-protobuf");
|
||||
|
||||
uint8_t txBuf[MAX_STREAM_BUF_SIZE];
|
||||
|
||||
uint32_t len = webAPI.getFromRadio(txBuf + HEADER_LEN);
|
||||
|
||||
res->write(txBuf, len);
|
||||
DEBUG_MSG("--------------- webAPI handleAPIv1FromRadio, len %d\n", len);
|
||||
}
|
||||
|
||||
void handleAPIv1ToRadio(HTTPRequest *req, HTTPResponse *res)
|
||||
{
|
||||
DEBUG_MSG("webAPI handleAPIv1ToRadio\n");
|
||||
|
||||
// Status code is 200 OK by default.
|
||||
// We want to deliver a simple HTML page, so we send a corresponding content type:
|
||||
res->setHeader("Content-Type", "application/x-protobuf");
|
||||
|
||||
// The response implements the Print interface, so you can use it just like
|
||||
// you would write to Serial etc.
|
||||
res->print("<!DOCTYPE html>");
|
||||
}
|
||||
|
||||
/*
|
||||
To convert text to c strings:
|
||||
|
||||
|
@ -2,11 +2,11 @@
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <functional>
|
||||
#include "PhoneAPI.h"
|
||||
|
||||
void initWebServer();
|
||||
void createSSLCert();
|
||||
|
||||
|
||||
void handleNotFound();
|
||||
|
||||
void handleWebResponse();
|
||||
@ -17,8 +17,21 @@ void notifyWebUI();
|
||||
|
||||
void handleHotspot();
|
||||
|
||||
|
||||
void handleStyleCSS();
|
||||
void handleRoot();
|
||||
void handleScriptsScriptJS();
|
||||
void handleJSONChatHistoryDummy();
|
||||
void handleJSONChatHistoryDummy();
|
||||
|
||||
class httpAPI : public PhoneAPI
|
||||
{
|
||||
|
||||
public:
|
||||
// Nothing here yet
|
||||
|
||||
private:
|
||||
// Nothing here yet
|
||||
|
||||
protected:
|
||||
// Nothing here yet
|
||||
|
||||
};
|
@ -17,7 +17,7 @@ static WiFiServerPort *apiPort;
|
||||
|
||||
uint8_t wifiDisconnectReason = 0;
|
||||
|
||||
// Stores the last 4 of our hardware ID, to make finding the device for pairing easier
|
||||
// Stores our hostname
|
||||
static char ourHost[16];
|
||||
|
||||
bool isWifiAvailable()
|
||||
|
Loading…
Reference in New Issue
Block a user