Skip to content

Commit 20d81c9

Browse files
committed
de-dupe define names
remove unused defines
1 parent c56de1a commit 20d81c9

File tree

5 files changed

+16
-19
lines changed

5 files changed

+16
-19
lines changed

lib/framework/MQTTSettingsService.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
#define MQTT_SETTINGS_FILE "/config/mqttSettings.json"
1111
#define MQTT_SETTINGS_SERVICE_PATH "/rest/mqttSettings"
1212

13-
#define MAX_MQTT_STATUS_SIZE 1024
14-
#define MQTT_STATUS_SERVICE_PATH "/rest/mqttStatus"
15-
1613
#define MQTT_SETTINGS_SERVICE_DEFAULT_ENABLED false
1714
#define MQTT_SETTINGS_SERVICE_DEFAULT_HOST "test.mosquitto.org"
1815
#define MQTT_SETTINGS_SERVICE_DEFAULT_PORT 1883

lib/framework/SettingsBroker.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <SettingsDeserializer.h>
77
#include <AsyncMqttClient.h>
88

9-
#define MAX_SETTINGS_SIZE 1024
9+
#define MAX_MESSAGE_SIZE 1024
1010
#define SETTINGS_BROKER_ORIGIN_ID "broker"
1111

1212
/**
@@ -70,7 +70,7 @@ class SettingsBroker {
7070
void publish() {
7171
if (_stateTopic.length() > 0 && _mqttClient->connected()) {
7272
// serialize to json doc
73-
DynamicJsonDocument json(MAX_SETTINGS_SIZE);
73+
DynamicJsonDocument json(MAX_MESSAGE_SIZE);
7474
_settingsService->read([&](T& settings) { _settingsSerializer->serialize(settings, json.to<JsonObject>()); });
7575

7676
// serialize to string
@@ -94,7 +94,7 @@ class SettingsBroker {
9494
}
9595

9696
// deserialize from string
97-
DynamicJsonDocument json(MAX_SETTINGS_SIZE);
97+
DynamicJsonDocument json(MAX_MESSAGE_SIZE);
9898
DeserializationError error = deserializeJson(json, payload, len);
9999
if (!error && json.is<JsonObject>()) {
100100
_settingsService->update(

lib/framework/SettingsEndpoint.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <SettingsSerializer.h>
1212
#include <SettingsDeserializer.h>
1313

14-
#define MAX_SETTINGS_SIZE 1024
14+
#define MAX_CONTENT_LENGTH 1024
1515
#define SETTINGS_ENDPOINT_ORIGIN_ID "endpoint"
1616

1717
template <class T>
@@ -37,7 +37,7 @@ class SettingsEndpoint {
3737
securityManager->wrapRequest(std::bind(&SettingsEndpoint::fetchSettings, this, std::placeholders::_1),
3838
authenticationPredicate));
3939
_updateHandler.setMethod(HTTP_POST);
40-
_updateHandler.setMaxContentLength(MAX_SETTINGS_SIZE);
40+
_updateHandler.setMaxContentLength(MAX_CONTENT_LENGTH);
4141
server->addHandler(&_updateHandler);
4242
}
4343

@@ -53,7 +53,7 @@ class SettingsEndpoint {
5353
std::bind(&SettingsEndpoint::updateSettings, this, std::placeholders::_1, std::placeholders::_2)) {
5454
server->on(servicePath.c_str(), HTTP_GET, std::bind(&SettingsEndpoint::fetchSettings, this, std::placeholders::_1));
5555
_updateHandler.setMethod(HTTP_POST);
56-
_updateHandler.setMaxContentLength(MAX_SETTINGS_SIZE);
56+
_updateHandler.setMaxContentLength(MAX_CONTENT_LENGTH);
5757
server->addHandler(&_updateHandler);
5858
}
5959

@@ -64,7 +64,7 @@ class SettingsEndpoint {
6464
AsyncCallbackJsonWebHandler _updateHandler;
6565

6666
void fetchSettings(AsyncWebServerRequest* request) {
67-
AsyncJsonResponse* response = new AsyncJsonResponse(false, MAX_SETTINGS_SIZE);
67+
AsyncJsonResponse* response = new AsyncJsonResponse(false, MAX_CONTENT_LENGTH);
6868
_settingsService->read(
6969
[&](T& settings) { _settingsSerializer->serialize(settings, response->getRoot().to<JsonObject>()); });
7070
response->setLength();
@@ -73,7 +73,7 @@ class SettingsEndpoint {
7373

7474
void updateSettings(AsyncWebServerRequest* request, JsonVariant& json) {
7575
if (json.is<JsonObject>()) {
76-
AsyncJsonResponse* response = new AsyncJsonResponse(false, MAX_SETTINGS_SIZE);
76+
AsyncJsonResponse* response = new AsyncJsonResponse(false, MAX_CONTENT_LENGTH);
7777

7878
// use callback to update the settings once the response is complete
7979
request->onDisconnect([this]() { _settingsService->callUpdateHandlers(SETTINGS_ENDPOINT_ORIGIN_ID); });

lib/framework/SettingsPersistence.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <SettingsDeserializer.h>
77
#include <FS.h>
88

9-
#define MAX_SETTINGS_SIZE 1024
9+
#define MAX_FILE_SIZE 1024
1010

1111
/**
1212
* SettingsPersistance takes care of loading and saving settings when they change.
@@ -34,8 +34,8 @@ class SettingsPersistence {
3434
File settingsFile = _fs->open(_filePath, "r");
3535

3636
if (settingsFile) {
37-
if (settingsFile.size() <= MAX_SETTINGS_SIZE) {
38-
DynamicJsonDocument jsonDocument = DynamicJsonDocument(MAX_SETTINGS_SIZE);
37+
if (settingsFile.size() <= MAX_FILE_SIZE) {
38+
DynamicJsonDocument jsonDocument = DynamicJsonDocument(MAX_FILE_SIZE);
3939
DeserializationError error = deserializeJson(jsonDocument, settingsFile);
4040
if (error == DeserializationError::Ok && jsonDocument.is<JsonObject>()) {
4141
readSettings(jsonDocument.as<JsonObject>());
@@ -53,7 +53,7 @@ class SettingsPersistence {
5353

5454
bool writeToFS() {
5555
// create and populate a new json object
56-
DynamicJsonDocument jsonDocument = DynamicJsonDocument(MAX_SETTINGS_SIZE);
56+
DynamicJsonDocument jsonDocument = DynamicJsonDocument(MAX_FILE_SIZE);
5757
_settingsService->read(
5858
[&](T& settings) { _settingsSerializer->serialize(settings, jsonDocument.to<JsonObject>()); });
5959

@@ -101,7 +101,7 @@ class SettingsPersistence {
101101
// We assume the readFromJsonObject supplies sensible defaults if an empty object
102102
// is supplied, this virtual function allows that to be changed.
103103
virtual void readDefaults() {
104-
DynamicJsonDocument jsonDocument = DynamicJsonDocument(MAX_SETTINGS_SIZE);
104+
DynamicJsonDocument jsonDocument = DynamicJsonDocument(MAX_FILE_SIZE);
105105
readSettings(jsonDocument.to<JsonObject>());
106106
}
107107
};

lib/framework/SettingsSocket.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <SettingsDeserializer.h>
77
#include <ESPAsyncWebServer.h>
88

9-
#define MAX_SIMPLE_MSG_SIZE 1024
9+
#define MAX_SETTINGS_SOCKET_MSG_SIZE 1024
1010

1111
#define SETTINGS_SOCKET_CLIENT_ID_MSG_SIZE 128
1212
#define SETTINGS_SOCKET_ORIGIN "socket"
@@ -67,7 +67,7 @@ class SettingsSocket {
6767
AwsFrameInfo* info = (AwsFrameInfo*)arg;
6868
if (info->final && info->index == 0 && info->len == len) {
6969
if (info->opcode == WS_TEXT) {
70-
DynamicJsonDocument jsonDocument = DynamicJsonDocument(MAX_SIMPLE_MSG_SIZE);
70+
DynamicJsonDocument jsonDocument = DynamicJsonDocument(MAX_SETTINGS_SOCKET_MSG_SIZE);
7171
DeserializationError error = deserializeJson(jsonDocument, (char*)data);
7272
if (!error && jsonDocument.is<JsonObject>()) {
7373
_settingsService->update(
@@ -104,7 +104,7 @@ class SettingsSocket {
104104
* simplifies the client and the server implementation but may not be sufficent for all use-cases.
105105
*/
106106
void transmitData(AsyncWebSocketClient* client, String originId) {
107-
DynamicJsonDocument jsonDocument = DynamicJsonDocument(MAX_SIMPLE_MSG_SIZE);
107+
DynamicJsonDocument jsonDocument = DynamicJsonDocument(MAX_SETTINGS_SOCKET_MSG_SIZE);
108108
JsonObject root = jsonDocument.to<JsonObject>();
109109
root["type"] = "payload";
110110
root["origin_id"] = originId;

0 commit comments

Comments
 (0)