Skip to content

Commit afca08a

Browse files
More Memory Improvements
1 parent ceeda18 commit afca08a

File tree

2 files changed

+53
-18
lines changed

2 files changed

+53
-18
lines changed

Sensatio_FW_ESP8266.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
SOURCE: https://github.com/sensate-io/firmware-esp8266.git
1212
1313
@section HISTORY
14+
v44 - More Memory Improvements
1415
v43 - Fixed data transmit issues in configurations with many sensors
1516
v42 - Fixed low memory issues in configurations with many sensors and a ST7735 Bug
1617
v41 - Changed IDE, Sensatio, Renamed Display Class to support more types
@@ -33,11 +34,11 @@
3334
VisualisationHelper* vHelper;
3435
Display* display = NULL;
3536

36-
int currentVersion = 43;
37+
int currentVersion = 44;
3738
boolean printMemory = false;
3839

3940
//String board = "Generic";
40-
//char firmwareType[] = "ESP8266";
41+
////char firmwareType[] = "ESP8266";
4142
// char firmwareType[] = "ESP8266-1M";
4243

4344
String board = "NodeMCU";
@@ -84,19 +85,27 @@ extern uint8_t i2cSDAPort;
8485
extern uint8_t i2cSCLPort;
8586
extern MQTT* mqtt;
8687

88+
extern String urlString;
89+
extern String requestDataString;
90+
extern String payload;
91+
8792
#define tickerInterval 250
8893
#define delayInterval 10000
8994

9095

