Skip to content

Commit

Permalink
More Memory Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel-Sensate committed Jun 1, 2021
1 parent ceeda18 commit afca08a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 18 deletions.
15 changes: 12 additions & 3 deletions Sensatio_FW_ESP8266.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
SOURCE: https://github.com/sensate-io/firmware-esp8266.git
@section HISTORY
v44 - More Memory Improvements
v43 - Fixed data transmit issues in configurations with many sensors
v42 - Fixed low memory issues in configurations with many sensors and a ST7735 Bug
v41 - Changed IDE, Sensatio, Renamed Display Class to support more types
Expand All @@ -33,11 +34,11 @@
VisualisationHelper* vHelper;
Display* display = NULL;

int currentVersion = 43;
int currentVersion = 44;
boolean printMemory = false;

//String board = "Generic";
//char firmwareType[] = "ESP8266";
////char firmwareType[] = "ESP8266";
// char firmwareType[] = "ESP8266-1M";

String board = "NodeMCU";
Expand Down Expand Up @@ -84,19 +85,27 @@ extern uint8_t i2cSDAPort;
extern uint8_t i2cSCLPort;
extern MQTT* mqtt;

extern String urlString;
extern String requestDataString;
extern String payload;

#define tickerInterval 250
#define delayInterval 10000


void setup()
{
Serial.begin(9600);
Serial.begin(9600);
Serial.println("---------------------------");
Serial.println(variant);
Serial.println("---------------------------");
Serial.println("Startup: ");
Serial.println(getUUID()); // @suppress("Invalid arguments")

urlString.reserve(300);
requestDataString.reserve(200);
payload.reserve(1000);

restoreBridgeConfig();

vHelper = new VisualisationHelper();
Expand Down
56 changes: 41 additions & 15 deletions src/controller/Bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
SOURCE: https://github.com/sensate-io/firmware-esp8266.git
@section HISTORY
v44 - More Memory Improvements
v43 - Fixed data transmit issues in configurations with many sensors
v42 - Fixed low memory issues in configurations with many sensors and a ST7735 Bug
v41 - Renamed Display Class to support more types
Expand Down Expand Up @@ -85,7 +86,6 @@ bool foundPorts = false;

String urlString;
String requestDataString;
String message;
String payload;

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

String port = portConfig["p"];

Serial.println("Configure Onboard Port:" + port);
Serial.print("Configure Onboard Port:");
Serial.println(port);

//portConfig.prettyPrintTo(Serial);
Serial.println("");
Expand Down Expand Up @@ -969,7 +970,8 @@ void configurePort(int portNumber, JsonObject& portConfig) {
uint8_t intPort = translateGPIOPort(port);
if(intPort<999)
{
Serial.println("Setting up Digital Switch at Port: " + port);
Serial.print("Setting up Digital Switch at Port: ");
Serial.println(port);
addSensor(new SensorDigitalSwitch(portConfig["id"], portConfig["c"], portConfig["sn"], portConfig["n"], intPort, refreshInterval, postDataInterval, calc));
}
}
Expand Down Expand Up @@ -1063,7 +1065,9 @@ void loopSensor(int currentTimeMs) {
if(!abortDelay)
{
int delayTime=100*retry;
Serial.println("Communication Issues - Retrying in "+String(delayTime)+"ms ");
Serial.print("Communication Issues - Retrying in ");
Serial.print(delayTime);
Serial.println("ms ");
yield();
delay(delayTime);
}
Expand Down Expand Up @@ -1106,7 +1110,8 @@ void trySleep(long microseconds)
{
loopDisplay(millis());
doPowerSaving();
Serial.println("Going to deep sleep for "+String(microseconds));
Serial.print("Going to deep sleep for ");
Serial.println(microseconds);
ESP.deepSleep(microseconds);
}
}
Expand All @@ -1115,7 +1120,8 @@ void doPowerSaving() {

if(powerSavePort!=NULL && !powerSavePort.length()>0)
{
Serial.println("Switching Power Save Port: "+powerSavePort);
Serial.print("Switching Power Save Port: ");
Serial.println(powerSavePort);

int port = translateGPIOPort(powerSavePort);

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

if(powerSavePort!="")
{
Serial.println("Init Power Save Port: "+powerSavePort);
Serial.print("Init Power Save Port: ");
Serial.println(powerSavePort);

int port = translateGPIOPort(powerSavePort);

Expand All @@ -1145,7 +1152,8 @@ void doPowerSavingInit(boolean doDelay) {
}
else
{
Serial.println("No valid Power Save Port defined: "+powerSavePort);
Serial.print("No valid Power Save Port defined: ");
Serial.println(powerSavePort);
}
}
else
Expand Down Expand Up @@ -1258,9 +1266,14 @@ boolean postSensorData(Data* data[], int dataCount)
restart();
}

Serial.println("Retry #"+String(postSensorDataRetry)+", restart at 25");
Serial.print("Retry #");
Serial.print(postSensorDataRetry);
Serial.println(", restart at 25");
}

Serial.print(" | HEAP: ");
Serial.println(ESP.getFreeHeap());

return success;
}

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

for (int i = startIndex; i <= endIndex; i++)
{
if (i == startIndex)
requestDataString = data[i]->getRequestString();
else
requestDataString = requestDataString + "," + data[i]->getRequestString();
if (i > startIndex)
{
requestDataString += ",";
}
requestDataString += data[i]->getRequestString();
}

urlString = bridgeURL + "/" + apiVersion + "/data/" + getUUID() + "/" + requestDataString;
urlString = "";
urlString += bridgeURL;
urlString += "/";
urlString += apiVersion ;
urlString += "/data/";
urlString += getUUID();
urlString += "/";
urlString += requestDataString;

httpClient.begin(*sslClient, urlString);

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

serverError = true;
Serial.println("\nServer Error: "+String(httpCode)+" - "+httpClient.errorToString(httpCode));

Serial.print("\nServer Error: ");
Serial.print(httpCode);
Serial.print(" - ");
Serial.print(httpClient.errorToString(httpCode));
Serial.print(" - WIFI: ");
Serial.println(WiFi.status());

httpClient.end();
Expand Down

0 comments on commit afca08a

Please sign in to comment.