Add mDNS resolution for network bus

This commit is contained in:
Blaz Kristan 2025-06-28 06:57:53 +02:00 committed by Blaž Kristan
parent a24420ae70
commit e7157e542a
6 changed files with 23 additions and 8 deletions

View File

@ -4,8 +4,9 @@
#include <Arduino.h> #include <Arduino.h>
#include <IPAddress.h> #include <IPAddress.h>
#include "src/dependencies/network/Network.h" // for isConnected() (& WiFi)
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
#include <ESPmDNS.h>
#include "src/dependencies/network/Network.h" // for isConnected() (& WiFi)
#include "driver/ledc.h" #include "driver/ledc.h"
#include "soc/ledc_struct.h" #include "soc/ledc_struct.h"
#if !(defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3)) #if !(defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3))
@ -26,6 +27,7 @@
#include "bus_wrapper.h" #include "bus_wrapper.h"
#include <bits/unique_ptr.h> #include <bits/unique_ptr.h>
extern char cmDNS[];
extern bool cctICused; extern bool cctICused;
extern bool useParallelI2S; extern bool useParallelI2S;

View File

@ -133,6 +133,7 @@ class Bus {
virtual uint16_t getUsedCurrent() const { return 0; } virtual uint16_t getUsedCurrent() const { return 0; }
virtual uint16_t getMaxCurrent() const { return 0; } virtual uint16_t getMaxCurrent() const { return 0; }
virtual size_t getBusSize() const { return sizeof(Bus); } virtual size_t getBusSize() const { return sizeof(Bus); }
virtual const String getCustomText() const { return String(); }
inline bool hasRGB() const { return _hasRgb; } inline bool hasRGB() const { return _hasRgb; }
inline bool hasWhite() const { return _hasWhite; } inline bool hasWhite() const { return _hasWhite; }
@ -215,7 +216,7 @@ class Bus {
uint8_t _autoWhiteMode; uint8_t _autoWhiteMode;
// global Auto White Calculation override // global Auto White Calculation override
static uint8_t _gAWM; static uint8_t _gAWM;
// _cct has the following menaings (see calculateCCT() & BusManager::setSegmentCCT()): // _cct has the following meanings (see calculateCCT() & BusManager::setSegmentCCT()):
// -1 means to extract approximate CCT value in K from RGB (in calcualteCCT()) // -1 means to extract approximate CCT value in K from RGB (in calcualteCCT())
// [0,255] is the exact CCT value where 0 means warm and 255 cold // [0,255] is the exact CCT value where 0 means warm and 255 cold
// [1900,10060] only for color correction expressed in K (colorBalanceFromKelvin()) // [1900,10060] only for color correction expressed in K (colorBalanceFromKelvin())
@ -375,8 +376,9 @@ struct BusConfig {
uint16_t frequency; uint16_t frequency;
uint8_t milliAmpsPerLed; uint8_t milliAmpsPerLed;
uint16_t milliAmpsMax; uint16_t milliAmpsMax;
String text;
BusConfig(uint8_t busType, uint8_t* ppins, uint16_t pstart, uint16_t len = 1, uint8_t pcolorOrder = COL_ORDER_GRB, bool rev = false, uint8_t skip = 0, byte aw=RGBW_MODE_MANUAL_ONLY, uint16_t clock_kHz=0U, uint8_t maPerLed=LED_MILLIAMPS_DEFAULT, uint16_t maMax=ABL_MILLIAMPS_DEFAULT) BusConfig(uint8_t busType, uint8_t* ppins, uint16_t pstart, uint16_t len = 1, uint8_t pcolorOrder = COL_ORDER_GRB, bool rev = false, uint8_t skip = 0, byte aw=RGBW_MODE_MANUAL_ONLY, uint16_t clock_kHz=0U, uint8_t maPerLed=LED_MILLIAMPS_DEFAULT, uint16_t maMax=ABL_MILLIAMPS_DEFAULT, String sometext = "")
: count(std::max(len,(uint16_t)1)) : count(std::max(len,(uint16_t)1))
, start(pstart) , start(pstart)
, colorOrder(pcolorOrder) , colorOrder(pcolorOrder)
@ -386,6 +388,7 @@ struct BusConfig {
, frequency(clock_kHz) , frequency(clock_kHz)
, milliAmpsPerLed(maPerLed) , milliAmpsPerLed(maPerLed)
, milliAmpsMax(maMax) , milliAmpsMax(maMax)
, text(sometext)
{ {
refreshReq = (bool) GET_BIT(busType,7); refreshReq = (bool) GET_BIT(busType,7);
type = busType & 0x7F; // bit 7 may be/is hacked to include refresh info (1=refresh in off state, 0=no refresh) type = busType & 0x7F; // bit 7 may be/is hacked to include refresh info (1=refresh in off state, 0=no refresh)

View File

@ -235,7 +235,8 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
} }
ledType |= refresh << 7; // hack bit 7 to indicate strip requires off refresh ledType |= refresh << 7; // hack bit 7 to indicate strip requires off refresh
busConfigs.emplace_back(ledType, pins, start, length, colorOrder, reversed, skipFirst, AWmode, freqkHz, maPerLed, maMax); String host = elm[F("text")] | String();
busConfigs.emplace_back(ledType, pins, start, length, colorOrder, reversed, skipFirst, AWmode, freqkHz, maPerLed, maMax, host);
doInitBusses = true; // finalization done in beginStrip() doInitBusses = true; // finalization done in beginStrip()
if (!Bus::isVirtual(ledType)) s++; // have as many virtual buses as you want if (!Bus::isVirtual(ledType)) s++; // have as many virtual buses as you want
} }
@ -379,7 +380,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
DEBUG_PRINTF_P(PSTR("PIN ALLOC error: GPIO%d for touch button #%d is not a touch pin!\n"), btnPin[s], s); DEBUG_PRINTF_P(PSTR("PIN ALLOC error: GPIO%d for touch button #%d is not a touch pin!\n"), btnPin[s], s);
btnPin[s] = -1; btnPin[s] = -1;
PinManager::deallocatePin(pin,PinOwner::Button); PinManager::deallocatePin(pin,PinOwner::Button);
} }
//if touch pin, enable the touch interrupt on ESP32 S2 & S3 //if touch pin, enable the touch interrupt on ESP32 S2 & S3
#ifdef SOC_TOUCH_VERSION_2 // ESP32 S2 and S3 have a function to check touch state but need to attach an interrupt to do so #ifdef SOC_TOUCH_VERSION_2 // ESP32 S2 and S3 have a function to check touch state but need to attach an interrupt to do so
else else
@ -976,6 +977,7 @@ void serializeConfig(JsonObject root) {
ins[F("freq")] = bus->getFrequency(); ins[F("freq")] = bus->getFrequency();
ins[F("maxpwr")] = bus->getMaxCurrent(); ins[F("maxpwr")] = bus->getMaxCurrent();
ins[F("ledma")] = bus->getLEDCurrent(); ins[F("ledma")] = bus->getLEDCurrent();
ins[F("text")] = bus->getCustomText();
} }
JsonArray hw_com = hw.createNestedArray(F("com")); JsonArray hw_com = hw.createNestedArray(F("com"));
@ -1340,4 +1342,4 @@ void serializeConfigSec() {
if (f) serializeJson(root, f); if (f) serializeJson(root, f);
f.close(); f.close();
releaseJSONBufferLock(); releaseJSONBufferLock();
} }

