Skip to content

Commit

Permalink
Added Support for VEML6075 and SI1145 UVI Sensors
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel-Sensate committed Dec 4, 2020
1 parent c4fb263 commit ea91feb
Show file tree
Hide file tree
Showing 10 changed files with 393 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ Find out more at https://www.sensate.io
- Soligen2010 fork of Adafruit_ADS1x15 (https://github.com/soligen2010/Adafruit_ADS1X15) v1.2.1
- Adafruit Unified Sensor Library (https://github.com/adafruit/Adafruit_Sensor v1.1.2)
- Adafruit DHT Sensor Library (https://github.com/adafruit/DHT-sensor-library v1.3.8)
- Adafruit BusIO (https://github.com/adafruit/Adafruit_BusIO v1.7.0)
- Adafruit VEML6075 (https://github.com/adafruit/Adafruit_VEML6075 v2.1.0)
- OneWire (https://www.pjrc.com/teensy/td_libs_OneWire.html v2.3.5)
- DallasTemperature (https://github.com/milesburton/Arduino-Temperature-Control-Library v3.8.0)
- BME280 (https://github.com/finitespace/BME280 v2.3.0)
- Adafruit BME680 (https://github.com/adafruit/Adafruit_BME680 v1.0.7)
- Max44009 (https://github.com/dantudose/MAX44009 v1.2.3)
- BH1750 (https://github.com/claws/BH1750)
- MQTT Client Library (https://github.com/knolleary/pubsubclient v2.8.0)
- SI1145 (https://github.com/wollewald/SI1145_WE v1.1.4)

Windows Users:
Use https://github.com/nodemcu/nodemcu-flasher for flashing the firmware.
Expand Down
5 changes: 3 additions & 2 deletions firmware-esp8266.ino
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
v35 - Added Support for VEML6075 and SI1145 UVI Sensors
v34 - Added Generic Analog Sensor Support
v33 - Added Digital Sensor Switch Support, Improved MQTT Setup Routine
v32 - Added MQTT Support!
Expand All @@ -28,7 +29,7 @@

Display* display = NULL;

int currentVersion = 34;
int currentVersion = 35;
boolean printMemory = false;

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

extern String name = "Bridge";
extern String type = "ESP8266";
extern String ucType = "ESP8266";

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

Expand Down
29 changes: 27 additions & 2 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
v35 - Added Support for VEML6075 and SI1145 UVI Sensors
v34 - Added Generic Analog Sensor Support
v33 - Added Digital Sensor Switch Support
v32 - Added MQTT Support!
Expand Down Expand Up @@ -40,7 +41,7 @@ extern struct rst_info resetInfo;

extern String name;
extern String board;
extern String type;
extern String ucType;

extern long powerOnDelay;
extern String powerSavePort;
Expand Down Expand Up @@ -110,7 +111,7 @@ bool registerBridge()
pwdHashString = String(pwdHashString);
}

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

int httpCode = httpClient.POST(message);

Expand Down Expand Up @@ -639,12 +640,20 @@ void configureExpansionPort(int portNumber, JsonObject& portConfig) {
calc = new SensorCalculationDirectPPM(portNumber);
else if (portConfig["s"]["cf"] == "DIRECT_NONE")
calc = new SensorCalculationDirectNone(portNumber);
else if (portConfig["s"]["cf"] == "DIRECT_WPM2")
calc = new SensorCalculationDirectWpm2(portNumber);
else if (portConfig["s"]["cf"] == "CALC_METER")
calc = new SensorCalculationCalcAltitude(portNumber);
else if (portConfig["s"]["cf"] == "CALC_RAW_PERCENT")
calc = new SensorCalculationRawToPercent(portConfig["c1"], portConfig["c2"], portNumber);
else if (portConfig["s"]["cf"] == "RAW")
calc = new SensorCalculationRaw(portNumber);
else if (portConfig["s"]["cf"] == "RAW_A")
calc = new SensorCalculationRaw(portNumber, "a");
else if (portConfig["s"]["cf"] == "RAW_B")
calc = new SensorCalculationRaw(portNumber, "b");
else if (portConfig["s"]["cf"] == "RAW_C")
calc = new SensorCalculationRaw(portNumber, "c");
else if (portConfig["s"]["cf"] == "CALC_RAW_VREF")
calc = new SensorCalculationRawToVoltage(portConfig["c1"], portConfig["c2"], portNumber);

Expand Down Expand Up @@ -705,6 +714,14 @@ void configureExpansionPort(int portNumber, JsonObject& portConfig) {
{
addSensor(new SensorBH1750(portConfig["id"], portConfig["c"], portConfig["sn"], portConfig["n"], portConfig["ec1"], portConfig["ec2"], refreshInterval, postDataInterval, portConfig["s"]["svt"], calc));
}
else if (portConfig["et"] == "VEML6075")
{
addSensor(new SensorVEML6075(portConfig["id"], portConfig["c"], portConfig["sn"], portConfig["n"], portConfig["ec1"], portConfig["ec2"], refreshInterval, postDataInterval, portConfig["s"]["svt"], calc));
}
else if (portConfig["et"] == "SI1145")
{
addSensor(new SensorSI1145(portConfig["id"], portConfig["c"], portConfig["sn"], portConfig["n"], portConfig["ec1"], portConfig["ec2"], refreshInterval, postDataInterval, portConfig["s"]["svt"], calc));
}

}

Expand Down Expand Up @@ -747,12 +764,20 @@ void configurePort(int portNumber, JsonObject& portConfig) {
calc = new SensorCalculationDirectPPM(portNumber);
else if (portConfig["s"]["cf"] == "DIRECT_NONE")
calc = new SensorCalculationDirectNone(portNumber);
else if (portConfig["s"]["cf"] == "DIRECT_WPM2")
calc = new SensorCalculationDirectWpm2(portNumber);
else if (portConfig["s"]["cf"] == "CALC_METER")
calc = new SensorCalculationCalcAltitude(portNumber);
else if (portConfig["s"]["cf"] == "CALC_RAW_PERCENT")
calc = new SensorCalculationRawToPercent(portConfig["c1"], portConfig["c2"], portNumber);
else if (portConfig["s"]["cf"] == "RAW")
calc = new SensorCalculationRaw(portNumber);
else if (portConfig["s"]["cf"] == "RAW_A")
calc = new SensorCalculationRaw(portNumber, "a");
else if (portConfig["s"]["cf"] == "RAW_B")
calc = new SensorCalculationRaw(portNumber, "b");
else if (portConfig["s"]["cf"] == "RAW_C")
calc = new SensorCalculationRaw(portNumber, "c");
else if (portConfig["s"]["cf"] == "CALC_RAW_VREF")
calc = new SensorCalculationRawToVoltage(portConfig["c1"], portConfig["c2"], portNumber);

Expand Down
3 changes: 3 additions & 0 deletions src/controller/Bridge.h
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
v35 - Added Support for VEML6075 and SI1145 UVI Sensors
v33 - Added Digital Sensor Switch Support
v32 - Added MQTT Support!
v29 - First Public Release
Expand All @@ -35,6 +36,8 @@
#include "../input/i2c/SensorBME680.h"
#include "../input/i2c/SensorMax44009.h"
#include "../input/i2c/SensorBH1750.h"
#include "../input/i2c/SensorVEML6075.h"
#include "../input/i2c/SensorSI1145.h"
#include "../input/onewire/SensorDHT.h"
#include "../input/onewire/SensorDallas.h"
#include "../output/display/DisplayOLED128.h"
Expand Down
24 changes: 24 additions & 0 deletions src/input/SensorCalculation.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
v35 - Added Support for VEML6075 and SI1145 UVI Sensors
v34 - Added Generic Analog Sensor Support
v33 - Added Digital Sensor Switch Support
v32 - Added MQTT Support!
Expand Down Expand Up @@ -153,6 +154,13 @@ SensorCalculationDirectNone::SensorCalculationDirectNone(int portNumber) : Senso
_portNumber = portNumber;
}

SensorCalculationDirectWpm2::SensorCalculationDirectWpm2(int portNumber) : SensorCalculation()
{
_valueType = "irradiance";
_valueUnit = "W/m²";
_portNumber = portNumber;
}

SensorCalculationCalcAltitude::SensorCalculationCalcAltitude(int portNumber) : SensorCalculation()
{
_valueType = "altitude";
Expand Down Expand Up @@ -185,6 +193,13 @@ SensorCalculationRaw::SensorCalculationRaw(int portNumber) : SensorCalculation()
_portNumber = portNumber;
}

SensorCalculationRaw::SensorCalculationRaw(int portNumber, String valueUnit) : SensorCalculation()
{
_valueType = valueUnit;
_valueUnit = "";
_portNumber = portNumber;
}

Data* SensorCalculation::calculate(Sensor* sensor, float rawValue, bool postData)
{
return NULL;
Expand Down Expand Up @@ -324,6 +339,15 @@ Data* SensorCalculationDirectPPM::calculate(Sensor* sensor, float rawValue, bool
return new Data (sensor, rawValue, "PPM");
}

Data* SensorCalculationDirectWpm2::calculate(Sensor* sensor, float rawValue, bool postData)
{
if(display!=NULL && _portNumber>=0)
display->drawValue(_portNumber, sensor->getName(), sensor->getShortName(), rawValue, _valueUnit);
if(!postData)
return NULL;
return new Data (sensor, rawValue, "WPM2");
}

Data* SensorCalculationDirectNone::calculate(Sensor* sensor, float rawValue, bool postData)
{
if(display!=NULL && _portNumber>=0)
Expand Down
8 changes: 8 additions & 0 deletions src/input/SensorCalculation.h
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
v35 - Added Support for VEML6075 and SI1145 UVI Sensors
v34 - Added Generic Analog Sensor Support
v33 - Added Digital Sensor Switch Support
v32 - Added MQTT Support!
Expand Down Expand Up @@ -133,6 +134,12 @@ class SensorCalculationDirectPPM : public SensorCalculation {
Data* calculate(Sensor* sensor, float, bool);
};

class SensorCalculationDirectWpm2 : public SensorCalculation {
public:
SensorCalculationDirectWpm2(int);
Data* calculate(Sensor* sensor, float, bool);
};

class SensorCalculationCalcAltitude : public SensorCalculation {
public:
SensorCalculationCalcAltitude(int);
Expand All @@ -150,6 +157,7 @@ class SensorCalculationRawToPercent : public SensorCalculation {
class SensorCalculationRaw : public SensorCalculation {
public:
SensorCalculationRaw(int);
SensorCalculationRaw(int, String);
Data* calculate(Sensor* sensor, float, bool);
Data* calculate(Sensor* sensor, bool, bool);
};
Expand Down
139 changes: 139 additions & 0 deletions src/input/i2c/SensorSI1145.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/**************************************************************************/
/*!
@file SensorSI1145.cpp
@author M. Fegerl (Sensate Digital Solutions GmbH)
@license GPL (see LICENSE file)
The Sensate ESP8266 firmware is used to connect ESP8266 based hardware
with the Sensate Cloud and the Sensate apps.
----> https://www.sensate.io
SOURCE: https://github.com/sensate-io/firmware-esp8266.git
@section HISTORY
v35 - Added Support for VEML6075 and SI1145 UVI Sensors
*/
/**************************************************************************/

#include "SensorSI1145.h"

extern boolean isResetting;
extern int powerMode;

// Adafruit_SI1145* SensorSI1145::si1145;
SI1145_WE* SensorSI1145::si1145;
int SensorSI1145::lastCycleId = -1;
boolean SensorSI1145::failedInit = false;

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) {

if(si1145==NULL)
si1145 = new SI1145_WE();

si1145->init();

si1145->enableHighSignalVisRange(); // Gain divided by 14.5
si1145->enableHighSignalIrRange(); // Gain divided by 14.5
si1145->enableMeasurements(PSALSUV_TYPE, AUTO);
}

void SensorSI1145::preCycle(int cycleId)
{
if(cycleId!=lastCycleId)
{
if(failedInit)
{
Serial.println("Trying to re-init SI1145...");
si1145->init();
si1145->enableHighSignalVisRange(); // Gain divided by 14.5
si1145->enableHighSignalIrRange(); // Gain divided by 14.5
si1145->enableMeasurements(PSALSUV_TYPE, AUTO);
failedInit=false;
}
lastCycleId=cycleId;
}

}

Data* SensorSI1145::read(bool shouldPostData)
{
if(!isResetting && !failedInit)
{
if(_calculation->getValueType()=="a")
{
float visLight = si1145->getAlsVisData();

if (visLight==65535.0) {
Serial.println("NAN VisLight!");
failedInit=true;
}
else {
shouldPostData = smartSensorCheck(visLight, _smartValueThreshold, shouldPostData);
return _calculation->calculate(this, visLight, shouldPostData);
}
}
else if(_calculation->getValueType()=="b")
{
float irLight = si1145->getAlsIrData();

if (irLight==65535.0f) {
Serial.println("NAN IrLight!");
failedInit=true;
}
else {
shouldPostData = smartSensorCheck(irLight, _smartValueThreshold, shouldPostData);
return _calculation->calculate(this, irLight, shouldPostData);
}
}
else if(_calculation->getValueType()=="c")
{
float prox = si1145->getPsData();

if (prox==65535.0f) {
Serial.println("NAN Proximiy!");
failedInit=true;
}
else {
shouldPostData = smartSensorCheck(prox, _smartValueThreshold, shouldPostData);
return _calculation->calculate(this, prox, shouldPostData);
}
}
else if(_calculation->getValueType()=="raw")
{
float index = si1145->getUvIndex();

if (index==655.35f) {
Serial.println("NAN UV-Index!");
failedInit=true;
}
else {
shouldPostData = smartSensorCheck(index, _smartValueThreshold, shouldPostData);
return _calculation->calculate(this, index, shouldPostData);
}
}
}
return NULL;
}

boolean SensorSI1145::smartSensorCheck(float currentRawValue, float threshhold, boolean shouldPostData)
{
if(powerMode == 3)
{
if(!shouldPostData)
{
if(!isnan(lastPostedValue))
{
if(lastPostedValue-currentRawValue>threshhold || lastPostedValue-currentRawValue<-threshhold)
{
shouldPostData = true;
}
}
}

if(shouldPostData)
lastPostedValue = currentRawValue;
}

return shouldPostData;

}
Loading

0 comments on commit ea91feb

Please sign in to comment.