9196
void setup()
9297
{
93-
Serial.begin(9600);
98+
Serial.begin(9600);
9499
Serial.println("---------------------------");
95100
Serial.println(variant);
96101
Serial.println("---------------------------");
97102
Serial.println("Startup: ");
98103
Serial.println(getUUID()); // @suppress("Invalid arguments")
99104

105+
urlString.reserve(300);
106+
requestDataString.reserve(200);
107+
payload.reserve(1000);
108+
100109
restoreBridgeConfig();
101110

102111
vHelper = new VisualisationHelper();

src/controller/Bridge.cpp

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
SOURCE: https://github.com/sensate-io/firmware-esp8266.git
1212
1313
@section HISTORY
14+
v44 - More Memory Improvements
1415
v43 - Fixed data transmit issues in configurations with many sensors
1516
v42 - Fixed low memory issues in configurations with many sensors and a ST7735 Bug
1617
v41 - Renamed Display Class to support more types
@@ -85,7 +86,6 @@ bool foundPorts = false;
8586

8687
String urlString;
8788
String requestDataString;
88-
String message;
8989
String payload;
9090

9191
std::unique_ptr<BearSSL::WiFiClientSecure>sslClient(new BearSSL::WiFiClientSecure);
@@ -881,7 +881,8 @@ void configurePort(int portNumber, JsonObject& portConfig) {
881881

882882
String port = portConfig["p"];
883883

884-
Serial.println("Configure Onboard Port:" + port);
884+
Serial.print("Configure Onboard Port:");
885+
Serial.println(port);
885886

886887
//portConfig.prettyPrintTo(Serial);
887888
Serial.println("");
@@ -969,7 +970,8 @@ void configurePort(int portNumber, JsonObject& portConfig) {
969970
uint8_t intPort = translateGPIOPort(port);
970971
if(intPort<999)
971972
{
972-
Serial.println("Setting up Digital Switch at Port: " + port);
973+
Serial.print("Setting up Digital Switch at Port: ");
974+
Serial.println(port);
973975
addSensor(new SensorDigitalSwitch(portConfig["id"], portConfig["c"], portConfig["sn"], portConfig["n"], intPort, refreshInterval, postDataInterval, calc));
974976
}
975977
}
@@ -1063,7 +1065,9 @@ void loopSensor(int currentTimeMs) {
10631065
if(!abortDelay)
10641066
{
10651067
int delayTime=100*retry;
1066-
Serial.println("Communication Issues - Retrying in "+String(delayTime)+"ms ");
1068+
Serial.print("Communication Issues - Retrying in ");
1069+
Serial.print(delayTime);
1070+
Serial.println("ms ");
10671071
yield();
10681072
delay(delayTime);
10691073
}
@@ -1106,7 +1110,8 @@ void trySleep(long microseconds)
11061110
{
11071111
loopDisplay(millis());
11081112
doPowerSaving();
1109-
Serial.println("Going to deep sleep for "+String(microseconds));
1113+
Serial.print("Going to deep sleep for ");
1114+
Serial.println(microseconds);
11101115
ESP.deepSleep(microseconds);
11111116
}
11121117
}
@@ -1115,7 +1120,8 @@ void doPowerSaving() {
11151120

11161121
if(powerSavePort!=NULL && !powerSavePort.length()>0)
11171122
{
1118-
Serial.println("Switching Power Save Port: "+powerSavePort);
1123+
Serial.print("Switching Power Save Port: ");
1124+
Serial.println(powerSavePort);
11191125

11201126
int port = translateGPIOPort(powerSavePort);
11211127

@@ -1134,7 +1140,8 @@ void doPowerSavingInit(boolean doDelay) {
11341140

11351141
if(powerSavePort!="")
11361142
{
1137-
Serial.println("Init Power Save Port: "+powerSavePort);
1143+
Serial.print("Init Power Save Port: ");
1144+
Serial.println(powerSavePort);
11381145

11391146
int port = translateGPIOPort(powerSavePort);
11401147

@@ -1145,7 +1152,8 @@ void doPowerSavingInit(boolean doDelay) {
11451152
}
11461153
else
11471154
{
1148-
Serial.println("No valid Power Save Port defined: "+powerSavePort);
1155+
Serial.print("No valid Power Save Port defined: ");
1156+
Serial.println(powerSavePort);
11491157
}
11501158
}
11511159
else
@@ -1258,9 +1266,14 @@ boolean postSensorData(Data* data[], int dataCount)
12581266
restart();
12591267
}
12601268

1261-
Serial.println("Retry #"+String(postSensorDataRetry)+", restart at 25");
1269+
Serial.print("Retry #");
1270+
Serial.print(postSensorDataRetry);
1271+
Serial.println(", restart at 25");
12621272
}
12631273

1274+
Serial.print(" | HEAP: ");
1275+
Serial.println(ESP.getFreeHeap());
1276+
12641277
return success;
12651278
}
12661279

@@ -1271,13 +1284,21 @@ boolean postSensorDataPart(Data* data[], int startIndex, int endIndex)
12711284

12721285
for (int i = startIndex; i <= endIndex; i++)
12731286
{
1274-
if (i == startIndex)
1275-
requestDataString = data[i]->getRequestString();
1276-
else
1277-
requestDataString = requestDataString + "," + data[i]->getRequestString();
1287+
if (i > startIndex)
1288+
{
1289+
requestDataString += ",";
1290+
}
1291+
requestDataString += data[i]->getRequestString();
12781292
}
12791293

1280-
urlString = bridgeURL + "/" + apiVersion + "/data/" + getUUID() + "/" + requestDataString;
1294+
urlString = "";
1295+
urlString += bridgeURL;
1296+
urlString += "/";
1297+
urlString += apiVersion ;
1298+
urlString += "/data/";
1299+
urlString += getUUID();
1300+
urlString += "/";
1301+
urlString += requestDataString;
12811302

12821303
httpClient.begin(*sslClient, urlString);
12831304

@@ -1353,7 +1374,12 @@ boolean postSensorDataPart(Data* data[], int startIndex, int endIndex)
13531374
}
13541375

13551376
serverError = true;
1356-
Serial.println("\nServer Error: "+String(httpCode)+" - "+httpClient.errorToString(httpCode));
1377+
1378+
Serial.print("\nServer Error: ");
1379+
Serial.print(httpCode);
1380+
Serial.print(" - ");
1381+
Serial.print(httpClient.errorToString(httpCode));
1382+
Serial.print(" - WIFI: ");
13571383
Serial.println(WiFi.status());
13581384

13591385
httpClient.end();

0 commit comments

Comments
 (0)