View File

@ -79,6 +79,9 @@ input {
input:disabled { input:disabled {
color: #888; color: #888;
} }
input:invalid {
color: #f00;
}
input[type="text"], input[type="text"],
input[type="number"], input[type="number"],
input[type="password"], input[type="password"],
@ -202,4 +205,4 @@ td {
#btns select { #btns select {
width: 144px; width: 144px;
} }
} }

View File

@ -141,6 +141,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
unsigned colorOrder, type, skip, awmode, channelSwap, maPerLed; unsigned colorOrder, type, skip, awmode, channelSwap, maPerLed;
unsigned length, start, maMax; unsigned length, start, maMax;
uint8_t pins[5] = {255, 255, 255, 255, 255}; uint8_t pins[5] = {255, 255, 255, 255, 255};
String text;
// this will set global ABL max current used when per-port ABL is not used // this will set global ABL max current used when per-port ABL is not used
unsigned ablMilliampsMax = request->arg(F("MA")).toInt(); unsigned ablMilliampsMax = request->arg(F("MA")).toInt();
@ -174,6 +175,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
char sp[4] = "SP"; sp[2] = offset+s; sp[3] = 0; //bus clock speed (DotStar & PWM) char sp[4] = "SP"; sp[2] = offset+s; sp[3] = 0; //bus clock speed (DotStar & PWM)
char la[4] = "LA"; la[2] = offset+s; la[3] = 0; //LED mA char la[4] = "LA"; la[2] = offset+s; la[3] = 0; //LED mA
char ma[4] = "MA"; ma[2] = offset+s; ma[3] = 0; //max mA char ma[4] = "MA"; ma[2] = offset+s; ma[3] = 0; //max mA
char hs[4] = "HS"; hs[2] = offset+s; hs[3] = 0; //hostname (for network types, custom text for others)
if (!request->hasArg(lp)) { if (!request->hasArg(lp)) {
DEBUG_PRINTF_P(PSTR("# of buses: %d\n"), s+1); DEBUG_PRINTF_P(PSTR("# of buses: %d\n"), s+1);
break; break;
@ -224,9 +226,10 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
maMax = request->arg(ma).toInt() * request->hasArg(F("PPL")); // if PP-ABL is disabled maMax (per bus) must be 0 maMax = request->arg(ma).toInt() * request->hasArg(F("PPL")); // if PP-ABL is disabled maMax (per bus) must be 0
} }
type |= request->hasArg(rf) << 7; // off refresh override type |= request->hasArg(rf) << 7; // off refresh override
text = request->arg(hs).substring(0,31);
// actual finalization is done in WLED::loop() (removing old busses and adding new) // actual finalization is done in WLED::loop() (removing old busses and adding new)
// this may happen even before this loop is finished so we do "doInitBusses" after the loop // this may happen even before this loop is finished so we do "doInitBusses" after the loop
busConfigs.emplace_back(type, pins, start, length, colorOrder | (channelSwap<<4), request->hasArg(cv), skip, awmode, freq, maPerLed, maMax); busConfigs.emplace_back(type, pins, start, length, colorOrder | (channelSwap<<4), request->hasArg(cv), skip, awmode, freq, maPerLed, maMax, text);
busesChanged = true; busesChanged = true;
} }
//doInitBusses = busesChanged; // we will do that below to ensure all input data is processed //doInitBusses = busesChanged; // we will do that below to ensure all input data is processed

