add http_api

This commit is contained in:
Stephan Mühl
2023-03-31 14:29:48 +02:00
parent 249074d022
commit 1b4a5b2952
16 changed files with 1217 additions and 570 deletions

View File

@@ -620,6 +620,9 @@ void NotifyApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state)
DisplayManager.getInstance().resetTextColor();
}
//Unattractive to have a function for every customapp wich does the same, but currently still no other option found TODO
void CApp1(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstApp, bool lastApp)
{
String name = getAppNameByFunction(CApp1);
@@ -680,6 +683,66 @@ void CApp10(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, i
ShowCustomApp(name, matrix, state, x, y, firstApp, lastApp);
}
void CApp11(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstApp, bool lastApp)
{
String name = getAppNameByFunction(CApp11);
ShowCustomApp(name, matrix, state, x, y, firstApp, lastApp);
}
void CApp12(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstApp, bool lastApp)
{
String name = getAppNameByFunction(CApp12);
ShowCustomApp(name, matrix, state, x, y, firstApp, lastApp);
}
void CApp13(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstApp, bool lastApp)
{
String name = getAppNameByFunction(CApp13);
ShowCustomApp(name, matrix, state, x, y, firstApp, lastApp);
}
void CApp14(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstApp, bool lastApp)
{
String name = getAppNameByFunction(CApp14);
ShowCustomApp(name, matrix, state, x, y, firstApp, lastApp);
}
void CApp15(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstApp, bool lastApp)
{
String name = getAppNameByFunction(CApp15);
ShowCustomApp(name, matrix, state, x, y, firstApp, lastApp);
}
void CApp16(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstApp, bool lastApp)
{
String name = getAppNameByFunction(CApp16);
ShowCustomApp(name, matrix, state, x, y, firstApp, lastApp);
}
void CApp17(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstApp, bool lastApp)
{
String name = getAppNameByFunction(CApp17);
ShowCustomApp(name, matrix, state, x, y, firstApp, lastApp);
}
void CApp18(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstApp, bool lastApp)
{
String name = getAppNameByFunction(CApp18);
ShowCustomApp(name, matrix, state, x, y, firstApp, lastApp);
}
void CApp19(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstApp, bool lastApp)
{
String name = getAppNameByFunction(CApp19);
ShowCustomApp(name, matrix, state, x, y, firstApp, lastApp);
}
void CApp20(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstApp, bool lastApp)
{
String name = getAppNameByFunction(CApp20);
ShowCustomApp(name, matrix, state, x, y, firstApp, lastApp);
}
const uint16_t *getWeatherIcon(int code)
{
switch (code)

View File

@@ -13,6 +13,7 @@
#include "ServerManager.h"
#include "MenuManager.h"
#include "Apps.h"
#include "Dictionary.h"
Ticker AlarmTicker;
Ticker TimerTicker;
@@ -214,7 +215,7 @@ void pushCustomApp(String name, int position)
if (customApps.count(name) == 0)
{
++customPagesCount;
void (*customApps[10])(FastLED_NeoMatrix *, MatrixDisplayUiState *, int16_t, int16_t, bool, bool) = {CApp1, CApp2, CApp3, CApp4, CApp5, CApp6, CApp7, CApp8, CApp9, CApp10};
void (*customApps[20])(FastLED_NeoMatrix *, MatrixDisplayUiState *, int16_t, int16_t, bool, bool) = {CApp1, CApp2, CApp3, CApp4, CApp5, CApp6, CApp7, CApp8, CApp9, CApp10, CApp11, CApp12, CApp13, CApp14, CApp15, CApp16, CApp17, CApp18, CApp19, CApp20};
if (position < 0) // Insert at the end of the vector
{
@@ -230,6 +231,7 @@ void pushCustomApp(String name, int position)
}
ui.setApps(Apps); // Add Apps
DisplayManager.getInstance().setAutoTransition(true);
}
}
@@ -714,4 +716,146 @@ void DisplayManager_::drawBarChart(int16_t x, int16_t y, const int data[], byte
int y1 = min(8 - barHeight, 7);
matrix.fillRect(x1, y1 + y, barWidth, barHeight, color);
}
}
}
void DisplayManager_::updateAppVector(const char *json)
{
// Parse the JSON input
DynamicJsonDocument doc(1024);
auto error = deserializeJson(doc, json);
if (error)
{
// If parsing fails, print an error message and return
Serial.print("Failed to parse JSON: ");
Serial.println(error.c_str());
return;
}
// Create new vectors to store updated apps
std::vector<std::pair<String, AppCallback>> newApps;
std::vector<String> activeApps;
// Loop through all apps in the JSON input
for (const auto &app : doc.as<JsonArray>())
{
// Get the app name, active status, and position (if specified)
String name = app["name"].as<String>();
bool show = true;
int position = -1;
if (app.containsKey("show"))
{
show = app["show"].as<bool>();
}
if (app.containsKey("pos"))
{
position = app["pos"].as<int>();
}
// Find the corresponding AppCallback function based on the app name
AppCallback callback;
if (name == "time")
{
callback = TimeApp;
SHOW_TIME = show;
}
else if (name == "date")
{
callback = DateApp;
SHOW_DATE = show;
}
else if (name == "temp")
{
callback = TempApp;
SHOW_TEMP = show;
}
else if (name == "hum")
{
callback = HumApp;
SHOW_HUM = show;
}
else if (name == "bat")
{
callback = BatApp;
SHOW_BAT = show;
}
else
{
// If the app is not one of the built-in apps, check if it's already in the vector
int appIndex = findAppIndexByName(name);
if (appIndex >= 0)
{
// The app is in the vector, so we can move it to a new position or remove it
auto it = Apps.begin() + appIndex;
if (show)
{
if (position >= 0 && static_cast<size_t>(position) < newApps.size())
{
Apps.erase(it);
newApps.insert(newApps.begin() + position, std::make_pair(name, it->second));
}
}
else
{
// If the app is being removed, also remove it from the customApps map
if (customApps.count(name))
{
customApps.erase(customApps.find(name));
removeCustomApp(name);
}
}
}
continue;
}
if (show)
{
// Add the app to the new vector
if (position >= 0 && static_cast<size_t>(position) < newApps.size())
{
newApps.insert(newApps.begin() + position, std::make_pair(name, callback));
}
else
{
newApps.emplace_back(name, callback);
}
}
activeApps.push_back(name);
}
// Loop through all apps currently in the vector
for (const auto &app : Apps)
{
// If the app is not in the updated activeApps vector, add it to the newApps vector
if (std::find(activeApps.begin(), activeApps.end(), app.first) == activeApps.end())
{
newApps.push_back(app);
}
}
// Update the apps vector, set it in the UI, and save settings
Apps = std::move(newApps);
ui.setApps(Apps);
saveSettings();
}
String DisplayManager_::getStat()
{
StaticJsonDocument<200> doc;
char buffer[5];
doc[BatKey] = BATTERY_PERCENT;
doc[BatRawKey] = BATTERY_RAW;
snprintf(buffer, 5, "%.0f", CURRENT_LUX);
doc[LuxKey] = buffer;
doc[LDRRawKey] = LDR_RAW;
doc[BrightnessKey] = BRIGHTNESS;
snprintf(buffer, 5, "%.0f", CURRENT_TEMP);
doc[TempKey] = buffer;
snprintf(buffer, 5, "%.0f", CURRENT_HUM);
doc[HumKey] = buffer;
doc[UpTimeKey] = PeripheryManager.readUptime();
doc[SignalStrengthKey] = WiFi.RSSI();
String jsonString;
serializeJson(doc, jsonString);
return jsonString;
}

