Skip to content

Commit 51ee8dd

Browse files
Greatly improved reliability of connectivity
1 parent df69110 commit 51ee8dd

File tree

4 files changed

+33
-33
lines changed

4 files changed

+33
-33
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Find out more at https://www.sensate.io
55

66
# The Sensate Firmware for ESP8266 currently uses the following Libraries:
77

8-
- Arduino IDE ESP8266 Base Library (https://github.com/esp8266/Arduino v2.5.2)
8+
- Arduino IDE ESP8266 Base Library (https://github.com/esp8266/Arduino v2.7.4)
99
- ArduinoJson (https://github.com/bblanchon/ArduinoJson v5.13.5)
1010
- Thingpulse SSD1306 (https://github.com/ThingPulse/esp8266-oled-ssd1306 v4.0.0)
1111
- Soligen2010 fork of Adafruit_ADS1x15 (https://github.com/soligen2010/Adafruit_ADS1X15) v1.2.1

firmware-esp8266.ino

Lines changed: 2 additions & 1 deletion
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+
v36 - Greatly improved reliability of connectivity
1415
v35 - Added Support for VEML6075 and SI1145 UVI Sensors
1516
v34 - Added Generic Analog Sensor Support
1617
v33 - Added Digital Sensor Switch Support, Improved MQTT Setup Routine
@@ -29,7 +30,7 @@
2930

3031
Display* display = NULL;
3132

32-
int currentVersion = 35;
33+
int currentVersion = 36;
3334
boolean printMemory = false;
3435

3536
String board = "Generic";

src/controller/Bridge.cpp

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222

2323
#include "Bridge.h"
2424

25-
#define ssl_fingerprint_prod "E9 A9 3D E2 AD AB C2 96 FA 3C A7 A8 57 DE 8E A0 95 59 9B 7A" //hub.sensate.cloud
26-
#define ssl_fingerprint_test "E3 19 E5 F3 DA 1A BD 01 EB BC 08 E6 49 18 7D 54 66 BD 2B 12" //test.sensate.cloud
25+
const uint8_t ssl_fingerprint_prod[20] = {0xE9, 0xA9, 0x3D, 0xE2, 0xAD, 0xAB, 0xC2, 0x96, 0xFA, 0x3C, 0xA7, 0xA8, 0x57, 0xDE, 0x8E, 0xA0, 0x95, 0x59, 0x9B, 0x7A}; //hub.sensate.cloud
26+
const uint8_t ssl_fingerprint_test[20] = {0xE3, 0x19, 0xE5, 0xF3, 0xDA, 0x1A, 0xBD, 0x01, 0xEB, 0xBC, 0x08, 0xE6, 0x49, 0x18, 0x7D, 0x54, 0x66, 0xBD, 0x2B, 0x12}; //test.sensate.cloud
27+
2728
#define maxSensorCount 25
2829

2930
extern State state;
@@ -62,8 +63,6 @@ unsigned long nextSensorDue = -1;
6263

6364
char pwdHash[41] = "";
6465

65-
66-
6766
String bridgeURL;
6867

6968
Sensor *sensors[maxSensorCount];
@@ -77,6 +76,8 @@ int configRetry = 0;
7776
int postSensorDataRetry = 0;
7877
int sensorCycle = 1;
7978

79+
std::unique_ptr<BearSSL::WiFiClientSecure>sslClient(new BearSSL::WiFiClientSecure);
80+
8081
bool registerBridge()
8182
{
8283
if(display!=NULL)
@@ -89,9 +90,6 @@ bool registerBridge()
8990
String uuid = getUUID();
9091
String networkIP = WiFi.localIP().toString();
9192

92-
Serial.print("HEAP 1: ");
93-
Serial.println(ESP.getFreeHeap());
94-
9593
if (uuid.length() > 0 && networkIP.length() > 0)
9694
{
9795
Serial.println("Registering Bridge " + uuid + " to Bridge located at " + bridgeURL);
@@ -101,19 +99,17 @@ bool registerBridge()
10199

102100
String urlString = bridgeURL + "/" + apiVersion + "/bridge/";
103101

102+
sslClient->setBufferSizes(1024, 1024);
104103
if(urlString.startsWith("https://hub"))
105-
httpClient.begin(urlString, ssl_fingerprint_prod);
104+
sslClient->setFingerprint(ssl_fingerprint_prod);
106105
else if(urlString.startsWith("https://test"))
107-
httpClient.begin(urlString, ssl_fingerprint_test);
108-
else
109-
httpClient.begin(urlString);
110-
106+
sslClient->setFingerprint(ssl_fingerprint_test);
107+
108+
httpClient.begin(*sslClient, urlString);
109+
111110
httpClient.addHeader("Content-Type", "application/json");
112111
httpClient.setTimeout(5000);
113112

114-
Serial.print("HEAP 2: ");
115-
Serial.println(ESP.getFreeHeap());
116-
117113
String pwdHashString = "";
118114

119115
if(pwdHash[0]!=0xff)
@@ -123,13 +119,12 @@ bool registerBridge()
123119

124120
String message = "{\"uuid\":\"" + uuid + "\",\"networkIP\":\"" + networkIP + "\",\"name\":\"" + name + "\",\"vendor\":\"" + board + "\",\"type\":\"" + ucType + "\",\"firmwareVersion\":" + currentVersion + ",\"secPassword\":\"" + pwdHashString + "\"}";
125121

122+
Serial.print("p");
126123
int httpCode = httpClient.POST(message);
127124

128-
Serial.print("HEAP 3: ");
129-
Serial.println(ESP.getFreeHeap());
130-
131125
if (httpCode == HTTP_CODE_OK)
132126
{
127+
Serial.print("o");
133128
String payload = httpClient.getString();
134129
if (payload == uuid)
135130
{
@@ -141,12 +136,14 @@ bool registerBridge()
141136
}
142137
else if (httpCode == HTTP_CODE_UPGRADE_REQUIRED)
143138
{
139+
Serial.print("u");
144140
httpClient.end();
145141
restart();
146142
return false;
147143
}
148144
else
149145
{
146+
Serial.print("e");
150147
registerRetry++;
151148

152149
Serial.println("Register failed..? - HTTP:" + String(httpCode));
@@ -345,19 +342,16 @@ bool getBridgeConfig() {
345342

346343
String urlString = bridgeURL + "/" + apiVersion + "/bridge/" + getUUID();
347344

348-
if(urlString.startsWith("https://hub"))
349-
httpClient.begin(urlString, ssl_fingerprint_prod);
350-
else if(urlString.startsWith("https://test"))
351-
httpClient.begin(urlString, ssl_fingerprint_test);
352-
else
353-
httpClient.begin(urlString);
345+
httpClient.begin(*sslClient, urlString);
354346

355347
httpClient.addHeader("Content-Type", "application/json");
356348

349+
Serial.print("g");
357350
int httpCode = httpClient.GET();
358351

359352
if (httpCode == HTTP_CODE_OK)
360353
{
354+
Serial.print("o");
361355
String payload = httpClient.getString();
362356

363357
int portNumber = 0;
@@ -420,6 +414,7 @@ bool getBridgeConfig() {
420414

421415
httpClient.end();
422416

417+
Serial.print("e");
423418
configRetry++;
424419
Serial.println("Retry #"+String(configRetry)+", restart at 25");
425420

@@ -1084,23 +1079,23 @@ boolean postSensorData(Data* data[], int dataCount)
10841079

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

1087-
if(urlString.startsWith("https://hub"))
1088-
httpClient.begin(urlString, ssl_fingerprint_prod);
1089-
else if(urlString.startsWith("https://test"))
1090-
httpClient.begin(urlString, ssl_fingerprint_test);
1091-
else
1092-
httpClient.begin(urlString);
1093-
1082+
httpClient.begin(*sslClient, urlString);
1083+
1084+
Serial.print("p");
1085+
10941086
int httpCode = httpClient.PUT("");
10951087

10961088
if (httpCode == HTTP_CODE_UPGRADE_REQUIRED)
10971089
{
1090+
Serial.print("u");
10981091
httpClient.end();
10991092
restart();
11001093
return true;
11011094
}
11021095
else if (httpCode == HTTP_CODE_OK)
11031096
{
1097+
Serial.print("o");
1098+
11041099
if(serverError || wasDisconnected)
11051100
{
11061101
serverError = false;
@@ -1137,6 +1132,8 @@ boolean postSensorData(Data* data[], int dataCount)
11371132
}
11381133
else
11391134
{
1135+
Serial.print("e");
1136+
11401137
if(display!=NULL)
11411138
{
11421139
wasDisconnected=true;

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+
v36 - Greatly improved reliability of connectivity
1415
v35 - Added Support for VEML6075 and SI1145 UVI Sensors
1516
v33 - Added Digital Sensor Switch Support
1617
v32 - Added MQTT Support!
@@ -20,6 +21,7 @@
2021

2122
#include <Esp.h>
2223
#include <EEPROM.h>
24+
#include <WiFiClientSecureBearSSL.h>
2325

2426
#ifndef _Bridge_h_
2527
#define _Bridge_h_

0 commit comments

Comments
 (0)