Skip to content

Commit ea91feb

Browse files
Added Support for VEML6075 and SI1145 UVI Sensors
1 parent c4fb263 commit ea91feb

File tree

10 files changed

+393
-4
lines changed

10 files changed

+393
-4
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@ Find out more at https://www.sensate.io
1111
- Soligen2010 fork of Adafruit_ADS1x15 (https://github.com/soligen2010/Adafruit_ADS1X15) v1.2.1
1212
- Adafruit Unified Sensor Library (https://github.com/adafruit/Adafruit_Sensor v1.1.2)
1313
- Adafruit DHT Sensor Library (https://github.com/adafruit/DHT-sensor-library v1.3.8)
14+
- Adafruit BusIO (https://github.com/adafruit/Adafruit_BusIO v1.7.0)
15+
- Adafruit VEML6075 (https://github.com/adafruit/Adafruit_VEML6075 v2.1.0)
1416
- OneWire (https://www.pjrc.com/teensy/td_libs_OneWire.html v2.3.5)
1517
- DallasTemperature (https://github.com/milesburton/Arduino-Temperature-Control-Library v3.8.0)
1618
- BME280 (https://github.com/finitespace/BME280 v2.3.0)
1719
- Adafruit BME680 (https://github.com/adafruit/Adafruit_BME680 v1.0.7)
1820
- Max44009 (https://github.com/dantudose/MAX44009 v1.2.3)
1921
- BH1750 (https://github.com/claws/BH1750)
2022
- MQTT Client Library (https://github.com/knolleary/pubsubclient v2.8.0)
23+
- SI1145 (https://github.com/wollewald/SI1145_WE v1.1.4)
2124

2225
Windows Users:
2326
Use https://github.com/nodemcu/nodemcu-flasher for flashing the firmware.

firmware-esp8266.ino

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+
v35 - Added Support for VEML6075 and SI1145 UVI Sensors
1415
v34 - Added Generic Analog Sensor Support
1516
v33 - Added Digital Sensor Switch Support, Improved MQTT Setup Routine
1617
v32 - Added MQTT Support!
@@ -28,7 +29,7 @@
2829

2930
Display* display = NULL;
3031

31-
int currentVersion = 34;
32+
int currentVersion = 35;
3233
boolean printMemory = false;
3334

3435
String board = "Generic";
@@ -47,7 +48,7 @@ char firmwareType[] = "ESP8266";
4748
// char firmwareType[] = "ESP8266-D1Mini";
4849

4950
extern String name = "Bridge";
50-
extern String type = "ESP8266";
51+
extern String ucType = "ESP8266";
5152

5253
String variant = "SensateV"+String(currentVersion)+board;
5354

src/controller/Bridge.cpp

Lines changed: 27 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+
v35 - Added Support for VEML6075 and SI1145 UVI Sensors
1415
v34 - Added Generic Analog Sensor Support
1516
v33 - Added Digital Sensor Switch Support
1617
v32 - Added MQTT Support!
@@ -40,7 +41,7 @@ extern struct rst_info resetInfo;
4041

4142
extern String name;
4243
extern String board;
43-
extern String type;
44+
extern String ucType;
4445

4546
extern long powerOnDelay;
4647
extern String powerSavePort;
@@ -110,7 +111,7 @@ bool registerBridge()
110111
pwdHashString = String(pwdHashString);
111112
}
112113

113-
String message = "{\"uuid\":\"" + uuid + "\",\"networkIP\":\"" + networkIP + "\",\"name\":\"" + name + "\",\"vendor\":\"" + board + "\",\"type\":\"" + type + "\",\"firmwareVersion\":" + currentVersion + ",\"secPassword\":\"" + pwdHashString + "\"}";
114+
String message = "{\"uuid\":\"" + uuid + "\",\"networkIP\":\"" + networkIP + "\",\"name\":\"" + name + "\",\"vendor\":\"" + board + "\",\"type\":\"" + ucType + "\",\"firmwareVersion\":" + currentVersion + ",\"secPassword\":\"" + pwdHashString + "\"}";
114115

115116
int httpCode = httpClient.POST(message);
116117

@@ -639,12 +640,20 @@ void configureExpansionPort(int portNumber, JsonObject& portConfig) {
639640
calc = new SensorCalculationDirectPPM(portNumber);
640641
else if (portConfig["s"]["cf"] == "DIRECT_NONE")
641642
calc = new SensorCalculationDirectNone(portNumber);
643+
else if (portConfig["s"]["cf"] == "DIRECT_WPM2")
644+
calc = new SensorCalculationDirectWpm2(portNumber);
642645
else if (portConfig["s"]["cf"] == "CALC_METER")
643646
calc = new SensorCalculationCalcAltitude(portNumber);
644647
else if (portConfig["s"]["cf"] == "CALC_RAW_PERCENT")
645648
calc = new SensorCalculationRawToPercent(portConfig["c1"], portConfig["c2"], portNumber);
646649
else if (portConfig["s"]["cf"] == "RAW")
647650
calc = new SensorCalculationRaw(portNumber);
651+
else if (portConfig["s"]["cf"] == "RAW_A")
652+
calc = new SensorCalculationRaw(portNumber, "a");
653+
else if (portConfig["s"]["cf"] == "RAW_B")
654+
calc = new SensorCalculationRaw(portNumber, "b");
655+
else if (portConfig["s"]["cf"] == "RAW_C")
656+
calc = new SensorCalculationRaw(portNumber, "c");
648657
else if (portConfig["s"]["cf"] == "CALC_RAW_VREF")
649658
calc = new SensorCalculationRawToVoltage(portConfig["c1"], portConfig["c2"], portNumber);
650659

@@ -705,6 +714,14 @@ void configureExpansionPort(int portNumber, JsonObject& portConfig) {
705714
{
706715
addSensor(new SensorBH1750(portConfig["id"], portConfig["c"], portConfig["sn"], portConfig["n"], portConfig["ec1"], portConfig["ec2"], refreshInterval, postDataInterval, portConfig["s"]["svt"], calc));
707716
}
717+
else if (portConfig["et"] == "VEML6075")
718+
{
719+
addSensor(new SensorVEML6075(portConfig["id"], portConfig["c"], portConfig["sn"], portConfig["n"], portConfig["ec1"], portConfig["ec2"], refreshInterval, postDataInterval, portConfig["s"]["svt"], calc));
720+
}
721+
else if (portConfig["et"] == "SI1145")
722+
{
723+
addSensor(new SensorSI1145(portConfig["id"], portConfig["c"], portConfig["sn"], portConfig["n"], portConfig["ec1"], portConfig["ec2"], refreshInterval, postDataInterval, portConfig["s"]["svt"], calc));
724+
}
708725

709726
}
710727

@@ -747,12 +764,20 @@ void configurePort(int portNumber, JsonObject& portConfig) {
747764
calc = new SensorCalculationDirectPPM(portNumber);
748765
else if (portConfig["s"]["cf"] == "DIRECT_NONE")
749766
calc = new SensorCalculationDirectNone(portNumber);
767+
else if (portConfig["s"]["cf"] == "DIRECT_WPM2")
768+
calc = new SensorCalculationDirectWpm2(portNumber);
750769
else if (portConfig["s"]["cf"] == "CALC_METER")
751770
calc = new SensorCalculationCalcAltitude(portNumber);
752771
else if (portConfig["s"]["cf"] == "CALC_RAW_PERCENT")
753772
calc = new SensorCalculationRawToPercent(portConfig["c1"], portConfig["c2"], portNumber);
754773
else if (portConfig["s"]["cf"] == "RAW")
755774
calc = new SensorCalculationRaw(portNumber);
775+
else if (portConfig["s"]["cf"] == "RAW_A")
776+
calc = new SensorCalculationRaw(portNumber, "a");
777+
else if (portConfig["s"]["cf"] == "RAW_B")
778+
calc = new SensorCalculationRaw(portNumber, "b");
779+
else if (portConfig["s"]["cf"] == "RAW_C")
780+
calc = new SensorCalculationRaw(portNumber, "c");
756781
else if (portConfig["s"]["cf"] == "CALC_RAW_VREF")
757782
calc = new SensorCalculationRawToVoltage(portConfig["c1"], portConfig["c2"], portNumber);
758783

src/controller/Bridge.h

Lines changed: 3 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+
v35 - Added Support for VEML6075 and SI1145 UVI Sensors
1415
v33 - Added Digital Sensor Switch Support
1516
v32 - Added MQTT Support!
1617
v29 - First Public Release
@@ -35,6 +36,8 @@
3536
#include "../input/i2c/SensorBME680.h"
3637
#include "../input/i2c/SensorMax44009.h"
3738
#include "../input/i2c/SensorBH1750.h"
39+
#include "../input/i2c/SensorVEML6075.h"
40+
#include "../input/i2c/SensorSI1145.h"
3841
#include "../input/onewire/SensorDHT.h"
3942
#include "../input/onewire/SensorDallas.h"
4043
#include "../output/display/DisplayOLED128.h"

src/input/SensorCalculation.cpp

Lines changed: 24 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+
v35 - Added Support for VEML6075 and SI1145 UVI Sensors
1415
v34 - Added Generic Analog Sensor Support
1516
v33 - Added Digital Sensor Switch Support
1617
v32 - Added MQTT Support!
@@ -153,6 +154,13 @@ SensorCalculationDirectNone::SensorCalculationDirectNone(int portNumber) : Senso
153154
_portNumber = portNumber;
154155
}
155156

157+
SensorCalculationDirectWpm2::SensorCalculationDirectWpm2(int portNumber) : SensorCalculation()
158+
{
159+
_valueType = "irradiance";
160+
_valueUnit = "W/m²";
161+
_portNumber = portNumber;
162+
}
163+
156164
SensorCalculationCalcAltitude::SensorCalculationCalcAltitude(int portNumber) : SensorCalculation()
157165
{
158166
_valueType = "altitude";
@@ -185,6 +193,13 @@ SensorCalculationRaw::SensorCalculationRaw(int portNumber) : SensorCalculation()
185193
_portNumber = portNumber;
186194
}
187195

196+
SensorCalculationRaw::SensorCalculationRaw(int portNumber, String valueUnit) : SensorCalculation()
197+
{
198+
_valueType = valueUnit;
199+
_valueUnit = "";
200+
_portNumber = portNumber;
201+
}
202+
188203
Data* SensorCalculation::calculate(Sensor* sensor, float rawValue, bool postData)
189204
{
190205
return NULL;
@@ -324,6 +339,15 @@ Data* SensorCalculationDirectPPM::calculate(Sensor* sensor, float rawValue, bool
324339
return new Data (sensor, rawValue, "PPM");
325340
}
326341

342+
Data* SensorCalculationDirectWpm2::calculate(Sensor* sensor, float rawValue, bool postData)
343+
{
344+
if(display!=NULL && _portNumber>=0)
345+
display->drawValue(_portNumber, sensor->getName(), sensor->getShortName(), rawValue, _valueUnit);
346+
if(!postData)
347+
return NULL;
348+
return new Data (sensor, rawValue, "WPM2");
349+
}
350+
327351
Data* SensorCalculationDirectNone::calculate(Sensor* sensor, float rawValue, bool postData)
328352
{
329353
if(display!=NULL && _portNumber>=0)

src/input/SensorCalculation.h

Lines changed: 8 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+
v35 - Added Support for VEML6075 and SI1145 UVI Sensors
1415
v34 - Added Generic Analog Sensor Support
1516
v33 - Added Digital Sensor Switch Support
1617
v32 - Added MQTT Support!
@@ -133,6 +134,12 @@ class SensorCalculationDirectPPM : public SensorCalculation {
133134
Data* calculate(Sensor* sensor, float, bool);
134135
};
135136

137+
class SensorCalculationDirectWpm2 : public SensorCalculation {
138+
public:
139+
SensorCalculationDirectWpm2(int);
140+
Data* calculate(Sensor* sensor, float, bool);
141+
};
142+
136143
class SensorCalculationCalcAltitude : public SensorCalculation {
137144
public:
138145
SensorCalculationCalcAltitude(int);
@@ -150,6 +157,7 @@ class SensorCalculationRawToPercent : public SensorCalculation {
150157
class SensorCalculationRaw : public SensorCalculation {
151158
public:
152159
SensorCalculationRaw(int);
160+
SensorCalculationRaw(int, String);
153161
Data* calculate(Sensor* sensor, float, bool);
154162
Data* calculate(Sensor* sensor, bool, bool);
155163
};

src/input/i2c/SensorSI1145.cpp

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
/**************************************************************************/
2+
/*!
3+
@file SensorSI1145.cpp
4+
@author M. Fegerl (Sensate Digital Solutions GmbH)
5+
@license GPL (see LICENSE file)
6+
The Sensate ESP8266 firmware is used to connect ESP8266 based hardware
7+
with the Sensate Cloud and the Sensate apps.
8+
9+
----> https://www.sensate.io
10+
11+
SOURCE: https://github.com/sensate-io/firmware-esp8266.git
12+
13+
@section HISTORY
14+
v35 - Added Support for VEML6075 and SI1145 UVI Sensors
15+
*/
16+
/**************************************************************************/
17+
18+
#include "SensorSI1145.h"
19+
20+
extern boolean isResetting;
21+
extern int powerMode;
22+
23+
// Adafruit_SI1145* SensorSI1145::si1145;
24+
SI1145_WE* SensorSI1145::si1145;
25+
int SensorSI1145::lastCycleId = -1;
26+
boolean SensorSI1145::failedInit = false;
27+
28+
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) {
29+
30+
if(si1145==NULL)
31+
si1145 = new SI1145_WE();
32+
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);
38+
}
39+
40+
void SensorSI1145::preCycle(int cycleId)
41+
{
42+
if(cycleId!=lastCycleId)
43+
{
44+
if(failedInit)
45+
{
46+
Serial.println("Trying to re-init SI1145...");
47+
si1145->init();
48+
si1145->enableHighSignalVisRange(); // Gain divided by 14.5
49+
si1145->enableHighSignalIrRange(); // Gain divided by 14.5
50+
si1145->enableMeasurements(PSALSUV_TYPE, AUTO);
51+
failedInit=false;
52+
}
53+
lastCycleId=cycleId;
54+
}
55+
56+
}
57+
58+
Data* SensorSI1145::read(bool shouldPostData)
59+
{
60+
if(!isResetting && !failedInit)
61+
{
62+
if(_calculation->getValueType()=="a")
63+
{
64+
float visLight = si1145->getAlsVisData();
65+
66+
if (visLight==65535.0) {
67+
Serial.println("NAN VisLight!");
68+
failedInit=true;
69+
}
70+
else {
71+
shouldPostData = smartSensorCheck(visLight, _smartValueThreshold, shouldPostData);
72+
return _calculation->calculate(this, visLight, shouldPostData);
73+
}
74+
}
75+
else if(_calculation->getValueType()=="b")
76+
{
77+
float irLight = si1145->getAlsIrData();
78+
79+
if (irLight==65535.0f) {
80+
Serial.println("NAN IrLight!");
81+
failedInit=true;
82+
}
83+
else {
84+
shouldPostData = smartSensorCheck(irLight, _smartValueThreshold, shouldPostData);
85+
return _calculation->calculate(this, irLight, shouldPostData);
86+
}
87+
}
88+
else if(_calculation->getValueType()=="c")
89+
{
90+
float prox = si1145->getPsData();
91+
92+
if (prox==65535.0f) {
93+
Serial.println("NAN Proximiy!");
94+
failedInit=true;
95+
}
96+
else {
97+
shouldPostData = smartSensorCheck(prox, _smartValueThreshold, shouldPostData);
98+
return _calculation->calculate(this, prox, shouldPostData);
99+
}
100+
}
101+
else if(_calculation->getValueType()=="raw")
102+
{
103+
float index = si1145->getUvIndex();
104+
105+
if (index==655.35f) {
106+
Serial.println("NAN UV-Index!");
107+
failedInit=true;
108+
}
109+
else {
110+
shouldPostData = smartSensorCheck(index, _smartValueThreshold, shouldPostData);
111+
return _calculation->calculate(this, index, shouldPostData);
112+
}
113+
}
114+
}
115+
return NULL;
116+
}
117+
118+
boolean SensorSI1145::smartSensorCheck(float currentRawValue, float threshhold, boolean shouldPostData)
119+
{
120+
if(powerMode == 3)
121+
{
122+
if(!shouldPostData)
123+
{
124+
if(!isnan(lastPostedValue))
125+
{
126+
if(lastPostedValue-currentRawValue>threshhold || lastPostedValue-currentRawValue<-threshhold)
127+
{
128+
shouldPostData = true;
129+
}
130+
}
131+
}
132+
133+
if(shouldPostData)
134+
lastPostedValue = currentRawValue;
135+
}
136+
137+
return shouldPostData;
138+
139+
}

0 commit comments

Comments
 (0)