Skip to content

Commit

Permalink
Merge remote-tracking branch 'ewowi/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
ewoudwijma committed Apr 5, 2024
2 parents a9a1b3a + 4f12da2 commit a64efbf
Show file tree
Hide file tree
Showing 14 changed files with 1,368 additions and 110 deletions.
58 changes: 1 addition & 57 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,59 +1,3 @@
# StarMod

Update April, 2024:
The LEDs part of [ewowi/StarMod](https://github.com/ewowi/StarMod) has been moved to [MoonModules/StarModLeds](https://github.com/MoonModules/StarModLeds). From now on:

* StarMod (Core) is a generic ESP32 platfom without any notion of LEDs
* StarMod LEDS is a fork of StarMod (Core) which adds LED functionality on top of it.
* StarMod (Core) can be forked by anyone who wants to build an ESP32 application
* Forks of StarMod (Core) should not change System functionality, changes on that should be done on StarMod (Core):
* Sys Modules
* Generic User Modules
* index.js / html / css
* platformio.ini
* The following should be changed on forks:
* App Modules
* main.cpp
* app.js
* Use Github issues for [StarMod (Core)](https://github.com/ewowi/StarMod/issues) or [StarMod Leds](https://github.com/MoonModules/StarModLeds/issues) respectively.


Headstart for building ESP32 applications: printing, file management, persistent data, Wifi, Web, UI and system management works out of the box.
StarMod will integrate with major IOT/network devices and applications.

Everything is a module.

System modules:

* Print: Print to different targets (Serial, file, net)
* Files: File Manager
* Model: Datamodel in json, stored to file, used in ui and network comms
* Network: Wifi
* Web: Web server
* UI: UI Server
* System: Show and manage ESP32 system

User Modules

* E131/DMX support
* Home Assistant (planned)
* LEDs
* ...

Build apps on top of this

* Led apps
* IO control apps
* IOT apps
* Any app

By [MoonModules](https://github.com/MoonModules)
LED module inspired by [WLED MM](https://github.com/MoonModules/WLED)

Disclaimer:

Using this software is the users responsibility as it is not bug free. Therefore contributors of this repo can not be held reliable for anything including but not limited to spontaneous combustion of the entire led strip, the house and the inevitable heat death of the universe

GPL V3 License:

You may copy, distribute and modify the software as long as you track changes/dates in source files. Any modifications to or software including (via compiler) GPL-licensed code must also be made available under the GPL along with build & install instructions ([tldrlegal](https://www.tldrlegal.com/license/gnu-general-public-license-v3-gpl-3))
See [StarDocs](https://ewowi.github.io/StarDocs/)
2 changes: 1 addition & 1 deletion src/Sys/SysModFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ bool SysModFiles::readObjectFromFile(const char* path, JsonDocument* dest) {
return false;
}
else {
USER_PRINTF(PSTR("File %s open to read, size %d bytes\n"), path, (int)f.size());
USER_PRINTF("File %s open to read, size %d bytes\n", path, (int)f.size());
DeserializationError error = deserializeJson(*dest, f, DeserializationOption::NestingLimit(20)); //StarMod requires more then 10
if (error) {
print->printJDocInfo("readObjectFromFile", *dest);
Expand Down
2 changes: 1 addition & 1 deletion src/Sys/SysModModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void SysModModel::setup() {
ui->initButton(parentVar, "deleteObsolete", false, [](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case f_UIFun:
ui->setLabel(var, "Delete obsolete variables");
ui->setComment(var, "WIP");
ui->setComment(var, "🚧");
return true;
// case f_ChangeFun:
// model->to<JsonArray>(); //create
Expand Down
5 changes: 1 addition & 4 deletions src/Sys/SysModNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,7 @@ void SysModNetwork::initConnection() {
WiFi.setTxPower(WIFI_POWER_8_5dBm );
#endif
WiFi.setSleep(false);
char hostname[25];
prepareHostname(hostname, mdl->getValue("instanceName"));
USER_PRINTF("hostname %s\n", hostname);
WiFi.setHostname(hostname);
WiFi.setHostname(mdns->cmDNS); //use the mdns name (instance name or star-mac)
}
else
USER_PRINTF("No SSID");
Expand Down
23 changes: 0 additions & 23 deletions src/Sys/SysModNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,6 @@ class SysModNetwork:public SysModule {

void loop1s();

//tbd: utility function ...
void prepareHostname(char* hostname, const char *in)
{
const char *pC = in;
uint8_t pos = 0;
while (*pC && pos < 24) { // while !null and not over length
if (isalnum(*pC)) { // if the current char is alpha-numeric append it to the hostname
hostname[pos] = *pC;
pos++;
} else if (*pC == ' ' || *pC == '_' || *pC == '-' || *pC == '+' || *pC == '!' || *pC == '?' || *pC == '*') {
hostname[pos] = '-';
pos++;
}
// else do nothing - no leading hyphens and do not include hyphens for all other characters.
pC++;
}
//last character must not be hyphen
if (pos > 5) {
while (pos > 4 && hostname[pos -1] == '-') pos--;
hostname[pos] = '\0'; // terminate string (leave at least "wled")
}
}

void handleConnection();
void initConnection();

Expand Down
2 changes: 1 addition & 1 deletion src/Sys/SysModPins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void SysModPins::setup() {
ui->initCanvas(parentVar, "board", UINT16_MAX, true, [](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case f_UIFun:
ui->setLabel(var, "Board layout");
ui->setComment(var, "WIP");
ui->setComment(var, "🚧");
return true;
case f_LoopFun:
var["interval"] = 10*10*10; //every 10 sec from cs to ms
Expand Down
4 changes: 2 additions & 2 deletions src/Sys/SysModPrint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void SysModPrint::setup() {
case f_UIFun:
{
ui->setLabel(var, "Output");
ui->setComment(var, "System log to Serial or Net print (WIP)");
ui->setComment(var, "🚧");

JsonArray options = ui->setOptions(var);
options.add("No");
Expand All @@ -73,7 +73,7 @@ void SysModPrint::setup() {
default: return false;
}});

ui->initTextArea(parentVar, "log", "WIP", true, [](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
ui->initTextArea(parentVar, "log", "🚧", true, [](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case f_UIFun:
ui->setComment(var, "Show the printed log");
return true;
Expand Down
25 changes: 17 additions & 8 deletions src/Sys/SysModSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include "SysModUI.h"
#include "SysModWeb.h"
#include "SysModModel.h"
#include "SysModNetwork.h"
#include "User/UserModMDNS.h"

// #include <Esp.h>

Expand Down Expand Up @@ -44,6 +46,13 @@ void SysModSystem::setup() {
ui->setLabel(var, "Name");
ui->setComment(var, "Instance name");
return true;
case f_ChangeFun:
char instanceName[25];
removeInvalidCharacters(instanceName, var["value"]);
USER_PRINTF("instanceName stripped %s\n", instanceName);
mdl->setValue(mdl->varID(var), JsonString(instanceName, JsonString::Copied));
mdns->resetMDNS(); // set the new name for mdns
return true;
default: return false;
}});

Expand Down Expand Up @@ -154,16 +163,16 @@ void SysModSystem::setup() {

//calculate version in format YYMMDDHH
//https://forum.arduino.cc/t/can-you-format-__date__/200818/10
int month, day, year, hour, minute, second;
const char month_names[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
sscanf(__DATE__, "%s %d %d", version, &day, &year); // Mon dd yyyy
month = (strstr(month_names, version)-month_names)/3+1;
sscanf(__TIME__, "%d:%d:%d", &hour, &minute, &second); //hh:mm:ss
print->fFormat(version, sizeof(version)-1, "%02d%02d%02d%02d", year-2000, month, day, hour);
// int month, day, year, hour, minute, second;
// const char month_names[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
// sscanf(__DATE__, "%s %d %d", version, &day, &year); // Mon dd yyyy
// month = (strstr(month_names, version)-month_names)/3+1;
// sscanf(__TIME__, "%d:%d:%d", &hour, &minute, &second); //hh:mm:ss
// print->fFormat(version, sizeof(version)-1, "%02d%02d%02d%02d", year-2000, month, day, hour);

USER_PRINTF("version %s %s %s %d:%d:%d\n", version, __DATE__, __TIME__, hour, minute, second);
// USER_PRINTF("version %s %s %s %d:%d:%d\n", version, __DATE__, __TIME__, hour, minute, second);

ui->initText(parentVar, "version", version, 16, true);
ui->initNumber(parentVar, "version", VERSION, UINT16_MAX, UINT16_MAX, true);
// ui->initText(parentVar, "date", __DATE__, 16, true);
// ui->initText(parentVar, "time", __TIME__, 16, true);

Expand Down
25 changes: 24 additions & 1 deletion src/Sys/SysModSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class SysModSystem:public SysModule {

public:
char version[16] = "";
// char version[16] = "";
char chipInfo[64] = "";

SysModSystem();
Expand All @@ -33,6 +33,29 @@ class SysModSystem:public SysModule {
int sysTools_get_arduino_maxStackUsage(void); // to query max used stack of the arduino task. returns "-1" if unknown
int sysTools_get_webserver_maxStackUsage(void); // to query max used stack of the webserver task. returns "-1" if unknown

//tbd: utility function ... (pka prepareHostname)
void removeInvalidCharacters(char* hostname, const char *in)
{
const char *pC = in;
uint8_t pos = 0;
while (*pC && pos < 24) { // while !null and not over length
if (isalnum(*pC)) { // if the current char is alpha-numeric append it to the hostname
hostname[pos] = *pC;
pos++;
} else if (*pC == ' ' || *pC == '_' || *pC == '-' || *pC == '+' || *pC == '!' || *pC == '?' || *pC == '*') {
hostname[pos] = '-';
pos++;
}
// else do nothing - no leading hyphens and do not include hyphens for all other characters.
pC++;
}
//last character must not be hyphen
if (pos > 5) {
while (pos > 4 && hostname[pos -1] == '-') pos--;
hostname[pos] = '\0'; // terminate string (leave at least "wled")
}
}

private:
unsigned long loopCounter = 0;

Expand Down
2 changes: 1 addition & 1 deletion src/Sys/SysModWeb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ void SysModWeb::serveIndex(WebRequest *request) {

WebResponse *response;
response = request->beginResponse_P(200, "text/html", PAGE_index, PAGE_index_L);
response->addHeader(FPSTR("Content-Encoding"),"gzip");
response->addHeader("Content-Encoding","gzip");
// setStaticContentCacheHeaders(response);
request->send(response);

Expand Down
2 changes: 2 additions & 0 deletions src/SysModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

#pragma once

#define VERSION 2024040511 //update for each build

//conventional (works)
// #define unsigned8 uint8_t
// #define unsigned16 uint16_t
Expand Down
2 changes: 1 addition & 1 deletion src/User/UserModInstances.h
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ class UserModInstances:public SysModule {
strncpy(starModMessage.header.name, instanceName?instanceName:"StarMod", sizeof(starModMessage.header.name)-1);
starModMessage.header.type = 32; //esp32 tbd: CONFIG_IDF_TARGET_ESP32S3 etc
starModMessage.header.insId = localIP[3]; //WLED: used in map of instances as index!
starModMessage.header.version = atoi(sys->version);
starModMessage.header.version = VERSION;
starModMessage.sys.type = 1; //StarMod
starModMessage.sys.upTime = millis()/1000;
starModMessage.sys.syncMaster = mdl->getValue("sma");
Expand Down
29 changes: 19 additions & 10 deletions src/User/UserModMDNS.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ class UserModMDNS:public SysModule {
escapedMac.replace(":", "");
escapedMac.toLowerCase();

sprintf(cmDNS, PSTR("star-%*s"), 6, escapedMac.c_str() + 6);
// strncpy(cmDNS, "wled-98765", sizeof(cmDNS) -1);
}

void loop() {
Expand All @@ -39,20 +37,31 @@ class UserModMDNS:public SysModule {
void onOffChanged() {
if (mdls->isConnected && isEnabled) {

// print->fFormat(cmDNS, sizeof(cmDNS)-1, "wled-%*s", WiFi.macAddress().c_str() + 6);
resetMDNS();

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("star", "tcp", 80);
MDNS.addServiceTxt("star", "tcp", "mac", escapedMac.c_str());
} else {
MDNS.end();
}
}

void resetMDNS() {

//reset cmDNS
const char * instanceName = mdl->getValue("instanceName");
if (strcmp(instanceName, "StarMod") == 0 )
sprintf(cmDNS, "star-%*s", 6, escapedMac.c_str() + 6);
else
strcpy(cmDNS, instanceName);

MDNS.end();
MDNS.begin(cmDNS);

USER_PRINTF("mDNS started %s -> %s\n", WiFi.macAddress().c_str(), cmDNS);
MDNS.addService("http", "tcp", 80);
MDNS.addService("star", "tcp", 80);
MDNS.addServiceTxt("star", "tcp", "mac", escapedMac.c_str());
}

};

extern UserModMDNS *mdns;
Loading

0 comments on commit a64efbf

Please sign in to comment.