View File

@@ -56,7 +56,9 @@ public:
void drawProgressBar(int cur, int total);
void drawMenuIndicator(int cur, int total, uint16_t color);
void drawBMP(int16_t x, int16_t y, const uint16_t bitmap[], int16_t w, int16_t h);
void drawBarChart(int16_t x, int16_t y,const int data[], byte dataSize, bool withIcon, uint16_t color);
void drawBarChart(int16_t x, int16_t y, const int data[], byte dataSize, bool withIcon, uint16_t color);
void updateAppVector(const char *json);
String getStat();
};
extern DisplayManager_ &DisplayManager;

View File

@@ -1,6 +1,8 @@
#include "Globals.h"
#include "Preferences.h"
#include <WiFi.h>
#include <ArduinoJson.h>
#include <LittleFS.h>
Preferences Settings;
@@ -13,8 +15,48 @@ char *getID()
return macStr;
}
void startLittleFS()
{
if (LittleFS.begin())
{
LittleFS.mkdir("/MELODIES");
LittleFS.mkdir("/ICONS");
}
else
{
Serial.println("ERROR on mounting LittleFS. It will be formmatted!");
LittleFS.format();
ESP.restart();
}
}
void loadDevSettings()
{
Serial.println("laodSettings");
File file = LittleFS.open("/dev.json", "r");
if (!file)
{
return;
}
DynamicJsonDocument doc(128);
DeserializationError error = deserializeJson(doc, file);
if (error)
{
Serial.println(F("Failed to read dev settings"));
return;
}
if (doc.containsKey("bootsound"))
{
BOOT_SOUND = doc["bootsound"].as<String>();
}
file.close();
}
void loadSettings()
{
startLittleFS();
Settings.begin("awtrix", false);
MATRIX_FPS = Settings.getUChar("FPS", 23);
BRIGHTNESS = Settings.getUChar("BRI", 120);
@@ -32,9 +74,11 @@ void loadSettings()
SHOW_TEMP = Settings.getBool("TEMP", true);
SHOW_HUM = Settings.getBool("HUM", true);
SHOW_BAT = Settings.getBool("BAT", true);
SOUND_ACTIVE = Settings.getBool("SOUND", true);
Settings.end();
uniqueID = getID();
MQTT_PREFIX = String(uniqueID);
loadDevSettings();
}
void saveSettings()
@@ -56,6 +100,7 @@ void saveSettings()
Settings.putBool("TEMP", SHOW_TEMP);
Settings.putBool("HUM", SHOW_HUM);
Settings.putBool("BAT", SHOW_BAT);
Settings.putBool("SOUND", SOUND_ACTIVE);
Settings.end();
}
@@ -122,4 +167,6 @@ bool AP_MODE;
bool MATRIX_OFF;
bool TIMER_ACTIVE;
bool ALARM_ACTIVE;
uint16_t TEXTCOLOR_565 = 0xFFFF;
uint16_t TEXTCOLOR_565 = 0xFFFF;
bool SOUND_ACTIVE;
String BOOT_SOUND = "";

