From c3336150f1e720917e9456f67c7f6763d818f185 Mon Sep 17 00:00:00 2001 From: andysheen Date: Thu, 1 Oct 2020 12:14:22 +0100 Subject: [PATCH 1/2] potential huawei fix for captive portal --- captivePortal.ino | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/captivePortal.ino b/captivePortal.ino index 185e670..0974742 100644 --- a/captivePortal.ino +++ b/captivePortal.ino @@ -11,8 +11,8 @@ class CaptiveRequestHandler : public AsyncWebHandler { void handleRequest(AsyncWebServerRequest *request) { Serial.print("handleRequest: "); Serial.println(request->url()); - - if(!isResetting) { + + if (!isResetting) { if (request->method() == HTTP_GET) { if (request->url() == "/credentials") getCredentials(request); else if (request->url() == "/scan") getScan(request); @@ -22,6 +22,9 @@ class CaptiveRequestHandler : public AsyncWebHandler { } else if (request->url().endsWith("connecttest.txt") || request->url().endsWith("ncsi.txt")) { request->send(200, "text/plain", "Microsoft NCSI"); + } else if (strstr(request->url().c_str(), "generate_204_") != NULL) { + Serial.println("you must be huawei!"); + sendFile(request, "/index.html"); } else { request->send(304); @@ -34,17 +37,17 @@ class CaptiveRequestHandler : public AsyncWebHandler { Serial.print("handleBody: "); Serial.println(request->url()); - if(!isResetting) { + if (!isResetting) { if (request->method() == HTTP_POST) { if (request->url() == "/credentials") { String json = ""; for (int i = 0; i < len; i++) json += char(data[i]); - + StaticJsonDocument<1024> settingsJsonDoc; if (!deserializeJson(settingsJsonDoc, json)) { bool readyToReset = setCredentials(settingsJsonDoc.as()); request->send(200); - + if (readyToReset) { socket_server.textAll("RESTART"); softReset(); @@ -109,7 +112,7 @@ class CaptiveRequestHandler : public AsyncWebHandler { bool setCredentials(JsonVariant json) { bool readyToReset = false; - + Serial.println("setCredentials"); String local_ssid = json["local_ssid"].as(); @@ -138,7 +141,7 @@ class CaptiveRequestHandler : public AsyncWebHandler { readyToReset = true; } - return(readyToReset); + return (readyToReset); } void getScan(AsyncWebServerRequest * request) { From e255bd7afb8d9a08ba11b99a5a236ce16f0bad0b Mon Sep 17 00:00:00 2001 From: andysheen Date: Thu, 1 Oct 2020 19:09:30 +0100 Subject: [PATCH 2/2] added fscale to add logarithmic fading to remote led --- ESP32-SOCKETIO.ino | 1 + captivePortal.ino | 16 +++++++------- rgbled.ino | 54 +++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 62 insertions(+), 9 deletions(-) diff --git a/ESP32-SOCKETIO.ino b/ESP32-SOCKETIO.ino index 0d0d545..9186e86 100644 --- a/ESP32-SOCKETIO.ino +++ b/ESP32-SOCKETIO.ino @@ -68,6 +68,7 @@ using namespace ace_button; #define USERLED 0 #define REMOTELED 1 #define RGBLEDPWMSTART 120 +#define FASTLONGFADE 120 #define LONGFADEMINUTESMAX 360 #define LONGFADECHECKMILLIS 60000 unsigned long prevLongFadeVal = 0; diff --git a/captivePortal.ino b/captivePortal.ino index b8d5224..f0ca6a2 100644 --- a/captivePortal.ino +++ b/captivePortal.ino @@ -15,10 +15,10 @@ class CaptiveRequestHandler : public AsyncWebHandler { if (!isResetting) { if (request->method() == HTTP_GET) { if (request->url() == "/credentials") getCredentials(request); - else if(request->url() == "/reboot") { - request->send(200); - socket_server.textAll("RESTART"); - softReset(); + else if (request->url() == "/reboot") { + request->send(200); + socket_server.textAll("RESTART"); + softReset(); } else if (request->url() == "/scan") getScan(request); else if (SPIFFS.exists(request->url())) sendFile(request, request->url()); @@ -27,7 +27,7 @@ class CaptiveRequestHandler : public AsyncWebHandler { } else if (request->url().endsWith("connecttest.txt") || request->url().endsWith("ncsi.txt")) { request->send(200, "text/plain", "Microsoft NCSI"); - } else if (strstr(request->url().c_str(), "generate_204_") != NULL) { + } else if (strstr(request->url().c_str(), "generate_204_") != NULL) { Serial.println("you must be huawei!"); sendFile(request, "/index.html"); } @@ -50,7 +50,7 @@ class CaptiveRequestHandler : public AsyncWebHandler { StaticJsonDocument<1024> settingsJsonDoc; if (!deserializeJson(settingsJsonDoc, json)) { - if(setCredentials(settingsJsonDoc.as())) request->send(200); + if (setCredentials(settingsJsonDoc.as())) request->send(200); else request->send(400); } } @@ -112,7 +112,7 @@ class CaptiveRequestHandler : public AsyncWebHandler { bool setCredentials(JsonVariant json) { bool result = false; - + Serial.println("setCredentials"); String local_ssid = json["local_ssid"].as(); @@ -141,7 +141,7 @@ class CaptiveRequestHandler : public AsyncWebHandler { result = true; } - return(result); + return (result); } void getScan(AsyncWebServerRequest * request) { diff --git a/rgbled.ino b/rgbled.ino index a86dd25..dbb99cb 100644 --- a/rgbled.ino +++ b/rgbled.ino @@ -116,7 +116,7 @@ void longFadeHandler() { if (currLongFadeVal != prevLongFadeVal) { prevLongFadeVal = currLongFadeVal; currLongFadeVal = currLongFadeVal - 1; - value[REMOTELED] = (byte)currLongFadeVal; + value[REMOTELED] = (byte)fscale(0,RGBLEDPWMSTART,0,RGBLEDPWMSTART,currLongFadeVal,-3); ledChanged[REMOTELED] = true; Serial.println(value[REMOTELED]); } @@ -126,3 +126,55 @@ void longFadeHandler() { } } } + + +int fscale(float originalMin, float originalMax, float newBegin, float newEnd, float inputValue, float curve) { + float OriginalRange = 0; + float NewRange = 0; + float zeroRefCurVal = 0; + float normalizedCurVal = 0; + float rangedValue = 0; + boolean invFlag = 0; + // condition curve parameter + // limit range + if (curve > 10) curve = 10; + if (curve < -10) curve = -10; + curve = (curve * -.1) ; // - invert and scale - this seems more intuitive - postive numbers give more weight to high end on output + curve = pow(10, curve); // convert linear scale into lograthimic exponent for other pow function + // Check for out of range inputValues + if (inputValue < originalMin) { + inputValue = originalMin; + } + if (inputValue > originalMax) { + inputValue = originalMax; + } + + // Zero Refference the values + OriginalRange = originalMax - originalMin; + + if (newEnd > newBegin) { + NewRange = newEnd - newBegin; + } + else + { + NewRange = newBegin - newEnd; + invFlag = 1; + } + zeroRefCurVal = inputValue - originalMin; + normalizedCurVal = zeroRefCurVal / OriginalRange; // normalize to 0 - 1 float + // Check for originalMin > originalMax - the math for all other cases i.e. negative numbers seems to work out fine + if (originalMin > originalMax ) { + return 0; + } + + if (invFlag == 0) { + rangedValue = (pow(normalizedCurVal, curve) * NewRange) + newBegin; + + } + else // invert the ranges + { + rangedValue = newBegin - (pow(normalizedCurVal, curve) * NewRange); + } + + return (int)rangedValue; +}