Skip to content

Commit

Permalink
Add fields for customization Blynk host (Aircoookie#1543)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
devMikeUA and Aircoookie authored Dec 21, 2020
1 parent af48dcd commit 068c585
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 8 deletions.
4 changes: 2 additions & 2 deletions wled00/blynk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 6 additions & 0 deletions wled00/cfg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions wled00/data/settings_sync.htm
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ <h3>Blynk</h3>
This may impact the responsiveness of the ESP8266.</b><br>
For best results, only use one of these services at a time.<br>
(alternatively, connect a second ESP to them and use the UDP sync)<br><br>
Host: <input name="BH" maxlength="32">
Port: <input name="BP" type="number" min="1" max="65535" value="80" class="d5"><br>
Device Auth token: <input name="BK" maxlength="33"><br>
<i>Clear the token field to disable. </i><a href="https://github.com/Aircoookie/WLED/wiki/Blynk" target="_blank">Setup info</a>
<h3>MQTT</h3>
Expand Down
2 changes: 1 addition & 1 deletion wled00/fcn_declare.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
7 changes: 4 additions & 3 deletions wled00/html_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,10 @@ maxlength="32"><h3>Blynk</h3><b>
Blynk, MQTT and Hue sync all connect to external hosts!<br>
This may impact the responsiveness of the ESP8266.</b><br>
For best results, only use one of these services at a time.<br>
(alternatively, connect a second ESP to them and use the UDP sync)<br><br>
Device Auth token: <input name="BK" maxlength="33"><br><i>
Clear the token field to disable. </i><a
(alternatively, connect a second ESP to them and use the UDP sync)<br><br>Host:
<input name="BH" maxlength="32"> Port: <input name="BP" type="number" min="1"
max="65535" value="80" class="d5"><br>Device Auth token: <input name="BK"
maxlength="33"><br><i>Clear the token field to disable. </i><a
href="https://github.com/Aircoookie/WLED/wiki/Blynk" target="_blank">Setup info
</a><h3>MQTT</h3>Enable MQTT: <input type="checkbox" name="MQ"><br>Broker:
<input name="MS" maxlength="32"> Port: <input name="MQPORT" type="number"
Expand Down
6 changes: 5 additions & 1 deletion wled00/set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,12 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
alexaEnabled = request->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
Expand Down
2 changes: 1 addition & 1 deletion wled00/wled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions wled00/wled.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions wled00/xml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 068c585

Please sign in to comment.