View File

@@ -62,7 +62,8 @@ extern String TIME_FORMAT;
extern String DATE_FORMAT;
extern bool START_ON_MONDAY;
extern bool IS_CELSIUS;
extern bool SOUND_ACTIVE;
extern String BOOT_SOUND;
void loadSettings();
void saveSettings();
#endif // Globals_H

View File

@@ -6,8 +6,7 @@
#include <WiFi.h>
#include <ArduinoJson.h>
#include "Dictionary.h"
unsigned long startTime;
#include "PeripheryManager.h"
WiFiClient espClient;
uint8_t lastBrightness;
@@ -193,16 +192,24 @@ void onMqttMessage(const char *topic, const uint8_t *payload, uint16_t length)
void onMqttConnected()
{
String prefix = MQTT_PREFIX;
mqtt.subscribe((prefix + String("/brightness")).c_str());
mqtt.subscribe((prefix + String("/notify/dismiss")).c_str());
mqtt.subscribe((prefix + String("/notify")).c_str());
mqtt.subscribe((prefix + String("/timer")).c_str());
mqtt.subscribe((prefix + String("/custom/#")).c_str());
mqtt.subscribe((prefix + String("/switch")).c_str());
mqtt.subscribe((prefix + String("/settings")).c_str());
mqtt.subscribe((prefix + String("/previousapp")).c_str());
mqtt.subscribe((prefix + String("/nextapp")).c_str());
Serial.println("MQTT Connected");
const char *topics[] PROGMEM = {
"/brightness",
"/notify/dismiss",
"/notify",
"/timer",
"/custom/#",
"/switch",
"/settings",
"/previousapp",
"/nextapp",
"/nextapp",
"/apps"};
for (const char *topic : topics)
{
String fullTopic = prefix + topic;
mqtt.subscribe(fullTopic.c_str());
}
Serial.println(F("MQTT Connected"));
}
void connect()
@@ -227,7 +234,7 @@ char btnAID[40], btnBID[40], btnCID[40], appID[40], tempID[40], humID[40], luxID
void MQTTManager_::setup()
{
startTime = millis();
if (HA_DISCOVERY)
{
Serial.println(F("Starting Homeassistant discorvery"));
@@ -242,6 +249,9 @@ void MQTTManager_::setup()
device.setManufacturer(HAmanufacturer);
device.setModel(HAmodel);
device.setAvailability(true);
device.enableSharedAvailability();
device.enableLastWill();
String uniqueIDWithSuffix;
@@ -396,22 +406,6 @@ void MQTTManager_::setCurrentApp(String value)
curApp->setValue(value.c_str());
}
const char *readUptime()
{
static char uptime[25]; // Make the array static to keep it from being destroyed when the function returns
unsigned long currentTime = millis();
unsigned long elapsedTime = currentTime - startTime;
unsigned long uptimeSeconds = elapsedTime / 1000;
unsigned long uptimeMinutes = uptimeSeconds / 60;
unsigned long uptimeHours = uptimeMinutes / 60;
unsigned long uptimeDays = uptimeHours / 24;
unsigned long hours = uptimeHours % 24;
unsigned long minutes = uptimeMinutes % 60;
unsigned long seconds = uptimeSeconds % 60;
sprintf(uptime, "P%dDT%dH%dM%dS", uptimeDays, hours, minutes, seconds);
return uptime;
}
void MQTTManager_::sendStats()
{
if (HA_DISCOVERY)
@@ -442,7 +436,7 @@ void MQTTManager_::sendStats()
int freeHeapBytes = ESP.getFreeHeap();
itoa(freeHeapBytes, rambuffer, 10);
ram->setValue(rambuffer);
uptime->setValue(readUptime());
uptime->setValue(PeripheryManager.readUptime());
version->setValue(VERSION);
transition->setState(AUTO_TRANSITION, false);
}
@@ -450,23 +444,7 @@ void MQTTManager_::sendStats()
{
}
StaticJsonDocument<200> doc;
char buffer[5];
doc[BatKey] = BATTERY_PERCENT;
doc[BatRawKey] = BATTERY_RAW;
snprintf(buffer, 5, "%.0f", CURRENT_LUX);
doc[LuxKey] = buffer;
doc[LDRRawKey] = LDR_RAW;
doc[BrightnessKey] = BRIGHTNESS;
snprintf(buffer, 5, "%.0f", CURRENT_TEMP);
doc[TempKey] = buffer;
snprintf(buffer, 5, "%.0f", CURRENT_HUM);
doc[HumKey] = buffer;
doc[UpTimeKey] = readUptime();
doc[SignalStrengthKey] = WiFi.RSSI();
String jsonString;
serializeJson(doc, jsonString);
publish(StatsTopic, jsonString.c_str());
publish(StatsTopic, DisplayManager.getStat().c_str());
}
void MQTTManager_::sendButton(byte btn, bool state)

