Skip to content

Commit

Permalink
Be a little smarter with setting the CPU frequency
Browse files Browse the repository at this point in the history
in the event we have HTTPS and HTTP requests within close periods, let the speed set by the HTTPS request take presidence.
  • Loading branch information
mc-hamster committed Oct 16, 2020
1 parent 3b2f5fa commit 038ddb8
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/meshwifi/meshhttp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void handle404(HTTPRequest *req, HTTPResponse *res);

void middlewareSpeedUp240(HTTPRequest *req, HTTPResponse *res, std::function<void()> next);
void middlewareSpeedUp160(HTTPRequest *req, HTTPResponse *res, std::function<void()> next);
void middlewareSession(HTTPRequest *req, HTTPResponse *res, std::function<void()> next);

bool isWebServerReady = 0;
bool isCertReady = 0;
Expand Down Expand Up @@ -104,7 +105,6 @@ void taskCreateCert(void *parameter)
DEBUG_MSG("Existing SSL Certificate found!\n");
} else {
DEBUG_MSG("Creating the certificate. This may take a while. Please wait...\n");
screen->print("Powered...\n");
cert = new SSLCert();
// disableCore1WDT();
int createCertResult = createSelfSignedCert(*cert, KEYSIZE_2048, "CN=meshtastic.local,O=Meshtastic,C=US",
Expand Down Expand Up @@ -240,7 +240,6 @@ void initWebServer()

insecureServer->addMiddleware(&middlewareSpeedUp160);


DEBUG_MSG("Starting Web Server...\n");
secureServer->start();
insecureServer->start();
Expand All @@ -264,7 +263,12 @@ void middlewareSpeedUp160(HTTPRequest *req, HTTPResponse *res, std::function<voi
// We want to print the response status, so we need to call next() first.
next();

setCpuFrequencyMhz(160);
// 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);
}
timeSpeedUp = millis();
}

Expand Down Expand Up @@ -328,11 +332,9 @@ void handleAPIv1FromRadio(HTTPRequest *req, HTTPResponse *res)

// Status code is 200 OK by default.
res->setHeader("Content-Type", "application/x-protobuf");
//res->setHeader("Content-Type", "application/json");

uint8_t txBuf[MAX_STREAM_BUF_SIZE];


uint32_t len = 1;
while (len) {
len = webAPI.getFromRadio(txBuf);
Expand All @@ -357,15 +359,7 @@ void handleAPIv1ToRadio(HTTPRequest *req, HTTPResponse *res)

// Status code is 200 OK by default.
res->setHeader("Content-Type", "application/x-protobuf");
//res->setHeader("Content-Type", "application/json");

// webAPI.handleToRadio(p);

// We use text/plain for the response
//res->setHeader("Content-Type", "text/plain");

// Stream the incoming request body to the response body
// Theoretically, this should work for every request size.
byte buffer[MAX_TO_FROM_RADIO_SIZE];
size_t s = req->readBytes(buffer, MAX_TO_FROM_RADIO_SIZE);

Expand Down

0 comments on commit 038ddb8

Please sign in to comment.