Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
6bd5cfb
Replace UrlEncode library with local implementation.
robertlipe Jan 5, 2026
23b16eb
include/effects/matrix/PatternStocks.h: Remove unused include of UrlE…
robertlipe Jan 5, 2026
67b1940
Merge branch 'main' into chore/remove-urlencode
robertlipe Jan 5, 2026
2712f55
Revert PatternWeather.
robertlipe Jan 5, 2026
8445c69
Remove extra newlines
robertlipe Jan 5, 2026
b931c84
Don't call NTP stuff if we don't have NTP
robertlipe Jan 24, 2026
75508cb
Can't validate network traffic if not WIFI
robertlipe Jan 24, 2026
fe80d0c
Avoid potentially bad pointer if we're inside WiFiDraw(), but withou…
robertlipe Jan 24, 2026
918f71b
Don't init NetworkCLI without Network
robertlipe Jan 24, 2026
7af691a
Webserver makes sense only if ENABLE_WEBSERVER
robertlipe Jan 24, 2026
c554c75
Only do NTP if ENABLE_NTP. Move uptime to debug_cli as it was never n…
robertlipe Jan 24, 2026
7ccdcf8
Don't globally expose (now) static functions in network.h
robertlipe Jan 24, 2026
f879f77
Pick up forgotten network.cpp changes.
robertlipe Jan 24, 2026
b23c7f6
Add sanity checks to globals. If you've turned on ENABLE_NTP but not …
robertlipe Jan 24, 2026
12bc9c7
Trigger CI
robertlipe Jan 24, 2026
adf84a4
Merge branch 'main' into chore/remove-urlencode
robertlipe Jan 24, 2026
7ca0128
Fix bad merge in network.cpp
robertlipe Jan 24, 2026
f4160c5
Test ENABLE_NTP after it's set in globals. Fixes atomlight, etc.
robertlipe Jan 24, 2026
d3792bb
Whitespace fix in network.cpp
robertlipe Jan 24, 2026
1498545
globals.h: avoid collision with ESPAsyncWebServer symbol introduces in
robertlipe Jan 24, 2026
d359e81
Patternsubscribers requires WIFI
robertlipe Jan 24, 2026
2a09787
Rename STR macros to avoid new conflict in new ESPAsync (ugh). Relax …
robertlipe Jan 24, 2026
3fe1d32
network.cpp needs systemcontainer even without WIFI
robertlipe Jan 24, 2026
0cedbb6
Adapt pattersubscribers to new espasync headers
robertlipe Jan 24, 2026
2517b45
actually commit the right fix for new Espasync macro conflict
robertlipe Jan 24, 2026
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);
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
6 changes: 5 additions & 1 deletion include/effects/matrix/PatternSubscribers.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
#ifndef PatternSub_H
#define PatternSub_H

#include <UrlEncode.h>
#if ENABLE_WIFI

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

extern const GFXfont Apple5x7 PROGMEM;
Expand Down Expand Up @@ -286,4 +288,6 @@ class PatternSubscribers : public EffectWithId<PatternSubscribers>
}
};

#endif // ENABLE_WIFI

#endif
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
2 changes: 2 additions & 0 deletions include/effects/strip/misceffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,10 @@ class StatusEffect : public EffectWithId<StatusEffect>
color = CRGB::Purple;
else if (!WiFi.isConnected())
color = CRGB::Red;
#if ENABLE_NTP
else if (!NTPTimeClient::HasClockBeenSet())
color = CRGB::Green;
#endif

if (_everyNth != 1)
fillSolidOnAllChannels(CRGB::Black);
Expand Down
50 changes: 43 additions & 7 deletions include/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@
#endif
#endif

#define XSTR(x) STR(x) // The defs will generate the stringized version of it
#define XSTR(x) ND_STR(x) // The defs will generate the stringized version of it
#if FLASH_VERSION > 99
#define STR(x) "v"#x
#define ND_STR(x) "v"#x
#else
#define STR(x) "v0"#x
#define ND_STR(x) "v0"#x
#endif
#define FLASH_VERSION_NAME_X(x) "v"#x
#define FLASH_VERSION_NAME XSTR(FLASH_VERSION)
Expand Down Expand Up @@ -261,20 +261,56 @@ extern RemoteDebug Debug; // Let everyone in the project know about it
#ifndef ENABLE_WIFI
#define ENABLE_WIFI 1 // Connect to WiFi
#endif