View File

@@ -26,6 +26,7 @@ enum MenuState
WeekdayMenu,
TempMenu,
Appmenu,
SoundMenu
};
const char *menuItems[] PROGMEM = {
@@ -40,10 +41,11 @@ const char *menuItems[] PROGMEM = {
"WEEKDAY",
"TEMP",
"APPS",
"SOUND",
"UPDATE"};
int8_t menuIndex = 0;
uint8_t menuItemCount = 12;
uint8_t menuItemCount = 13;
const char *timeFormat[] PROGMEM = {
"%H:%M:%S",
@@ -71,13 +73,6 @@ const char *dateFormat[] PROGMEM = {
int8_t dateFormatIndex;
uint8_t dateFormatCount = 9;
const char *appsItems[][2] PROGMEM = {
{"13", "time"},
{"1158", "date"},
{"234", "temp"},
{"2075", "hum"},
{"1486", "bat"}};
int8_t appsIndex;
uint8_t appsCount = 5;
@@ -129,6 +124,8 @@ String MenuManager_::menutext()
return "0x" + String(textColors[currentColor], HEX);
case SwitchMenu:
return AUTO_TRANSITION ? "ON" : "OFF";
case SoundMenu:
return SOUND_ACTIVE ? "ON" : "OFF";
case TspeedMenu:
return String(TIME_PER_TRANSITION / 1000.0, 1) + "s";
case AppTimeMenu:
@@ -231,6 +228,9 @@ void MenuManager_::rightButton()
case WeekdayMenu:
START_ON_MONDAY = !START_ON_MONDAY;
break;
case SoundMenu:
SOUND_ACTIVE = !SOUND_ACTIVE;
break;
case TempMenu:
IS_CELSIUS = !IS_CELSIUS;
break;
@@ -291,6 +291,9 @@ void MenuManager_::leftButton()
case TempMenu:
IS_CELSIUS = !IS_CELSIUS;
break;
case SoundMenu:
SOUND_ACTIVE = !SOUND_ACTIVE;
break;
default:
break;
}
@@ -342,6 +345,9 @@ void MenuManager_::selectButton()
currentState = Appmenu;
break;
case 11:
currentState = SoundMenu;
break;
case 12:
if (FirmwareVersionCheck())
{
updateFirmware();
@@ -424,6 +430,7 @@ void MenuManager_::selectButtonLong()
DATE_FORMAT = dateFormat[dateFormatIndex];
saveSettings();
case WeekdayMenu:
case SoundMenu:
case TempMenu:
saveSettings();
break;

View File

@@ -9,8 +9,6 @@
#include <LightDependentResistor.h>
#include <MenuManager.h>
#define SOUND_OFF true
#ifdef ULANZI
// Pinouts für das ULANZI-Environment
#define BATTERY_PIN 34
@@ -50,6 +48,7 @@ unsigned long previousMillis_LDR = 0;
const unsigned long interval_BatTempHum = 10000;
const unsigned long interval_LDR = 100;
int total = 0;
unsigned long startTime;
const int LDRReadings = 10;
int TotalLDRReadings[LDRReadings];
@@ -105,13 +104,21 @@ void select_button_tripple()
void PeripheryManager_::playBootSound()
{
if (SOUND_OFF)
if (!SOUND_ACTIVE)
return;
const int nNotes = 6;
String notes[nNotes] = {"E5", "C5", "G4", "E4", "G4", "C5"};
const int timeUnit = 150;
Melody melody = MelodyFactory.load("Nice Melody", timeUnit, notes, nNotes);
player.playAsync(melody);
if (BOOT_SOUND == "")
{
const int nNotes = 6;
String notes[nNotes] = {"E5", "C5", "G4", "E4", "G4", "C5"};
const int timeUnit = 150;
Melody melody = MelodyFactory.load("Bootsound", timeUnit, notes, nNotes);
player.playAsync(melody);
}
else
{
playFromFile("/MELODIES/" + BOOT_SOUND + ".txt");
}
}
void PeripheryManager_::stopSound()
@@ -121,7 +128,7 @@ void PeripheryManager_::stopSound()
void PeripheryManager_::playFromFile(String file)
{
if (SOUND_OFF)
if (!SOUND_ACTIVE)
return;
Melody melody = MelodyFactory.loadRtttlFile(file);
player.playAsync(melody);
@@ -148,6 +155,7 @@ void fistStart()
void PeripheryManager_::setup()
{
startTime = millis();
pinMode(LDR_PIN, INPUT);
pinMode(BUZZER_PIN, OUTPUT);
digitalWrite(BUZZER_PIN, LOW);
@@ -274,3 +282,20 @@ void PeripheryManager_::checkAlarms()
}
}
}
const char *PeripheryManager_::readUptime()
{
static char uptime[25]; // Make the array static to keep it from being destroyed when the function returns
unsigned long currentTime = millis();
unsigned long elapsedTime = currentTime - startTime;
unsigned long uptimeSeconds = elapsedTime / 1000;
unsigned long uptimeMinutes = uptimeSeconds / 60;
unsigned long uptimeHours = uptimeMinutes / 60;
unsigned long uptimeDays = uptimeHours / 24;
unsigned long hours = uptimeHours % 24;
unsigned long minutes = uptimeMinutes % 60;
unsigned long seconds = uptimeSeconds % 60;
sprintf(uptime, "P%dDT%dH%dM%dS", uptimeDays, hours, minutes, seconds);
return uptime;
}

View File

@@ -29,6 +29,7 @@ public:
void playFromFile(String file);
bool isPlaying();
void stopSound();
const char *readUptime();
};
extern PeripheryManager_ &PeripheryManager;

View File

@@ -13,22 +13,6 @@
WebServer server(80);
FSWebServer mws(LittleFS, server);
bool FSOPEN;
void startLittleFS()
{
if (LittleFS.begin())
{
LittleFS.mkdir("/MELODIES");
LittleFS.mkdir("/ICONS");
FSOPEN = true;
}
else
{
Serial.println("ERROR on mounting LittleFS. It will be formmatted!");
LittleFS.format();
ESP.restart();
}
}
// The getter for the instantiated singleton instance
ServerManager_ &ServerManager_::getInstance()
@@ -49,14 +33,90 @@ void versionHandler()
void saveHandler()
{
WebServerClass *webRequest = mws.getRequest();
Serial.println("Save");
ServerManager.getInstance().loadSettings();
webRequest->send(200);
}
void handlePostRequest()
{
WebServerClass *webRequest = mws.getRequest();
String url = webRequest->uri();
url.replace("/api", "");
if (webRequest->method() == HTTP_POST)
{
String body = webRequest->arg("plain");
const char *bodyPtr = body.c_str();
webRequest->send(200);
if (url == "/notify")
{
if (body[0] != '{' || body[strlen(bodyPtr) - 1] != '}')
{
webRequest->send(400, "text/plain", "Invalid payload format");
return;
}
DisplayManager.generateNotification(bodyPtr);
}
else if (url == "/timer")
{
DisplayManager.gererateTimer(bodyPtr);
}
else if (url == "/notify/dismiss")
{
DisplayManager.dismissNotify();
}
else if (url == "/apps")
{
DisplayManager.updateAppVector(bodyPtr);
}
else if (url == "/switch")
{
DisplayManager.switchToApp(bodyPtr);
}
else if (url == "/settings")
{
DisplayManager.setNewSettings(bodyPtr);
}
else if (url == "/nextapp")
{
DisplayManager.nextApp();
}
else if (url == "/previousapp")
{
DisplayManager.previousApp();
}
else if (url.startsWith("/custom"))
{
String topic_str = url.substring(MQTT_PREFIX.length() + 7);
DisplayManager.generateCustomPage(topic_str, bodyPtr);
}
else
{
webRequest->send(400);
}
}
else if (webRequest->method() == HTTP_GET)
{
if (url == "/stats")
{
webRequest->sendContent(DisplayManager.getStat());
}
else
{
webRequest->send(400);
}
}
}
void ServerManager_::setup()
{
if (!local_IP.fromString(NET_IP) || !gateway.fromString(NET_GW) || !subnet.fromString(NET_SN) || !primaryDNS.fromString(NET_PDNS) || !secondaryDNS.fromString(NET_SDNS))
NET_STATIC = false;
if (NET_STATIC)
@@ -69,6 +129,7 @@ void ServerManager_::setup()
if (isConnected)
{
mws.onNotFound(handlePostRequest);
mws.addOptionBox("Network");
mws.addOption("Static IP", NET_STATIC);
mws.addOption("Local IP", NET_IP);
@@ -96,7 +157,6 @@ void ServerManager_::setup()
mws.addHandler("/save", HTTP_GET, saveHandler);
}
mws.addHandler("/version", HTTP_GET, versionHandler);
mws.begin();
if (!MDNS.begin(uniqueID))
@@ -129,12 +189,10 @@ uint16_t stringToColor(const String &str)
String gStr = str.substring(comma1 + 1, comma2);
String bStr = str.substring(comma2 + 1);
int r = rStr.toInt();
int g = gStr.toInt();
int b = bStr.toInt();
if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255)
{
return 0xFFFF;
@@ -164,9 +222,6 @@ String colorToString(uint16_t color)
void ServerManager_::loadSettings()
{
if (!FSOPEN)
startLittleFS();
if (LittleFS.exists("/config.json"))
{
File file = LittleFS.open("/config.json", "r");

View File

@@ -14,7 +14,6 @@ public:
void tick();
void loadSettings();
bool isConnected;
void SaveSettings();
};
extern ServerManager_ &ServerManager;