From 068c5851efbd2353e2eb6b6c48c99001119b3d8c Mon Sep 17 00:00:00 2001 From: Mike Date: Tue, 22 Dec 2020 01:44:16 +0200 Subject: [PATCH] Add fields for customization Blynk host (#1543) * Add fields for customization Blynk host Add fields to 'Sync Interfaces' for customization Blynk host. Now you can set you own Blynk server. All you needs its set custom host and port to local Blync server. * Lower blynk host length (memory usage) Co-authored-by: cschwinne --- wled00/blynk.cpp | 4 ++-- wled00/cfg.cpp | 6 ++++++ wled00/data/settings_sync.htm | 2 ++ wled00/fcn_declare.h | 2 +- wled00/html_settings.h | 7 ++++--- wled00/set.cpp | 6 +++++- wled00/wled.cpp | 2 +- wled00/wled.h | 2 ++ wled00/xml.cpp | 2 ++ 9 files changed, 25 insertions(+), 8 deletions(-) diff --git a/wled00/blynk.cpp b/wled00/blynk.cpp index 39b43ba80..ef53ca9b2 100644 --- a/wled00/blynk.cpp +++ b/wled00/blynk.cpp @@ -8,12 +8,12 @@ uint16_t blHue = 0; byte blSat = 255; -void initBlynk(const char* auth) +void initBlynk(const char *auth, const char *host, uint16_t port) { #ifndef WLED_DISABLE_BLYNK if (!WLED_CONNECTED) return; blynkEnabled = (auth[0] != 0); - if (blynkEnabled) Blynk.config(auth); + if (blynkEnabled) Blynk.config(auth, host, port); #endif } diff --git a/wled00/cfg.cpp b/wled00/cfg.cpp index 4bacb9a72..68eba7a3e 100644 --- a/wled00/cfg.cpp +++ b/wled00/cfg.cpp @@ -212,6 +212,10 @@ void deserializeConfig() { if (tdd > 20 || tdd == 0) getStringFromJson(blynkApiKey, apikey, 36); //normally not present due to security + JsonObject if_blynk = interfaces[F("blynk")]; + getStringFromJson(blynkHost, if_blynk[F("host")], 33); + CJSON(blynkPort, if_blynk[F("port")]); + JsonObject if_mqtt = interfaces[F("mqtt")]; CJSON(mqttEnabled, if_mqtt[F("en")]); getStringFromJson(mqttServer, if_mqtt[F("broker")], 33); @@ -531,6 +535,8 @@ void serializeConfig() { if_va_macros.add(macroAlexaOff); JsonObject if_blynk = interfaces.createNestedObject("blynk"); if_blynk[F("token")] = strlen(blynkApiKey) ? "Hidden":""; + if_blynk[F("host")] = blynkHost; + if_blynk[F("port")] = blynkPort; JsonObject if_mqtt = interfaces.createNestedObject("mqtt"); if_mqtt[F("en")] = mqttEnabled; diff --git a/wled00/data/settings_sync.htm b/wled00/data/settings_sync.htm index aa9f03330..778142940 100644 --- a/wled00/data/settings_sync.htm +++ b/wled00/data/settings_sync.htm @@ -79,6 +79,8 @@ Alexa invocation name: This may impact the responsiveness of the ESP8266.
For best results, only use one of these services at a time.
(alternatively, connect a second ESP to them and use the UDP sync)

+Host: +Port:
Device Auth token:
Clear the token field to disable. Setup info

MQTT

diff --git a/wled00/fcn_declare.h b/wled00/fcn_declare.h index ea819f70a..a1c60eeef 100644 --- a/wled00/fcn_declare.h +++ b/wled00/fcn_declare.h @@ -15,7 +15,7 @@ void handleAlexa(); void onAlexaChange(EspalexaDevice* dev); //blynk.cpp -void initBlynk(const char* auth); +void initBlynk(const char* auth, const char* host, uint16_t port); void handleBlynk(); void updateBlynk(); diff --git a/wled00/html_settings.h b/wled00/html_settings.h index b6c7297f3..8943ddfe0 100644 --- a/wled00/html_settings.h +++ b/wled00/html_settings.h @@ -255,9 +255,10 @@ maxlength="32">

Blynk

Blynk, MQTT and Hue sync all connect to external hosts!
This may impact the responsiveness of the ESP8266.

For best results, only use one of these services at a time.
-(alternatively, connect a second ESP to them and use the UDP sync)

-Device Auth token:
-Clear the token field to disable.
Host: + Port:
Device Auth token:
Clear the token field to disable.
Setup info

MQTT

Enable MQTT:
Broker: Port: hasArg(F("AL")); strlcpy(alexaInvocationName, request->arg(F("AI")).c_str(), 33); + strlcpy(blynkHost, request->arg("BH").c_str(), 33); + t = request->arg(F("BP")).toInt(); + if (t > 0) blynkPort = t; + if (request->hasArg("BK") && !request->arg("BK").equals(F("Hidden"))) { - strlcpy(blynkApiKey, request->arg("BK").c_str(), 36); initBlynk(blynkApiKey); + strlcpy(blynkApiKey, request->arg("BK").c_str(), 36); initBlynk(blynkApiKey, blynkHost, blynkPort); } #ifdef WLED_ENABLE_MQTT diff --git a/wled00/wled.cpp b/wled00/wled.cpp index b58676f68..0dd3704c8 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -493,7 +493,7 @@ void WLED::initInterfaces() if (ntpEnabled) ntpConnected = ntpUdp.begin(ntpLocalPort); - initBlynk(blynkApiKey); + initBlynk(blynkApiKey, blynkHost, blynkPort); e131.begin(e131Multicast, e131Port, e131Universe, E131_MAX_UNIVERSE_COUNT); reconnectHue(); initMqtt(); diff --git a/wled00/wled.h b/wled00/wled.h index 213abf6a2..ca19bdbab 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -249,6 +249,8 @@ WLED_GLOBAL bool alexaEnabled _INIT(false); // enable devi WLED_GLOBAL char alexaInvocationName[33] _INIT("Light"); // speech control name of device. Choose something voice-to-text can understand WLED_GLOBAL char blynkApiKey[36] _INIT(""); // Auth token for Blynk server. If empty, no connection will be made +WLED_GLOBAL char blynkHost[33] _INIT("blynk-cloud.com"); // Default Blynk host +WLED_GLOBAL uint16_t blynkPort _INIT(80); // Default Blynk port WLED_GLOBAL uint16_t realtimeTimeoutMs _INIT(2500); // ms timeout of realtime mode before returning to normal mode WLED_GLOBAL int arlsOffset _INIT(0); // realtime LED offset diff --git a/wled00/xml.cpp b/wled00/xml.cpp index 7e512679a..1a64eb5c6 100644 --- a/wled00/xml.cpp +++ b/wled00/xml.cpp @@ -323,6 +323,8 @@ void getSettingsJS(byte subPage, char* dest) sappends('s',SET_F("AI"),alexaInvocationName); sappend('c',SET_F("SA"),notifyAlexa); sappends('s',SET_F("BK"),(char*)((blynkEnabled)?SET_F("Hidden"):"")); + sappends('s',SET_F("BH"),blynkHost); + sappend('v',SET_F("BP"),blynkPort); #ifdef WLED_ENABLE_MQTT sappend('c',SET_F("MQ"),mqttEnabled);