Skip to content

Commit 54602a2

Browse files
Readded VEML6075 and SI1145 support, improved sensor reinit if sensor fails, merged with v38 changes
1 parent 5e46948 commit 54602a2

File tree

10 files changed

+116
-58
lines changed

10 files changed

+116
-58
lines changed

README.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,24 @@ Find out more at https://www.sensate.io
77

88
- Arduino IDE ESP8266 Base Library (https://github.com/esp8266/Arduino v2.7.4)
99
- ArduinoJson (https://github.com/bblanchon/ArduinoJson v5.13.5)
10+
- ESP8266TrueRandom (https://github.com/marvinroger/ESP8266TrueRandom from 17.7.18)
1011
- Thingpulse SSD1306 (https://github.com/ThingPulse/esp8266-oled-ssd1306 v4.0.0)
1112
- Soligen2010 fork of Adafruit_ADS1x15 (https://github.com/soligen2010/Adafruit_ADS1X15) v1.2.1
12-
- Adafruit Unified Sensor Library (https://github.com/adafruit/Adafruit_Sensor v1.1.2)
13-
- Adafruit DHT Sensor Library (https://github.com/adafruit/DHT-sensor-library v1.3.8)
13+
- Adafruit Unified Sensor Library (https://github.com/adafruit/Adafruit_Sensor v1.1.4)
14+
- Adafruit DHT Sensor Library (https://github.com/adafruit/DHT-sensor-library v1.4.1)
1415
- Adafruit BusIO (https://github.com/adafruit/Adafruit_BusIO v1.7.0)
1516
- Adafruit VEML6075 (https://github.com/adafruit/Adafruit_VEML6075 v2.1.0)
1617
- OneWire (https://www.pjrc.com/teensy/td_libs_OneWire.html v2.3.5)
17-
- DallasTemperature (https://github.com/milesburton/Arduino-Temperature-Control-Library v3.8.0)
18+
- DallasTemperature (https://github.com/milesburton/Arduino-Temperature-Control-Library v3.9.0)
1819
- BME280 (https://github.com/finitespace/BME280 v2.3.0)
19-
- Adafruit BME680 (https://github.com/adafruit/Adafruit_BME680 v1.0.7)
20+
- Adafruit BME680 (https://github.com/adafruit/Adafruit_BME680 v1.1.1)
2021
- Max44009 (https://github.com/dantudose/MAX44009 v1.2.3)
21-
- BH1750 (https://github.com/claws/BH1750)
22+
- BH1750 (https://github.com/claws/BH1750 v1.2.0)
2223
- MQTT Client Library (https://github.com/knolleary/pubsubclient v2.8.0)
2324
- SI1145 (https://github.com/wollewald/SI1145_WE v1.1.4)
2425

25-
Windows Users:
26-
Use https://github.com/nodemcu/nodemcu-flasher for flashing the firmware.
27-
28-
Linux and Mac Users:
29-
Use https://github.com/espressif/esptool for flashing the firmware.
26+
Windows, Linux and Mac Users:
27+
Use pyflasher from https://github.com/marcelstoer/nodemcu-pyflasher/releases for flashing the firmware.
3028

3129
Find more informations here:
3230
https://www.sensate.io

firmware-esp8266.ino

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
SOURCE: https://github.com/sensate-io/firmware-esp8266.git
1212
1313
@section HISTORY
14+
v39 - ReAdded Support for VEML6075 and SI1145 UVI Sensors, added auto-reinit if sensor fails
15+
v38 - Changed automatic Update to only if required Update, removed VEML6075 and SI1145 UV Sensors
1416
v36 - Greatly improved reliability of connectivity
1517
v35 - Added Support for VEML6075 and SI1145 UVI Sensors
1618
v34 - Added Generic Analog Sensor Support
@@ -30,11 +32,11 @@
3032

3133
Display* display = NULL;
3234

33-
int currentVersion = 37;
35+
int currentVersion = 39;
3436
boolean printMemory = false;
3537

36-
// String board = "Generic";
37-
// char firmwareType[] = "ESP8266";
38+
String board = "Generic";
39+
char firmwareType[] = "ESP8266";
3840
// char firmwareType[] = "ESP8266-1M";
3941

4042
// String board = "NodeMCU";
@@ -46,8 +48,8 @@ boolean printMemory = false;
4648
// String board = "ESP07";
4749
// char firmwareType[] = "ESP8266-ESP07";
4850

49-
String board = "D1Mini";
50-
char firmwareType[] = "ESP8266-D1Mini";
51+
// String board = "D1Mini";
52+
// char firmwareType[] = "ESP8266-D1Mini";
5153

5254
extern String name = "Bridge";
5355
extern String ucType = "ESP8266";
@@ -208,7 +210,7 @@ void initSensate() {
208210
if(resetInfo.reason != REASON_DEEP_SLEEP_AWAKE)
209211
{
210212
Serial.println("STATE: Check_Firmware");
211-
tryFirmwareUpdate();
213+
tryFirmwareUpdate("");
212214
}
213215
else
214216
{

src/controller/Bridge.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,23 @@ bool getBridgeConfig() {
366366
{
367367
JsonObject& bridgeConfig = jsonBuffer.parseObject(payload);
368368

369+
if(bridgeConfig.containsKey("mv"))
370+
{
371+
int minimalVersion = bridgeConfig["mv"];
372+
if(currentVersion < minimalVersion)
373+
{
374+
Serial.println("Firmware Version is "+String(currentVersion)+" but required: "+String(minimalVersion));
375+
String fwUpdateToken = bridgeConfig["ut"];
376+
if(fwUpdateToken!=NULL)
377+
{
378+
tryFirmwareUpdate(fwUpdateToken);
379+
}
380+
else
381+
{
382+
Serial.println("MISSING FW Update Token, canceling update!");
383+
}
384+
}
385+
}
369386
if(bridgeConfig.containsKey("p"))
370387
{
371388
configureBridge(bridgeConfig);

src/controller/Bridge.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#include "StateHelper.h"
3030
#include "UUID.h"
31+
#include "OTA.h"
3132
#include "../communication/WiFiManager.h"
3233
#include "../communication/MQTT.h"
3334
#include "../input/Sensor.h"

src/controller/OTA.cpp

Lines changed: 5 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+
v38 - Changed automatic Update to only if required Update
1415
v29 - First Public Release
1516
*/
1617
/**************************************************************************/
@@ -24,7 +25,7 @@ extern bool isResetting;
2425
extern char firmwareType[];
2526
extern int currentVersion;
2627

27-
void tryFirmwareUpdate() {
28+
void tryFirmwareUpdate(String fwUpdateToken) {
2829

2930
t_httpUpdate_return ret;
3031
ESPhttpUpdate.rebootOnUpdate(false);
@@ -39,7 +40,7 @@ void tryFirmwareUpdate() {
3940
display->drawString(20, 21, "Update...");
4041
}
4142

42-
String updatePath = "/v1/bridge/firmware?version="+String(currentVersion)+"&type="+firmwareType;
43+
String updatePath = "/v1/bridge/firmware/"+fwUpdateToken+"?version="+String(currentVersion)+"&type="+firmwareType;
4344

4445
Serial.println(updatePath);
4546

@@ -71,6 +72,7 @@ void tryFirmwareUpdate() {
7172
break;
7273
}
7374

74-
state = Connected_WiFi;
75+
if(state==Check_Firmware)
76+
state = Connected_WiFi;
7577

7678
}

src/controller/OTA.h

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+
v38 - Changed automatic Update to only if required Update
1415
v29 - First Public Release
1516
*/
1617
/**************************************************************************/
@@ -24,6 +25,6 @@
2425

2526
#include "Bridge.h"
2627

27-
void tryFirmwareUpdate();
28+
void tryFirmwareUpdate(String fwUpdateToken);
2829

2930
#endif

src/input/i2c/SensorSI1145.cpp

Lines changed: 4 additions & 7 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+
v39 - ReAdded Support for VEML6075 and SI1145 UVI Sensors, added auto-reinit if sensor fails
1415
v35 - Added Support for VEML6075 and SI1145 UVI Sensors
1516
*/
1617
/**************************************************************************/
@@ -23,18 +24,13 @@ extern int powerMode;
2324
// Adafruit_SI1145* SensorSI1145::si1145;
2425
SI1145_WE* SensorSI1145::si1145;
2526
int SensorSI1145::lastCycleId = -1;
26-
boolean SensorSI1145::failedInit = false;
27+
boolean SensorSI1145::failedInit = true;
2728

2829
SensorSI1145::SensorSI1145 (long id, String category, String shortName, String name, String PortSDA, String PortSCL, int refreshInterval, int postDataInterval, float smartValueThreshold, SensorCalculation* calculation) : Sensor (id, category, shortName, name, refreshInterval, postDataInterval, smartValueThreshold, calculation, false) {
2930

3031
if(si1145==NULL)
3132
si1145 = new SI1145_WE();
3233

33-
si1145->init();
34-
35-
si1145->enableHighSignalVisRange(); // Gain divided by 14.5
36-
si1145->enableHighSignalIrRange(); // Gain divided by 14.5
37-
si1145->enableMeasurements(PSALSUV_TYPE, AUTO);
3834
}
3935

4036
void SensorSI1145::preCycle(int cycleId)
@@ -43,7 +39,8 @@ void SensorSI1145::preCycle(int cycleId)
4339
{
4440
if(failedInit)
4541
{
46-
Serial.println("Trying to re-init SI1145...");
42+
if(lastCycleId!=-1)
43+
Serial.println("Trying to re-init SI1145...");
4744
si1145->init();
4845
si1145->enableHighSignalVisRange(); // Gain divided by 14.5
4946
si1145->enableHighSignalIrRange(); // Gain divided by 14.5

src/input/i2c/SensorSI1145.h

Lines changed: 1 addition & 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+
v39 - ReAdded Support for VEML6075 and SI1145 UVI Sensors, added auto-reinit if sensor fails
1415
v35 - Added Support for VEML6075 and SI1145 UVI Sensors
1516
*/
1617
/**************************************************************************/
@@ -24,7 +25,6 @@
2425

2526
class SensorSI1145 : public Sensor {
2627
private:
27-
// static Adafruit_SI1145 *si1145;
2828
static SI1145_WE *si1145;
2929
static boolean failedInit;
3030
static int lastCycleId;

src/input/i2c/SensorVEML6075.cpp

Lines changed: 67 additions & 29 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+
v39 - ReAdded Support for VEML6075 and SI1145 UVI Sensors, added auto-reinit if sensor fails
1415
v35 - Added Support for VEML6075 and SI1145 UVI Sensors
1516
*/
1617
/**************************************************************************/
@@ -20,42 +21,57 @@
2021
extern boolean isResetting;
2122
extern int powerMode;
2223

24+
int SensorVEML6075::lastCycleId = -1;
25+
boolean SensorVEML6075::failedInit = true;
26+
2327
Adafruit_VEML6075* SensorVEML6075::veml6075;
2428

2529
SensorVEML6075::SensorVEML6075 (long id, String category, String shortName, String name, String PortSDA, String PortSCL, int refreshInterval, int postDataInterval, float smartValueThreshold, SensorCalculation* calculation) : Sensor (id, category, shortName, name, refreshInterval, postDataInterval, smartValueThreshold, calculation, false) {
2630

2731
int i=0;
28-
failedInit = false;
2932

3033
if(veml6075==NULL)
3134
veml6075 = new Adafruit_VEML6075();
3235

33-
while(!veml6075->begin())
34-
{
35-
Serial.println("Trying to find VEML6075 sensor!");
36-
delay(500);
37-
38-
if(i==5)
39-
{
40-
Serial.println("Could not find a valid VEML6075 sensor, check wiring!");
41-
failedInit=true;
42-
break;
43-
}
44-
45-
i++;
46-
}
47-
48-
veml6075->setIntegrationTime(VEML6075_100MS);
49-
veml6075->setHighDynamic(true);
50-
veml6075->setForcedMode(false);
51-
veml6075->setCoefficients(2.22, 1.33, // UVA_A and UVA_B coefficients
52-
2.95, 1.74, // UVB_C and UVB_D coefficients
53-
0.001461, 0.002591); // UVA and UVB responses
54-
5536
}
5637

5738
void SensorVEML6075::preCycle(int cycleId)
5839
{
40+
if(cycleId!=lastCycleId)
41+
{
42+
if(failedInit)
43+
{
44+
failedInit = false;
45+
46+
int i=0;
47+
if(lastCycleId!=-1)
48+
Serial.println("Trying to re-init VEML6075...");
49+
while(!veml6075->begin())
50+
{
51+
delay(500);
52+
if(i==5)
53+
{
54+
Serial.println("Could not find a valid VEML6075 sensor, check wiring!");
55+
failedInit=true;
56+
break;
57+
}
58+
59+
i++;
60+
}
61+
62+
if(!failedInit)
63+
{
64+
veml6075->setIntegrationTime(VEML6075_100MS);
65+
veml6075->setHighDynamic(true);
66+
veml6075->setForcedMode(false);
67+
veml6075->setCoefficients(2.22, 1.33, // UVA_A and UVA_B coefficients
68+
2.95, 1.74, // UVB_C and UVB_D coefficients
69+
0.001461, 0.002591); // UVA and UVB responses
70+
}
71+
72+
}
73+
lastCycleId=cycleId;
74+
}
5975
}
6076

6177
Data* SensorVEML6075::read(bool shouldPostData)
@@ -65,20 +81,42 @@ Data* SensorVEML6075::read(bool shouldPostData)
6581
if(_calculation->getValueType()=="a")
6682
{
6783
float irradiance_a = veml6075->readUVA();
68-
shouldPostData = smartSensorCheck(irradiance_a, _smartValueThreshold, shouldPostData);
69-
return _calculation->calculate(this, irradiance_a, shouldPostData);
84+
if(irradiance_a>=-1000) {
85+
shouldPostData = smartSensorCheck(irradiance_a, _smartValueThreshold, shouldPostData);
86+
return _calculation->calculate(this, irradiance_a, shouldPostData);
87+
}
88+
else
89+
{
90+
Serial.println("NAN UV-A!");
91+
failedInit=true;
92+
}
7093
}
7194
else if(_calculation->getValueType()=="b")
7295
{
7396
float irradiance_b = veml6075->readUVB();
74-
shouldPostData = smartSensorCheck(irradiance_b, _smartValueThreshold, shouldPostData);
75-
return _calculation->calculate(this, irradiance_b, shouldPostData);
97+
if(irradiance_b>=-1000) {
98+
shouldPostData = smartSensorCheck(irradiance_b, _smartValueThreshold, shouldPostData);
99+
return _calculation->calculate(this, irradiance_b, shouldPostData);
100+
}
101+
else
102+
{
103+
Serial.println("NAN UV-B!");
104+
failedInit=true;
105+
}
76106
}
77107
else if(_calculation->getValueType()=="raw")
78108
{
79109
float index = veml6075->readUVI();
80-
shouldPostData = smartSensorCheck(index, _smartValueThreshold, shouldPostData);
81-
return _calculation->calculate(this, index, shouldPostData);
110+
if(index>=-1000) {
111+
shouldPostData = smartSensorCheck(index, _smartValueThreshold, shouldPostData);
112+
return _calculation->calculate(this, index, shouldPostData);
113+
}
114+
else
115+
{
116+
Serial.println("NAN UV-Index!");
117+
failedInit=true;
118+
}
119+
82120
}
83121
}
84122
return NULL;

src/input/i2c/SensorVEML6075.h

Lines changed: 3 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+
v39 - ReAdded Support for VEML6075 and SI1145 UVI Sensors, added auto-reinit if sensor fails
1415
v35 - Added Support for VEML6075 and SI1145 UVI Sensors
1516
*/
1617
/**************************************************************************/
@@ -24,7 +25,8 @@
2425
class SensorVEML6075 : public Sensor {
2526
private:
2627
static Adafruit_VEML6075 *veml6075;
27-
boolean failedInit;
28+
static boolean failedInit;
29+
static int lastCycleId;
2830
float lastPostedValue = NAN;
2931
protected:
3032
Data* read(bool);

0 commit comments

Comments
 (0)