// Check for nonsensical network configurations
#if !ENABLE_WIFI
#if defined(ENABLE_WEBSERVER) && ENABLE_WEBSERVER
#error "ENABLE_WEBSERVER requires ENABLE_WIFI"
#endif
#if defined(ENABLE_NTP) && ENABLE_NTP
#error "ENABLE_NTP requires ENABLE_WIFI"
#endif
#if defined(ENABLE_OTA) && ENABLE_OTA
#error "ENABLE_OTA requires ENABLE_WIFI"
#endif
#if defined(INCOMING_WIFI_ENABLED) && INCOMING_WIFI_ENABLED
#error "INCOMING_WIFI_ENABLED requires ENABLE_WIFI"
#endif
#if defined(COLORDATA_SERVER_ENABLED) && COLORDATA_SERVER_ENABLED
#error "COLORDATA_SERVER_ENABLED requires ENABLE_WIFI"
#endif
#endif

#ifndef INCOMING_WIFI_ENABLED
#define INCOMING_WIFI_ENABLED 1 // Accepting incoming color data and commands
#if ENABLE_WIFI
#define INCOMING_WIFI_ENABLED 1 // Accepting incoming color data and commands
#else
#define INCOMING_WIFI_ENABLED 0
#endif
#endif
#ifndef TIME_BEFORE_LOCAL
#define TIME_BEFORE_LOCAL 1 // How many seconds before the lamp times out and shows local content
#endif
#ifndef ENABLE_NTP
#define ENABLE_NTP 1 // Set the clock from the web
#if ENABLE_WIFI
#define ENABLE_NTP 1 // Set the clock from the web
#else
#define ENABLE_NTP 0
#endif
#endif
#ifndef ENABLE_OTA
#define ENABLE_OTA 1
#if ENABLE_WIFI
#define ENABLE_OTA 1
#else
#define ENABLE_OTA 0
#endif
#endif
#ifndef ENABLE_WEBSERVER
#define ENABLE_WEBSERVER 1 // Turn on the internal webserver
#if ENABLE_WIFI
#define ENABLE_WEBSERVER 1 // Turn on the internal webserver
#else
#define ENABLE_WEBSERVER 0
#endif
#endif

#ifndef LED_PIN0
Expand Down
3 changes: 0 additions & 3 deletions include/network.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,9 @@
CompileTimeCreds = 1
};

void processRemoteDebugCmd();

WiFiConnectResult ConnectToWiFi(const String& ssid, const String& password);
WiFiConnectResult ConnectToWiFi(const String* ssid, const String* password);
void UpdateNTPTime();
void SetupOTA(const String & strHostname);
bool ReadWiFiConfig(WifiCredSource source, String& WiFi_ssid, String& WiFi_password);
bool WriteWiFiConfig(WifiCredSource source, const String& WiFi_ssid, const String& WiFi_password);
bool ClearWiFiConfig(WifiCredSource source);
Expand Down
6 changes: 2 additions & 4 deletions include/ntptimeclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#pragma once

#if ENABLE_NTP
#include <sys/cdefs.h>
#include <sys/time.h>
#include <ctime>
Expand Down Expand Up @@ -59,10 +60,7 @@ class NTPTimeClient
}

static bool UpdateClockFromWeb(WiFiUDP * pUDP);

static void ShowUptime();
};



#endif // ENABLE_NTP

3 changes: 3 additions & 0 deletions include/webserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@

#pragma once

#if ENABLE_WEBSERVER

#include "deviceconfig.h"
#include "network.h"

Expand Down Expand Up @@ -238,3 +240,4 @@ inline CWebServer::StatisticsType operator&(CWebServer::StatisticsType lhs, CWeb
// Set value in lambda using a forwarding function. Reports success based on function's return value,
// which must be implicitly convertable to bool
#define CONFIRM_VALUE(functionCall) [&](auto value)->bool { return functionCall; }
#endif // ENABLE_WEBSERVER
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
37 changes: 37 additions & 0 deletions src/debug_cli.cpp
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'll pretend I didn't see this feature being snuck in with the UrlEncode refactor. ;)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thank you for the integration.

Moving uptime, unchanged, from a file that was networking (where it used to live because debug stuff was entangled with network stuff) to a file that is home for debugging was not a new feature and was not sneaky. It was a very deliberate change as part of making ENABLE_WIFI (which clearly otherwise applies to networking.cc) honest, as it required that method to be rehomed so it could still be available even in builds without ENABLE_WIFI, as this is useful over the console port.

I landed DoUptime back in 2023 in #402 because when running long times for leaks or stability testing, I want to see that it's been running a long time and didn't crash or reboot minutes before I walked back into the room. Even then we noted it was an awkward fit

