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/* *************************************************************************/
2021extern boolean isResetting;
2122extern int powerMode;
2223
24+ int SensorVEML6075::lastCycleId = -1 ;
25+ boolean SensorVEML6075::failedInit = true ;
26+
2327Adafruit_VEML6075* SensorVEML6075::veml6075;
2428
2529SensorVEML6075::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
5738void 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
6177Data* 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 ;
0 commit comments