diff --git a/src/Sys/SysModWeb.cpp b/src/Sys/SysModWeb.cpp index e9b78013..4c0a693a 100644 --- a/src/Sys/SysModWeb.cpp +++ b/src/Sys/SysModWeb.cpp @@ -416,7 +416,7 @@ bool SysModWeb::addURL(const char * uri, const char * contentType, const char * request->send(LittleFS, path, contentType); } else { - USER_PRINT_Async("Webserver: addUrl %s %s csdata", uri, contentType); + USER_PRINT_Async("Webserver: addUrl %s %s csdata %d-%d (%s)", uri, contentType, content, len, request->url().c_str()); // if (handleIfNoneMatchCacheHeader(request)) return; diff --git a/src/User/UserModExample.h b/src/User/UserModExample.h index d044128c..ca6825f4 100644 --- a/src/User/UserModExample.h +++ b/src/User/UserModExample.h @@ -30,6 +30,12 @@ class UserModExample:public Module { // Module::loop(); } + void onOffChanged() { + if (SysModModules::isConnected && isEnabled) { + } else { + } + } + }; static UserModExample *example; \ No newline at end of file diff --git a/src/User/UserModInstances.h b/src/User/UserModInstances.h index 3510a244..797952d3 100644 --- a/src/User/UserModInstances.h +++ b/src/User/UserModInstances.h @@ -226,7 +226,7 @@ class UserModInstances:public Module { } void updateNode( UDPWLEDMessage udpMessage, char *body = nullptr) { - USER_PRINTF("Instance: %d.%d.%d.%d %s\n", udpMessage.ip0, udpMessage.ip1, udpMessage.ip2, udpMessage.ip3, udpMessage.name ); + USER_PRINTF("Instance: %d.%d.%d.%d n:%s b:%s\n", udpMessage.ip0, udpMessage.ip1, udpMessage.ip2, udpMessage.ip3, udpMessage.name, body ); if (body) { // const char *bump = reinterpret_cast(body); USER_PRINTF("body %s\n", body); @@ -239,8 +239,10 @@ class UserModInstances:public Module { found = true; node->timeStamp = millis(); //update timestamp strncpy(node->details, udpMessage.name, sizeof(node->details)-1); //update name (in case changed) - strncat(node->details, " ", sizeof(node->details)-1); - strncat(node->details, body, sizeof(node->details)-1); + if (body) { + strncat(node->details, " ", sizeof(node->details)-1); + strncat(node->details, body, sizeof(node->details)-1); + } } } diff --git a/src/User/UserModMDNS.h b/src/User/UserModMDNS.h new file mode 100644 index 00000000..9c235efc --- /dev/null +++ b/src/User/UserModMDNS.h @@ -0,0 +1,63 @@ +/* + @title StarMod + @file UserModMDNS.h + @date 20230810 + @repo https://github.com/ewowi/StarMod + @Authors https://github.com/ewowi/StarMod/commits/main + @Copyright (c) 2023 Github StarMod Commit Authors + @license GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 +*/ + +#include + +class UserModMDNS:public Module { + +public: + String escapedMac; + char cmDNS[64] = ""; + + UserModMDNS() :Module("MDNS") { + USER_PRINT_FUNCTION("%s %s\n", __PRETTY_FUNCTION__, name); + + USER_PRINT_FUNCTION("%s %s %s\n", __PRETTY_FUNCTION__, name, success?"success":"failed"); + }; + + //setup filesystem + void setup() { + Module::setup(); + USER_PRINT_FUNCTION("%s %s\n", __PRETTY_FUNCTION__, name); + + escapedMac = WiFi.macAddress(); + escapedMac.replace(":", ""); + escapedMac.toLowerCase(); + + sprintf(cmDNS, PSTR("wled-%*s"), 6, escapedMac.c_str() + 6); + // strncpy(cmDNS, "wled-98765", sizeof(cmDNS) -1); + + USER_PRINT_FUNCTION("%s %s %s\n", __PRETTY_FUNCTION__, name, success?"success":"failed"); + } + + void loop(){ + // Module::loop(); + } + + void onOffChanged() { + if (SysModModules::isConnected && isEnabled) { + + // print->fFormat(cmDNS, sizeof(cmDNS)-1, "wled-%*s", WiFi.macAddress().c_str() + 6); + + MDNS.end(); + MDNS.begin(cmDNS); + + USER_PRINTF("mDNS started %s -> %s -> %s\n", WiFi.macAddress().c_str(), escapedMac.c_str(), cmDNS); + MDNS.addService("http", "tcp", 80); + MDNS.addService("wled", "tcp", 80); + MDNS.addServiceTxt("wled", "tcp", "mac", escapedMac.c_str()); + } else { + MDNS.end(); + } + } + +}; + +static UserModMDNS *mdns; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 8badbcb5..3032ad5a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -23,6 +23,7 @@ #include "Sys/SysModNetwork.h" #include "Sys/SysModPins.h" #include "User/UserModInstances.h" +#include "User/UserModMDNS.h" #ifdef APPMOD_LEDS #include "App/AppModLeds.h" #include "App/AppModLedFixGen.h" @@ -56,6 +57,7 @@ void setup() { sys = new SysModSystem(); pins = new SysModPins(); instances = new UserModInstances(); + mdns = new UserModMDNS(); #ifdef APPMOD_LEDS lds = new AppModLeds(); lfg = new AppModLedFixGen(); @@ -109,6 +111,7 @@ void setup() { #ifdef USERMOD_WLEDAUDIO mdls->add(wledAudioMod); #endif + // mdls->add(mdns); //no ui //do not add mdls itself as it does setup and loop for itself!!! (it is the orchestrator) mdls->setup();