But agreed that this PR morphed from "don't download and install a 20 line function 50 times" to make ENABLE_WIFI (and related networking #defines) actually bracket when they claim to bracket. That was me taking your request to its conclusion.

Copy link
Collaborator

Choose a reason for hiding this comment

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

...which I appreciate. In any case, the comment was mainly about the addition of the "uptime" command to the CLI command set. To which you may say "are you serious?", to which I would reply "no, that's why I approved and merged."

I think the PR adds a number of sanity checks/extra safeguards to a complicated area of the codebase (anything networking), which is unequivocally a good thing to do. So, thank you for it!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

But uptime wasn't added. It was added in 2023. It was moved from one file to another.

Are we talking past each other?

But, yeah, this definitely ballooned, but leaves it better than we found it.

Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,42 @@ static void DoCat(const cli_argv &argv)
file.close();
}

void DoUptime(const cli_argv &)
{
struct timeval timeval = { 0 };
// Microseconds since boot. File wrap bugreport in 292 million years.
auto uptime = esp_timer_get_time();

timeval.tv_sec = uptime / MICROS_PER_SECOND;

char buf[128];
struct tm *tm = gmtime(&timeval.tv_sec);
// No, I don't care about leap seconds.
strftime(buf, sizeof(buf), "%X", tm);
int ndays = timeval.tv_sec / (24 * 60 * 60);
cli_printf("Uptime: %d days - %s\n", ndays, buf);

const char* reason_text = "Unknown";
esp_reset_reason_t reason = esp_reset_reason();
switch (reason)
{
case ESP_RST_POWERON: reason_text = "Power On"; break;
case ESP_RST_EXT: reason_text = "External Pin"; break;
case ESP_RST_SW: reason_text = "Software Restart"; break;
case ESP_RST_PANIC: reason_text = "Panic"; break;
case ESP_RST_INT_WDT: reason_text = "Watchdog barked"; break;
case ESP_RST_TASK_WDT: reason_text = "Task Watchdog barked"; break;
case ESP_RST_WDT: reason_text = "Other Watchdog barked"; break;
case ESP_RST_DEEPSLEEP: reason_text = "Reset in deep sleep"; break;
case ESP_RST_BROWNOUT: reason_text = "Brownout"; break;
case ESP_RST_SDIO: reason_text = "Reset over SDIO"; break;
// Documented, but not defined in ESP-IDF esp_system.h (v5.1.0) yet.
// case ESP_RST_USB: reason_text = "Reset by USB peripheral"; break;
default: reason_text = "Unknown"; break;
}
cli_printf("Last boot reason: (%d): %s\n", reason, reason_text);
}

static const command core_commands[] = {
{"cat", "Display file content", "Printing file...", DoCat},
{"reboot", "Reboot system", "Rebooting. Please stand by...", [](const cli_argv &) { esp_restart(); }},
Expand Down Expand Up @@ -567,6 +603,7 @@ static const command core_commands[] = {
g_ptrSystem->DeviceConfig().SetBrightness(val);
cli_printf("Brightness: %d\n", val);
}},
{"uptime", "Show system uptime", "Showing uptime...", DoUptime},
{"help", "Display command line options", "Displaying system help",
PrintHelp} // Function pointer logic requires PrintHelp signature match. It does.
};
Expand Down
2 changes: 2 additions & 0 deletions src/deviceconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ bool DeviceConfig::SetTimeZone(const String& newTimeZone, bool skipWrite)
return true;
}

#if ENABLE_WIFI
DeviceConfig::ValidateResponse DeviceConfig::ValidateOpenWeatherAPIKey(const String &newOpenWeatherAPIKey)
{
HTTPClient http;
Expand Down Expand Up @@ -142,6 +143,7 @@ DeviceConfig::ValidateResponse DeviceConfig::ValidateOpenWeatherAPIKey(const Str
}
}
}
#endif // ENABLE_WIFI

void DeviceConfig::SetColorSettings(const CRGB& newGlobalColor, const CRGB& newSecondColor)
{
Expand Down
4 changes: 4 additions & 0 deletions src/drawing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ uint16_t WiFiDraw()
if (false == bufferManager.IsEmpty())
{
std::shared_ptr<LEDBuffer> pBuffer;
#if ENABLE_NTP
if (NTPTimeClient::HasClockBeenSet() == false)
{
pBuffer = bufferManager.GetOldestBuffer();
Expand All @@ -81,6 +82,9 @@ uint16_t WiFiDraw()
while (!bufferManager.IsEmpty() && bufferManager.PeekOldestBuffer()->IsBufferOlderThan(tv))
pBuffer = bufferManager.GetOldestBuffer();
}
#else
pBuffer = bufferManager.GetOldestBuffer();
#endif

if (pBuffer)
{
Expand Down
4 changes: 3 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,8 +550,10 @@ void setup()
taskManager.StartColorDataThread();
taskManager.StartSocketThread();


#if ENABLE_WIFI
DebugCLI::InitDebugCLI();
InitNetworkCLI();
#endif

SaveEffectManagerConfig();
// Start the main loop
Expand Down
Loading