View File

@ -311,6 +311,7 @@ void getSettingsJS(byte subPage, Print& settingsScript)
char sp[4] = "SP"; sp[2] = offset+s; sp[3] = 0; //bus clock speed char sp[4] = "SP"; sp[2] = offset+s; sp[3] = 0; //bus clock speed
char la[4] = "LA"; la[2] = offset+s; la[3] = 0; //LED current char la[4] = "LA"; la[2] = offset+s; la[3] = 0; //LED current
char ma[4] = "MA"; ma[2] = offset+s; ma[3] = 0; //max per-port PSU current char ma[4] = "MA"; ma[2] = offset+s; ma[3] = 0; //max per-port PSU current
char hs[4] = "HS"; hs[2] = offset+s; hs[3] = 0; //hostname (for network types, custom text for others)
settingsScript.print(F("addLEDs(1);")); settingsScript.print(F("addLEDs(1);"));
uint8_t pins[5]; uint8_t pins[5];
int nPins = bus->getPins(pins); int nPins = bus->getPins(pins);
@ -350,6 +351,7 @@ void getSettingsJS(byte subPage, Print& settingsScript)
printSetFormValue(settingsScript,sp,speed); printSetFormValue(settingsScript,sp,speed);
printSetFormValue(settingsScript,la,bus->getLEDCurrent()); printSetFormValue(settingsScript,la,bus->getLEDCurrent());
printSetFormValue(settingsScript,ma,bus->getMaxCurrent()); printSetFormValue(settingsScript,ma,bus->getMaxCurrent());
printSetFormValue(settingsScript,hs,bus->getCustomText().c_str());
sumMa += bus->getMaxCurrent(); sumMa += bus->getMaxCurrent();
} }
printSetFormValue(settingsScript,PSTR("MA"),BusManager::ablMilliampsMax() ? BusManager::ablMilliampsMax() : sumMa); printSetFormValue(settingsScript,PSTR("MA"),BusManager::ablMilliampsMax() ? BusManager::ablMilliampsMax() : sumMa);