Skip to content

Commit ffc8e1f

Browse files
committed
[C009] Reduce memory usage for C009 controller.
1 parent d6ec7aa commit ffc8e1f

File tree

2 files changed

+44
-48
lines changed

2 files changed

+44
-48
lines changed

src/_C009.ino

Lines changed: 44 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,13 @@ boolean CPlugin_009(byte function, struct EventStruct *event, String& string)
5959
{
6060
byte valueCount = getValueCountFromSensorType(event->sensorType);
6161
C009_queue_element element(event);
62-
if (ExtraTaskSettings.TaskIndex != event->TaskIndex)
63-
PluginCall(PLUGIN_GET_DEVICEVALUENAMES, event, dummyString);
6462

6563
MakeControllerSettings(ControllerSettings);
6664
LoadControllerSettings(event->ControllerIndex, ControllerSettings);
6765

6866
for (byte x = 0; x < valueCount; x++)
6967
{
7068
element.txt[x] = formatUserVarNoCheck(event, x);
71-
element.valueNames[x] = ExtraTaskSettings.TaskDeviceValueNames[x];
7269
}
7370
success = C009_DelayHandler.addToQueue(element);
7471
scheduleNextDelayQueue(TIMER_C009_DELAY_QUEUE, C009_DelayHandler.getNextScheduleTime());
@@ -86,55 +83,56 @@ bool do_process_c009_delay_queue(int controller_number, const C009_queue_element
8683
if (!try_connect_host(controller_number, client, ControllerSettings))
8784
return false;
8885

89-
// Create json root object
90-
DynamicJsonBuffer jsonBuffer;
91-
JsonObject& root = jsonBuffer.createObject();
92-
root[F("module")] = String(F("ESPEasy"));
93-
root[F("version")] = String(F("1.04"));
94-
95-
// Create nested objects
96-
JsonObject& data = root.createNestedObject(String(F("data")));
97-
JsonObject& ESP = data.createNestedObject(String(F("ESP")));
98-
ESP[F("name")] = Settings.Name;
99-
ESP[F("unit")] = Settings.Unit;
100-
ESP[F("version")] = Settings.Version;
101-
ESP[F("build")] = Settings.Build;
102-
ESP[F("build_notes")] = String(F(BUILD_NOTES));
103-
ESP[F("build_git")] = String(F(BUILD_GIT));
104-
ESP[F("node_type_id")] = NODE_TYPE_ID;
105-
ESP[F("sleep")] = Settings.deepSleep;
106-
107-
// embed IP, important if there is NAT/PAT
108-
// char ipStr[20];
109-
// IPAddress ip = WiFi.localIP();
110-
// sprintf_P(ipStr, PSTR("%u.%u.%u.%u"), ip[0], ip[1], ip[2], ip[3]);
111-
ESP[F("ip")] = WiFi.localIP().toString();
112-
113-
// Create nested SENSOR json object
114-
JsonObject& SENSOR = data.createNestedObject(String(F("SENSOR")));
115-
byte valueCount = getValueCountFromSensorType(element.sensorType);
116-
// char itemNames[valueCount][2];
117-
for (byte x = 0; x < valueCount; x++)
86+
LoadTaskSettings(element.TaskIndex);
87+
String jsonString;
11888
{
119-
// Each sensor value get an own object (0..n)
120-
// sprintf(itemNames[x],"%d",x);
121-
JsonObject& val = SENSOR.createNestedObject(String(x));
122-
val[F("deviceName")] = getTaskDeviceName(element.TaskIndex);
123-
val[F("valueName")] = element.valueNames[x];
124-
val[F("type")] = element.sensorType;
125-
val[F("value")] = element.txt[x];
89+
// Create json root object
90+
DynamicJsonBuffer jsonBuffer;
91+
JsonObject& root = jsonBuffer.createObject();
92+
root[F("module")] = String(F("ESPEasy"));
93+
root[F("version")] = String(F("1.04"));
94+
95+
// Create nested objects
96+
JsonObject& data = root.createNestedObject(String(F("data")));
97+
JsonObject& ESP = data.createNestedObject(String(F("ESP")));
98+
ESP[F("name")] = Settings.Name;
99+
ESP[F("unit")] = Settings.Unit;
100+
ESP[F("version")] = Settings.Version;
101+
ESP[F("build")] = Settings.Build;
102+
ESP[F("build_notes")] = String(F(BUILD_NOTES));
103+
ESP[F("build_git")] = String(F(BUILD_GIT));
104+
ESP[F("node_type_id")] = NODE_TYPE_ID;
105+
ESP[F("sleep")] = Settings.deepSleep;
106+
107+
// embed IP, important if there is NAT/PAT
108+
// char ipStr[20];
109+
// IPAddress ip = WiFi.localIP();
110+
// sprintf_P(ipStr, PSTR("%u.%u.%u.%u"), ip[0], ip[1], ip[2], ip[3]);
111+
ESP[F("ip")] = WiFi.localIP().toString();
112+
113+
// Create nested SENSOR json object
114+
JsonObject& SENSOR = data.createNestedObject(String(F("SENSOR")));
115+
byte valueCount = getValueCountFromSensorType(element.sensorType);
116+
// char itemNames[valueCount][2];
117+
for (byte x = 0; x < valueCount; x++)
118+
{
119+
// Each sensor value get an own object (0..n)
120+
// sprintf(itemNames[x],"%d",x);
121+
JsonObject& val = SENSOR.createNestedObject(String(x));
122+
val[F("deviceName")] = getTaskDeviceName(element.TaskIndex);
123+
val[F("valueName")] = ExtraTaskSettings.TaskDeviceValueNames[x];
124+
val[F("type")] = element.sensorType;
125+
val[F("value")] = element.txt[x];
126+
}
127+
128+
// Create json buffer
129+
root.printTo(jsonString);
126130
}
127131

128-
// Create json buffer
129-
String jsonString;
130-
root.printTo(jsonString);
131-
132132
// We now create a URI for the request
133-
String url = F("/ESPEasy");
134-
135133
String request = create_http_request_auth(
136134
controller_number, element.controller_idx, ControllerSettings,
137-
F("POST"), url, jsonString.length());
135+
F("POST"), F("/ESPEasy"), jsonString.length());
138136
request += jsonString;
139137

140138
return send_via_http(controller_number, client, request, ControllerSettings.MustCheckReply);

src/_CPlugin_Helper.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,11 @@ class C009_queue_element {
157157
size_t total = sizeof(this);
158158
for (int i = 0; i < VARS_PER_TASK; ++i) {
159159
total += txt[i].length();
160-
total += valueNames[i].length();
161160
}
162161
return total;
163162
}
164163

165164
String txt[VARS_PER_TASK];
166-
String valueNames[VARS_PER_TASK];
167165
int controller_idx;
168166
byte TaskIndex;
169167
int idx;

0 commit comments

Comments
 (0)