Skip to content

Commit be737ad

Browse files
Improved Data Handling for Configurations with many Sensors
1 parent 5f49384 commit be737ad

File tree

4 files changed

+89
-17
lines changed

4 files changed

+89
-17
lines changed

Sensatio_FW_ESP8266.cpp

Lines changed: 3 additions & 2 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+
v43 - Fixed data transmit issues in configurations with many sensors
1415
v42 - Fixed low memory issues in configurations with many sensors and a ST7735 Bug
1516
v41 - Changed IDE, Sensatio, Renamed Display Class to support more types
1617
v40 - New Display Structure to enable Display Rotation, different Styles etc.
@@ -32,7 +33,7 @@
3233
VisualisationHelper* vHelper;
3334
Display* display = NULL;
3435

35-
int currentVersion = 42;
36+
int currentVersion = 43;
3637
boolean printMemory = false;
3738

3839
//String board = "Generic";
@@ -54,7 +55,7 @@ boolean printMemory = false;
5455
extern String name = "Bridge";
5556
extern String ucType = "ESP8266";
5657

57-
String variant = "SensateV"+String(currentVersion)+board;
58+
String variant = "SensatioV"+String(currentVersion)+board;
5859

5960
String apiVersion = "v1";
6061

src/controller/Bridge.cpp

Lines changed: 67 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+
v43 - Fixed data transmit issues in configurations with many sensors
1415
v42 - Fixed low memory issues in configurations with many sensors and a ST7735 Bug
1516
v41 - Renamed Display Class to support more types
1617
v40 - New Display Structure to enable Display Rotation, different Styles etc.
@@ -1203,14 +1204,76 @@ uint8_t translateGPIOPort(String gpioPort)
12031204
}
12041205

12051206
boolean postSensorData(Data* data[], int dataCount)
1207+
{
1208+
if(printMemory)
1209+
{
1210+
Serial.print("HEAP: ");
1211+
Serial.println(ESP.getFreeHeap());
1212+
}
1213+
1214+
boolean success = true;
1215+
1216+
if(dataCount<=5)
1217+
{
1218+
success = postSensorDataPart(data, 0, dataCount-1);
1219+
}
1220+
else
1221+
{
1222+
Serial.print("s");
1223+
Serial.print(dataCount);
1224+
1225+
int start = 0;
1226+
int end = 4;
1227+
1228+
while(end<=dataCount)
1229+
{
1230+
if(!postSensorDataPart(data, start, end))
1231+
success = false;
1232+
1233+
yield();
1234+
1235+
if(printMemory)
1236+
{
1237+
Serial.print("HEAP: ");
1238+
Serial.println(ESP.getFreeHeap());
1239+
}
1240+
1241+
start+=5;
1242+
end+=5;
1243+
1244+
if(start>dataCount-1)
1245+
break;
1246+
if(end>dataCount-1)
1247+
end = dataCount-1;
1248+
}
1249+
}
1250+
1251+
if(!success)
1252+
{
1253+
postSensorDataRetry++;
1254+
1255+
if(postSensorDataRetry>=25)
1256+
{
1257+
postSensorDataRetry=0;
1258+
restart();
1259+
}
1260+
1261+
Serial.println("Retry #"+String(postSensorDataRetry)+", restart at 25");
1262+
}
1263+
1264+
return success;
1265+
}
1266+
1267+
1268+
boolean postSensorDataPart(Data* data[], int startIndex, int endIndex)
12061269
{
12071270
HTTPClient httpClient;
12081271

12091272
String requestDataString = "";
12101273

1211-
for (int i = 0; i < dataCount; i++)
1274+
for (int i = startIndex; i <= endIndex; i++)
12121275
{
1213-
if (i == 0)
1276+
if (i == startIndex)
12141277
requestDataString = data[i]->getRequestString();
12151278
else
12161279
requestDataString = requestDataString + "," + data[i]->getRequestString();
@@ -1245,6 +1308,7 @@ boolean postSensorData(Data* data[], int dataCount)
12451308
}
12461309

12471310
String payload = httpClient.getString();
1311+
httpClient.end();
12481312

12491313
if(payload!=NULL && displayType!=0)
12501314
{
@@ -1278,7 +1342,6 @@ boolean postSensorData(Data* data[], int dataCount)
12781342
}
12791343
}
12801344

1281-
httpClient.end();
12821345
return true;
12831346
}
12841347
else
@@ -1292,22 +1355,11 @@ boolean postSensorData(Data* data[], int dataCount)
12921355
}
12931356

12941357
serverError = true;
1295-
Serial.println("Server Error: "+String(httpCode));
1296-
1297-
Serial.println("Server Error: "+httpClient.errorToString(httpCode));
1358+
Serial.println("\nServer Error: "+String(httpCode)+" - "+httpClient.errorToString(httpCode));
12981359
Serial.println(WiFi.status());
12991360

13001361
httpClient.end();
13011362

1302-
postSensorDataRetry++;
1303-
1304-
if(postSensorDataRetry>=25)
1305-
{
1306-
postSensorDataRetry=0;
1307-
restart();
1308-
}
1309-
1310-
Serial.println("Retry #"+String(postSensorDataRetry)+", restart at 25");
13111363
}
13121364
return false;
13131365
}

src/controller/Bridge.h

Lines changed: 2 additions & 0 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+
v43 - Fixed data transmit issues in configurations with many sensors
1415
v42 - Fixed low memory issues in configurations with many sensors and a ST7735 Bug
1516
v40 - New Display Structure to enable Display Rotation, different Styles etc.
1617
v36 - Greatly improved reliability of connectivity
@@ -65,6 +66,7 @@ void addSensor(Sensor *);
6566
void loopSensor(int);
6667
void loopDisplay(unsigned long);
6768
boolean postSensorData(Data* data[], int);
69+
boolean postSensorDataPart(Data* data[], int, int);
6870
void checkStatus();
6971
void trySleep(long);
7072
void storeDisplayAndPowerConfig(boolean);

src/output/display/DisplayST7735.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,27 @@ void DisplayST7735::drawString(int16_t x, int16_t y, String text) {
203203

204204
void DisplayST7735::drawDisconnected(bool update) {
205205

206+
if(!isResetting && displayEnabled)
207+
{
208+
display->fillRect(144, 112, 16, 16, ST7735_BLACK); // @suppress("Method cannot be resolved")
209+
210+
display->drawLine(144, 117, 150, 117, ST7735_CYAN);
211+
display->drawLine(144, 123, 148, 123, ST7735_CYAN);
212+
display->drawLine(148, 127, 151, 113, ST7735_CYAN);
213+
display->drawLine(152, 127, 155, 113, ST7735_CYAN);
214+
215+
display->drawLine(154, 117, 195, 117, ST7735_CYAN);
216+
display->drawLine(153, 123, 195, 123, ST7735_CYAN);
217+
218+
}
206219
}
207220

208221
void DisplayST7735::drawConnected(bool update) {
209222

223+
if(!isResetting && displayEnabled)
224+
{
225+
display->fillRect(112, 48, 16, 16, ST7735_BLACK);
226+
}
210227
}
211228

212229
int DisplayST7735::getSimultanValueCount() {

0 commit comments

Comments
 (0)