2017-10-25 13:27:30 +01:00
|
|
|
/*
|
2019-10-27 10:13:24 +00:00
|
|
|
xsns_11_veml6070.ino - VEML6070 ultra violet light sensor support for Tasmota
|
2017-10-25 13:27:30 +01:00
|
|
|
|
2019-01-01 12:55:01 +00:00
|
|
|
Copyright (C) 2019 Theo Arends
|
2017-10-25 13:27:30 +01:00
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2018-09-25 13:32:24 +01:00
|
|
|
|
|
|
|
-----------------------------------------------------
|
|
|
|
Some words to the meaning of the UV Risk Level:
|
|
|
|
-----------------------------------------------------
|
|
|
|
D_UV_INDEX_1 = "Low" = sun->fun
|
|
|
|
D_UV_INDEX_2 = "Mid" = sun->glases advised
|
|
|
|
D_UV_INDEX_3 = "High" = sun->glases a must
|
|
|
|
D_UV_INDEX_4 = "Danger" = sun->skin burns Level 1
|
|
|
|
D_UV_INDEX_5 = "BurnL1/2" = sun->skin burns level 1..2
|
|
|
|
D_UV_INDEX_6 = "BurnL3" = sun->skin burns with level 3
|
|
|
|
D_UV_INDEX_7 = "OoR" = out of range or unknown
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------------------
|
|
|
|
Version Date Action Description
|
|
|
|
--------------------------------------------------------------------------------------------
|
2018-09-25 16:03:22 +01:00
|
|
|
|
2019-03-08 14:15:42 +00:00
|
|
|
1.0.0.3 20181006 fixed - missing "" around the UV Index text
|
2018-10-06 19:48:26 +01:00
|
|
|
- thanks to Lisa she had tested it on here mqtt system.
|
|
|
|
--
|
2018-09-28 16:34:25 +01:00
|
|
|
1.0.0.2 20180928 tests - same as in version 1.0.0.1
|
|
|
|
cleaned - source code
|
|
|
|
changed - snprintf_P for json and web server output
|
|
|
|
- much more compressed and more professional code
|
|
|
|
added - uv_risk_text to json and web server output
|
|
|
|
changed - switch (function) to be 100% compatible
|
|
|
|
- added Veml6070EverySecond in thought of compatibile
|
|
|
|
added - Veml6070UvTableInit to do this only once to spare time
|
|
|
|
debugging - @Adrian helped me out in case of a %s%s in mqtt_data. Thank You Adrian
|
|
|
|
next - possible i will add the calculation for LAT and LONG coordinates for much more precission (TBD)
|
|
|
|
- show not only the UV Power value in W/m2, possible a @define value to show it as joule value (TBD)
|
|
|
|
- add a #define to select how many characters are shown benhind the decimal point for the UV Index (TBD)
|
|
|
|
---
|
2018-09-25 13:32:24 +01:00
|
|
|
1.0.0.1 20180925 tests - all tests are done with 1x sonoff sv, 2x Wemos D1 (not the mini)
|
|
|
|
- 3 different VEMl6070 sensors from 3 different online shops
|
|
|
|
- all the last three test where good and all looks working so far
|
|
|
|
- all tests are done at high noon with blue sky and a leaned UV light source
|
|
|
|
sience - a special Thank You to my friend the professor. He works in the aerospace industrie. Thank You R.G.T.
|
|
|
|
- all calculations are based on the very good work of Karel Vanicek. Thank You Karel
|
|
|
|
- more information about UV Index and the irradiation power calculation can be found on the internet
|
|
|
|
info - all calculations are based on the effective irradiation from Karel Vanicek
|
|
|
|
- all this was not possible without the work of @arendst. He has done really a lot of basic work/code. Thank You Theo
|
|
|
|
cleaned - source code a little bit
|
|
|
|
added - missing void in function calls: void name(void)
|
|
|
|
added - UV Risk level now defined as UV Index, 0.00 based on NASA standard with text behind the value
|
2018-09-25 16:03:22 +01:00
|
|
|
added - UV Power level now named as UV Power, used W/m2 because official standards
|
2018-09-25 13:32:24 +01:00
|
|
|
added - automatic fill of the uv-risk compare table based on the coefficient calculation
|
|
|
|
added - suspend and wakeup mode for the uv seonsor
|
|
|
|
- current drain in wake-up-ed mode was around 180uA incl. I2C bus
|
|
|
|
- current drain in suspend mode was around 70..80uA incl. I2C bus
|
|
|
|
changed - 2x the power calculation about some incorrent data sheet values
|
|
|
|
changed - float to double calculation because a rare effect on uv compare map filling
|
|
|
|
- in that case @andrethomas was a big help too (while(work){output=lot_of_fun};)
|
2018-09-25 16:03:22 +01:00
|
|
|
added - USE_VEML6070_RSET
|
2018-09-25 13:32:24 +01:00
|
|
|
- in user_config as possible input, different resistor values depending on PCB types
|
|
|
|
added - USE_VEML6070_SHOW_RAW
|
|
|
|
- in user_config, show or show-NOT the uv raw value
|
|
|
|
added - lots of #defines for automatic calulations to get the best possible values
|
|
|
|
added - error messages for LOG_LEVEL_DEBUG
|
2019-10-27 10:13:24 +00:00
|
|
|
added - lots of information in one of the last postings in: https://github.com/arendst/Tasmota/issues/3844
|
2018-09-25 13:32:24 +01:00
|
|
|
debugging - without the softly hit ;-) from @andrethomas about Serial.print i would never done it. Thank You Andre
|
|
|
|
safety - personal, please read this: http://www.segurancaetrabalho.com.br/download/uv_index_karel_vanicek.pdf
|
|
|
|
next - possible i will add the calculation for LAT and LONG coordinates for much more precission
|
|
|
|
- show not only the UV Power value in W/m2, possible a @define value to show it as joule value
|
2018-09-25 16:03:22 +01:00
|
|
|
- add a #define to select how many characters are shown benhind the decimal point for the UV Index
|
2018-09-25 13:32:24 +01:00
|
|
|
---
|
2018-10-06 19:48:26 +01:00
|
|
|
1.0.0.0 20180912 started - further development by mike2nl - https://github.com/mike2nl/Sonoff-Tasmota
|
2019-10-27 10:13:24 +00:00
|
|
|
forked - from arendst/tasmota - https://github.com/arendst/Tasmota
|
2018-10-06 19:48:26 +01:00
|
|
|
base - code base from arendst too
|
2018-09-25 16:03:22 +01:00
|
|
|
|
2017-10-25 13:27:30 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef USE_I2C
|
|
|
|
#ifdef USE_VEML6070
|
|
|
|
/*********************************************************************************************\
|
2018-09-25 13:32:24 +01:00
|
|
|
* VEML6070 - Ultra Violet Light Intensity (UV-A, 100% output by 255nm)
|
2017-11-11 11:33:30 +00:00
|
|
|
*
|
|
|
|
* I2C Address: 0x38 and 0x39
|
2017-10-25 13:27:30 +01:00
|
|
|
\*********************************************************************************************/
|
|
|
|
|
2018-11-06 16:33:51 +00:00
|
|
|
#define XSNS_11 11
|
2019-11-03 16:54:39 +00:00
|
|
|
#define XI2C_12 12 // See I2CDEVICES.md
|
2018-11-06 16:33:51 +00:00
|
|
|
|
2018-09-25 13:32:24 +01:00
|
|
|
#define VEML6070_ADDR_H 0x39 // on some PCB boards the address can be changed by a solder point,
|
|
|
|
#define VEML6070_ADDR_L 0x38 // to have no address conflicts with other I2C sensors and/or hardware
|
|
|
|
#define VEML6070_INTEGRATION_TIME 3 // IT_4 = 500msec integration time, because the precission is 4 times higher then IT_0.5
|
|
|
|
#define VEML6070_ENABLE 1 //
|
|
|
|
#define VEML6070_DISABLE 0 //
|
|
|
|
#define VEML6070_RSET_DEFAULT 270000 // 270K default resistor value 270000 ohm, range from 220K..1Meg
|
|
|
|
#define VEML6070_UV_MAX_INDEX 15 // normal 11, internal on weather laboratories and NASA it's 15 so far the sensor is linear
|
|
|
|
#define VEML6070_UV_MAX_DEFAULT 11 // 11 = public default table values
|
2018-09-25 16:03:22 +01:00
|
|
|
#define VEML6070_POWER_COEFFCIENT 0.025 // based on calculations from Karel Vanicek and reorder by hand
|
|
|
|
#define VEML6070_TABLE_COEFFCIENT 32.86270591 // calculated by hand with help from a friend of mine, a professor which works in aero space things
|
2018-09-25 13:32:24 +01:00
|
|
|
// (resistor, differences, power coefficients and official UV index calculations (LAT & LONG will be added later)
|
|
|
|
|
|
|
|
/********************************************************************************************/
|
2017-10-25 13:27:30 +01:00
|
|
|
|
2018-09-25 13:32:24 +01:00
|
|
|
// globals
|
2018-09-28 16:34:25 +01:00
|
|
|
const char kVemlTypes[] PROGMEM = "VEML6070"; // in preperation of veml6075
|
|
|
|
double uv_risk_map[VEML6070_UV_MAX_INDEX] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
|
|
|
double uvrisk = 0;
|
|
|
|
double uvpower = 0;
|
|
|
|
uint16_t uvlevel = 0;
|
|
|
|
uint8_t veml6070_addr_low = VEML6070_ADDR_L;
|
|
|
|
uint8_t veml6070_addr_high = VEML6070_ADDR_H;
|
|
|
|
uint8_t itime = VEML6070_INTEGRATION_TIME;
|
|
|
|
uint8_t veml6070_type = 0;
|
|
|
|
uint8_t veml6070_valid = 0;
|
|
|
|
char veml6070_name[9];
|
|
|
|
char str_uvrisk_text[10];
|
2017-10-25 13:27:30 +01:00
|
|
|
|
2018-09-25 13:32:24 +01:00
|
|
|
/********************************************************************************************/
|
|
|
|
|
|
|
|
void Veml6070Detect(void)
|
|
|
|
{
|
2019-11-06 16:48:38 +00:00
|
|
|
if (veml6070_type) { return; }
|
|
|
|
if (I2cActive(VEML6070_ADDR_L)) { return; }
|
|
|
|
|
2018-09-28 16:34:25 +01:00
|
|
|
// init the UV sensor
|
|
|
|
Wire.beginTransmission(VEML6070_ADDR_L);
|
2018-09-25 13:32:24 +01:00
|
|
|
Wire.write((itime << 2) | 0x02);
|
|
|
|
uint8_t status = Wire.endTransmission();
|
2018-09-28 16:34:25 +01:00
|
|
|
// action on status
|
2018-09-25 13:32:24 +01:00
|
|
|
if (!status) {
|
2019-11-06 16:48:38 +00:00
|
|
|
I2cSetActive(VEML6070_ADDR_L);
|
2018-09-28 16:34:25 +01:00
|
|
|
veml6070_type = 1;
|
2019-11-06 16:48:38 +00:00
|
|
|
Veml6070UvTableInit(); // 1[ms], initalize the UV compare table only once
|
2018-09-28 16:38:06 +01:00
|
|
|
uint8_t veml_model = 0;
|
|
|
|
GetTextIndexed(veml6070_name, sizeof(veml6070_name), veml_model, kVemlTypes);
|
2019-11-06 16:48:38 +00:00
|
|
|
AddLog_P2(LOG_LEVEL_INFO, S_LOG_I2C_FOUND_AT, "VEML6070", VEML6070_ADDR_L);
|
2018-09-25 13:32:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************************/
|
|
|
|
|
2018-09-28 16:34:25 +01:00
|
|
|
void Veml6070UvTableInit(void)
|
2018-09-25 13:32:24 +01:00
|
|
|
{
|
2018-09-28 16:34:25 +01:00
|
|
|
// fill the uv-risk compare table once, based on the coefficient calculation
|
2019-06-30 15:44:36 +01:00
|
|
|
for (uint32_t i = 0; i < VEML6070_UV_MAX_INDEX; i++) {
|
2018-09-28 16:34:25 +01:00
|
|
|
#ifdef USE_VEML6070_RSET
|
|
|
|
if ( (USE_VEML6070_RSET >= 220000) && (USE_VEML6070_RSET <= 1000000) ) {
|
|
|
|
uv_risk_map[i] = ( (USE_VEML6070_RSET / VEML6070_TABLE_COEFFCIENT) / VEML6070_UV_MAX_DEFAULT ) * (i+1);
|
|
|
|
} else {
|
|
|
|
uv_risk_map[i] = ( (VEML6070_RSET_DEFAULT / VEML6070_TABLE_COEFFCIENT) / VEML6070_UV_MAX_DEFAULT ) * (i+1);
|
2019-03-08 14:15:42 +00:00
|
|
|
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "VEML6070 resistor error %d"), USE_VEML6070_RSET);
|
2018-09-28 16:34:25 +01:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
uv_risk_map[i] = ( (VEML6070_RSET_DEFAULT / VEML6070_TABLE_COEFFCIENT) / VEML6070_UV_MAX_DEFAULT ) * (i+1);
|
2019-03-08 14:15:42 +00:00
|
|
|
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "VEML6070 resistor default used %d"), VEML6070_RSET_DEFAULT);
|
2018-09-28 16:34:25 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
2018-09-25 13:32:24 +01:00
|
|
|
|
2018-09-28 16:34:25 +01:00
|
|
|
/********************************************************************************************/
|
|
|
|
|
|
|
|
void Veml6070EverySecond(void)
|
|
|
|
{
|
|
|
|
// all = 10..15[ms]
|
|
|
|
if (11 == (uptime %100)) {
|
2019-11-06 16:48:38 +00:00
|
|
|
if (!veml6070_type) {
|
|
|
|
// Veml6070ModeCmd(1); // on = 1[ms], wakeup the UV sensor - THIS CORRUPTS OTHER I2C DEVICES
|
|
|
|
Veml6070Detect(); // 1[ms], check for sensor and init with IT time
|
|
|
|
// Veml6070ModeCmd(0); // off = 5[ms], suspend the UV sensor - THIS CORRUPTS OTHER I2C DEVICES
|
|
|
|
}
|
2018-09-25 13:32:24 +01:00
|
|
|
} else {
|
2019-11-06 16:48:38 +00:00
|
|
|
if (veml6070_type) {
|
|
|
|
Veml6070ModeCmd(1); // 1[ms], wakeup the UV sensor
|
|
|
|
uvlevel = Veml6070ReadUv(); // 1..2[ms], get UV raw values
|
|
|
|
uvrisk = Veml6070UvRiskLevel(uvlevel); // 0..1[ms], get UV risk level
|
|
|
|
uvpower = Veml6070UvPower(uvrisk); // 2[ms], get UV power in W/m2
|
|
|
|
Veml6070ModeCmd(0); // off = 5[ms], suspend the UV sensor
|
|
|
|
}
|
2018-09-25 13:32:24 +01:00
|
|
|
}
|
2018-09-28 16:34:25 +01:00
|
|
|
}
|
2018-09-25 16:03:22 +01:00
|
|
|
|
2018-09-28 16:34:25 +01:00
|
|
|
/********************************************************************************************/
|
2018-09-25 13:32:24 +01:00
|
|
|
|
2019-01-28 13:08:33 +00:00
|
|
|
void Veml6070ModeCmd(bool mode_cmd)
|
2018-09-28 16:34:25 +01:00
|
|
|
{
|
|
|
|
// mode_cmd 1 = on = 1[ms]
|
|
|
|
// mode_cmd 0 = off = 2[ms]
|
|
|
|
Wire.beginTransmission(VEML6070_ADDR_L);
|
|
|
|
Wire.write((mode_cmd << 0) | 0x02 | (itime << 2));
|
|
|
|
uint8_t status = Wire.endTransmission();
|
|
|
|
// action on status
|
2018-09-25 13:32:24 +01:00
|
|
|
if (!status) {
|
2019-03-08 14:15:42 +00:00
|
|
|
AddLog_P2(LOG_LEVEL_DEBUG, S_LOG_I2C_FOUND_AT, "VEML6070 mode_cmd", VEML6070_ADDR_L);
|
2018-09-25 13:32:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************************/
|
|
|
|
|
|
|
|
uint16_t Veml6070ReadUv(void)
|
2017-10-25 13:27:30 +01:00
|
|
|
{
|
2018-09-28 16:34:25 +01:00
|
|
|
uint16_t uv_raw = 0;
|
|
|
|
// read high byte
|
2017-10-25 13:27:30 +01:00
|
|
|
if (Wire.requestFrom(VEML6070_ADDR_H, 1) != 1) {
|
|
|
|
return -1;
|
|
|
|
}
|
2018-09-28 16:34:25 +01:00
|
|
|
uv_raw = Wire.read();
|
|
|
|
uv_raw <<= 8;
|
|
|
|
// read low byte
|
2017-10-25 13:27:30 +01:00
|
|
|
if (Wire.requestFrom(VEML6070_ADDR_L, 1) != 1) {
|
|
|
|
return -1;
|
|
|
|
}
|
2018-09-28 16:34:25 +01:00
|
|
|
uv_raw |= Wire.read();
|
|
|
|
// high and low done
|
|
|
|
return uv_raw;
|
2017-10-25 13:27:30 +01:00
|
|
|
}
|
|
|
|
|
2017-11-04 15:36:51 +00:00
|
|
|
/********************************************************************************************/
|
|
|
|
|
2018-09-25 13:32:24 +01:00
|
|
|
double Veml6070UvRiskLevel(uint16_t uv_level)
|
2017-10-25 13:27:30 +01:00
|
|
|
{
|
2018-09-25 13:32:24 +01:00
|
|
|
double risk = 0;
|
|
|
|
if (uv_level < uv_risk_map[VEML6070_UV_MAX_INDEX-1]) {
|
2018-09-28 16:34:25 +01:00
|
|
|
risk = (double)uv_level / uv_risk_map[0];
|
|
|
|
// generate uv-risk string
|
|
|
|
if ( (risk >= 0) && (risk <= 2.9) ) { snprintf_P(str_uvrisk_text, sizeof(str_uvrisk_text), D_UV_INDEX_1); }
|
|
|
|
else if ( (risk >= 3.0) && (risk <= 5.9) ) { snprintf_P(str_uvrisk_text, sizeof(str_uvrisk_text), D_UV_INDEX_2); }
|
|
|
|
else if ( (risk >= 6.0) && (risk <= 7.9) ) { snprintf_P(str_uvrisk_text, sizeof(str_uvrisk_text), D_UV_INDEX_3); }
|
|
|
|
else if ( (risk >= 8.0) && (risk <= 10.9) ) { snprintf_P(str_uvrisk_text, sizeof(str_uvrisk_text), D_UV_INDEX_4); }
|
|
|
|
else if ( (risk >= 11.0) && (risk <= 12.9) ) { snprintf_P(str_uvrisk_text, sizeof(str_uvrisk_text), D_UV_INDEX_5); }
|
|
|
|
else if ( (risk >= 13.0) && (risk <= 25.0) ) { snprintf_P(str_uvrisk_text, sizeof(str_uvrisk_text), D_UV_INDEX_6); }
|
|
|
|
else { snprintf_P(str_uvrisk_text, sizeof(str_uvrisk_text), D_UV_INDEX_7); }
|
|
|
|
return risk;
|
2018-09-25 13:32:24 +01:00
|
|
|
} else {
|
2018-09-28 16:34:25 +01:00
|
|
|
// out of range and much to high - it must be outerspace or sensor damaged
|
|
|
|
snprintf_P(str_uvrisk_text, sizeof(str_uvrisk_text), D_UV_INDEX_7);
|
|
|
|
return ( risk = 99 );
|
2019-03-08 14:15:42 +00:00
|
|
|
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "VEML6070 out of range %d"), risk);
|
2017-10-25 13:27:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-25 13:32:24 +01:00
|
|
|
/********************************************************************************************/
|
|
|
|
|
|
|
|
double Veml6070UvPower(double uvrisk)
|
|
|
|
{
|
|
|
|
// based on calculations for effective irradiation from Karel Vanicek
|
2018-09-28 16:34:25 +01:00
|
|
|
double power = 0;
|
|
|
|
return ( power = VEML6070_POWER_COEFFCIENT * uvrisk );
|
2018-09-25 13:32:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************************/
|
2018-09-28 16:34:25 +01:00
|
|
|
// normaly in i18n.h, Line 520 .. 525
|
2018-09-25 13:32:24 +01:00
|
|
|
|
2017-10-25 13:27:30 +01:00
|
|
|
#ifdef USE_WEBSERVER
|
2018-09-25 13:32:24 +01:00
|
|
|
// {s} = <tr><th>, {m} = </th><td>, {e} = </td></tr>
|
|
|
|
#ifdef USE_VEML6070_SHOW_RAW
|
2019-03-19 16:31:43 +00:00
|
|
|
const char HTTP_SNS_UV_LEVEL[] PROGMEM = "{s}VEML6070 " D_UV_LEVEL "{m}%s " D_UNIT_INCREMENTS "{e}";
|
2018-09-25 13:32:24 +01:00
|
|
|
#endif // USE_VEML6070_SHOW_RAW
|
|
|
|
// different uv index level texts
|
2019-03-19 16:31:43 +00:00
|
|
|
const char HTTP_SNS_UV_INDEX[] PROGMEM = "{s}VEML6070 " D_UV_INDEX "{m}%s %s{e}";
|
|
|
|
const char HTTP_SNS_UV_POWER[] PROGMEM = "{s}VEML6070 " D_UV_POWER "{m}%s " D_UNIT_WATT_METER_QUADRAT "{e}";
|
2017-11-04 15:36:51 +00:00
|
|
|
#endif // USE_WEBSERVER
|
2017-11-03 17:07:25 +00:00
|
|
|
|
2018-09-25 13:32:24 +01:00
|
|
|
/********************************************************************************************/
|
|
|
|
|
2019-01-28 13:08:33 +00:00
|
|
|
void Veml6070Show(bool json)
|
2017-10-25 13:27:30 +01:00
|
|
|
{
|
|
|
|
if (veml6070_type) {
|
2018-09-25 13:32:24 +01:00
|
|
|
// convert double values to string
|
2018-12-21 15:17:06 +00:00
|
|
|
char str_uvlevel[33]; // e.g. 99999 inc = UVLevel
|
2018-09-28 16:34:25 +01:00
|
|
|
dtostrfd((double)uvlevel, 0, str_uvlevel);
|
2018-12-21 15:17:06 +00:00
|
|
|
char str_uvrisk[33]; // e.g. 25.99 text = UvIndex
|
2018-09-25 13:32:24 +01:00
|
|
|
dtostrfd(uvrisk, 2, str_uvrisk);
|
2018-12-21 15:17:06 +00:00
|
|
|
char str_uvpower[33]; // e.g. 0.399 W/m² = UvPower
|
2018-09-25 13:32:24 +01:00
|
|
|
dtostrfd(uvpower, 3, str_uvpower);
|
2017-11-04 15:36:51 +00:00
|
|
|
if (json) {
|
2018-09-25 13:32:24 +01:00
|
|
|
#ifdef USE_VEML6070_SHOW_RAW
|
2019-03-23 16:57:31 +00:00
|
|
|
ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_UV_LEVEL "\":%s,\"" D_JSON_UV_INDEX "\":%s,\"" D_JSON_UV_INDEX_TEXT "\":\"%s\",\"" D_JSON_UV_POWER "\":%s}"),
|
|
|
|
veml6070_name, str_uvlevel, str_uvrisk, str_uvrisk_text, str_uvpower);
|
2018-09-28 16:34:25 +01:00
|
|
|
#else
|
2019-03-23 16:57:31 +00:00
|
|
|
ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_UV_INDEX "\":%s,\"" D_JSON_UV_INDEX_TEXT "\":\"%s\",\"" D_JSON_UV_POWER "\":%s}"),
|
|
|
|
veml6070_name, str_uvrisk, str_uvrisk_text, str_uvpower);
|
2018-09-25 13:32:24 +01:00
|
|
|
#endif // USE_VEML6070_SHOW_RAW
|
2017-11-04 15:36:51 +00:00
|
|
|
#ifdef USE_DOMOTICZ
|
2018-09-28 16:34:25 +01:00
|
|
|
if (0 == tele_period) { DomoticzSensor(DZ_ILLUMINANCE, uvlevel); }
|
2017-11-04 15:36:51 +00:00
|
|
|
#endif // USE_DOMOTICZ
|
|
|
|
#ifdef USE_WEBSERVER
|
|
|
|
} else {
|
2018-09-25 13:32:24 +01:00
|
|
|
#ifdef USE_VEML6070_SHOW_RAW
|
2019-03-19 16:31:43 +00:00
|
|
|
WSContentSend_PD(HTTP_SNS_UV_LEVEL, str_uvlevel);
|
2018-09-25 13:32:24 +01:00
|
|
|
#endif // USE_VEML6070_SHOW_RAW
|
2019-03-19 16:31:43 +00:00
|
|
|
WSContentSend_PD(HTTP_SNS_UV_INDEX, str_uvrisk, str_uvrisk_text);
|
|
|
|
WSContentSend_PD(HTTP_SNS_UV_POWER, str_uvpower);
|
2017-11-04 15:36:51 +00:00
|
|
|
#endif // USE_WEBSERVER
|
|
|
|
}
|
2017-10-25 13:27:30 +01:00
|
|
|
}
|
|
|
|
}
|
2017-11-03 17:07:25 +00:00
|
|
|
|
|
|
|
/*********************************************************************************************\
|
|
|
|
* Interface
|
|
|
|
\*********************************************************************************************/
|
|
|
|
|
2019-01-28 13:08:33 +00:00
|
|
|
bool Xsns11(uint8_t function)
|
2017-11-03 17:07:25 +00:00
|
|
|
{
|
2019-11-06 16:48:38 +00:00
|
|
|
if (!I2cEnabled(XI2C_12)) { return false; }
|
2019-11-03 16:54:39 +00:00
|
|
|
|
2019-01-28 13:08:33 +00:00
|
|
|
bool result = false;
|
2017-11-03 17:07:25 +00:00
|
|
|
|
2019-11-04 09:38:05 +00:00
|
|
|
switch (function) {
|
|
|
|
case FUNC_EVERY_SECOND:
|
|
|
|
Veml6070EverySecond(); // 10..15[ms], tested with OLED display, do all the actions needed to get all sensor values
|
|
|
|
break;
|
|
|
|
case FUNC_JSON_APPEND:
|
|
|
|
Veml6070Show(1);
|
|
|
|
break;
|
2017-11-03 17:07:25 +00:00
|
|
|
#ifdef USE_WEBSERVER
|
2019-11-04 09:38:05 +00:00
|
|
|
case FUNC_WEB_SENSOR:
|
|
|
|
Veml6070Show(0);
|
|
|
|
break;
|
2017-11-03 17:07:25 +00:00
|
|
|
#endif // USE_WEBSERVER
|
2019-11-06 16:48:38 +00:00
|
|
|
case FUNC_INIT:
|
|
|
|
Veml6070Detect(); // 1[ms], detect and init the sensor
|
|
|
|
break;
|
2017-11-03 17:07:25 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-10-25 13:27:30 +01:00
|
|
|
#endif // USE_VEML6070
|
|
|
|
#endif // USE_I2C
|