Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions include/UrlEncode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//+--------------------------------------------------------------------------
//
// File: UrlEncode.h
//
// NightDriverStrip - (c) 2026 Plummer's Software LLC. All Rights Reserved.
//
// This file is part of the NightDriver software project.
//
// NightDriver is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// NightDriver is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Nightdriver. It is normally found in copying.txt
// If not, see <https://www.gnu.org/licenses/>.
//
// Description:
//
// Helper to URL-encode strings for API calls.
// Implemenation provides RFC 1738 style percent-encoding.
//
//---------------------------------------------------------------------------

#pragma once

#include <Arduino.h>

String urlEncode(const String& str);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest we add a comment to indicate where the definition lives, that not being UrlEncode.cpp.
Which is something I was actually going to challenge, but I can see the logic after thinking it through from a few different angles.

1 change: 0 additions & 1 deletion include/effects/matrix/PatternStocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
#include <gfxfont.h> // Adafruit GFX font structs
#include <string.h>
#include <HTTPClient.h>
#include <UrlEncode.h>
#include <ledstripeffect.h>
#include <ArduinoJson.h>
#include "systemcontainer.h"
Expand Down
1 change: 0 additions & 1 deletion include/effects/matrix/PatternSubscribers.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#ifndef PatternSub_H
#define PatternSub_H

#include <UrlEncode.h>
#include "systemcontainer.h"

extern const GFXfont Apple5x7 PROGMEM;
Expand Down
2 changes: 1 addition & 1 deletion include/effects/matrix/PatternWeather.h
Original file line number Diff line number Diff line change
Expand Up @@ -604,4 +604,4 @@ class PatternWeather : public EffectWithId<PatternWeather>
}
};

#endif
#endif
1 change: 0 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ lib_deps = crankyoldgit/IRremoteESP8266 @ ^2.8.6
esp32async/ESPAsyncWebServer @ ^3.7.10
bblanchon/ArduinoJson @ ^7.4.2
https://github.com/PlummersSoftwareLLC/RemoteDebug
plageoj/UrlEncode @ ^1.0.1

; This partition table is the default and fits everything in 4M of flash without OTA.
board_build.partitions = config/partitions_custom_noota.csv
Expand Down
4 changes: 4 additions & 0 deletions src/deviceconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ bool DeviceConfig::SetTimeZone(const String& newTimeZone, bool skipWrite)

DeviceConfig::ValidateResponse DeviceConfig::ValidateOpenWeatherAPIKey(const String &newOpenWeatherAPIKey)
{
#if ENABLE_WIFI
HTTPClient http;

String url = "http://api.openweathermap.org/data/2.5/weather?lat=0&lon=0&appid=" + urlEncode(newOpenWeatherAPIKey);
Expand Down Expand Up @@ -141,6 +142,9 @@ DeviceConfig::ValidateResponse DeviceConfig::ValidateOpenWeatherAPIKey(const Str
return { false, "Unable to validate" };
}
}
#else
return { true, "" };
#endif
}

void DeviceConfig::SetColorSettings(const CRGB& newGlobalColor, const CRGB& newSecondColor)
Expand Down
30 changes: 29 additions & 1 deletion src/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,36 @@ DRAM_ATTR bool NTPTimeClient::_bClockSet = false;
DRAM_ATTR std::mutex NTPTimeClient::_clockMutex; // Clock guard mutex for SNTP client



#if ENABLE_WIFI

String urlEncode(const String& str)
{
String encodedString = "";
char c;
char code0;
char code1;
for (int i = 0; i < str.length(); i++) {
c = str.charAt(i);
if (isalnum(c)) {
encodedString += c;
} else {
code1 = (c & 0xf) + '0';
if ((c & 0xf) > 9) {
code1 = (c & 0xf) - 10 + 'A';
}
c = (c >> 4) & 0xf;
code0 = c + '0';
if (c > 9) {
code0 = c - 10 + 'A';
}
encodedString += '%';
encodedString += code0;
encodedString += code1;
}
}
return encodedString;
}

void DoStatsCommand()
{
auto& bufferManager = g_ptrSystem->BufferManagers()[0];
Expand Down