Merge pull request #3893 from mike2nl/development

changed driver xsns_11_veml6070.ino
This commit is contained in:
Theo Arends 2018-09-25 15:57:22 +02:00 committed by GitHub
commit 104eef4829
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 359 additions and 23 deletions

View File

@ -163,7 +163,15 @@
#define D_USER "Потребител"
#define D_UTC_TIME "UTC"
#define D_UV_INDEX "UV индекс"
#define D_UV_INDEX_1 "Low"
#define D_UV_INDEX_2 "Mid"
#define D_UV_INDEX_3 "High"
#define D_UV_INDEX_4 "Danger"
#define D_UV_INDEX_5 "BurnL1/2"
#define D_UV_INDEX_6 "BurnL3"
#define D_UV_INDEX_7 "OoR"
#define D_UV_LEVEL "Ниво на ултравиолетово излъчване"
#define D_UV_POWER "UV Power"
#define D_VERSION "Версия"
#define D_VOLTAGE "Напрежение"
#define D_WARMLIGHT "Топла"
@ -514,6 +522,7 @@
#define D_UNIT_VOLT "V"
#define D_UNIT_WATT "W"
#define D_UNIT_WATTHOUR "Wh"
#define D_UNIT_WATT_METER_QUADRAT "W/m²"
// Log message prefix
#define D_LOG_APPLICATION "APP: " // Application

View File

@ -163,7 +163,15 @@
#define D_USER "Uživatel"
#define D_UTC_TIME "UTC"
#define D_UV_INDEX "UV Index"
#define D_UV_INDEX_1 "Low"
#define D_UV_INDEX_2 "Mid"
#define D_UV_INDEX_3 "High"
#define D_UV_INDEX_4 "Danger"
#define D_UV_INDEX_5 "BurnL1/2"
#define D_UV_INDEX_6 "BurnL3"
#define D_UV_INDEX_7 "OoR"
#define D_UV_LEVEL "úroveň UV"
#define D_UV_POWER "UV Power"
#define D_VERSION "Verze"
#define D_VOLTAGE "Napětí"
#define D_WARMLIGHT "Teplé světlo"
@ -514,6 +522,7 @@
#define D_UNIT_VOLT "V"
#define D_UNIT_WATT "W"
#define D_UNIT_WATTHOUR "Wh"
#define D_UNIT_WATT_METER_QUADRAT "W/m²"
// Log message prefix
#define D_LOG_APPLICATION "APP: " // Application

View File

@ -163,7 +163,14 @@
#define D_USER "Benutzer"
#define D_UTC_TIME "UTC"
#define D_UV_INDEX "UV-Index"
#define D_UV_INDEX_2 "Mid"
#define D_UV_INDEX_3 "High"
#define D_UV_INDEX_4 "Danger"
#define D_UV_INDEX_5 "BurnL1/2"
#define D_UV_INDEX_6 "BurnL3"
#define D_UV_INDEX_7 "OoR"
#define D_UV_LEVEL "UV-Level"
#define D_UV_POWER "UV Power"
#define D_VERSION "Version"
#define D_VOLTAGE "Spannung"
#define D_WARMLIGHT "warm"
@ -514,6 +521,7 @@
#define D_UNIT_VOLT "V"
#define D_UNIT_WATT "W"
#define D_UNIT_WATTHOUR "Wh"
#define D_UNIT_WATT_METER_QUADRAT "W/m²"
// Log message prefix
#define D_LOG_APPLICATION "APP: " // Application

View File

@ -163,7 +163,14 @@
#define D_USER "Χρήστης"
#define D_UTC_TIME "UTC"
#define D_UV_INDEX "UV Index"
#define D_UV_INDEX_2 "Mid"
#define D_UV_INDEX_3 "High"
#define D_UV_INDEX_4 "Danger"
#define D_UV_INDEX_5 "BurnL1/2"
#define D_UV_INDEX_6 "BurnL3"
#define D_UV_INDEX_7 "OoR"
#define D_UV_LEVEL "Επίπεδο UV"
#define D_UV_POWER "UV Power"
#define D_VERSION "Έκδοση"
#define D_VOLTAGE "Τάση"
#define D_WARMLIGHT "Ζεστό"
@ -514,6 +521,7 @@
#define D_UNIT_VOLT "V"
#define D_UNIT_WATT "W"
#define D_UNIT_WATTHOUR "Wh"
#define D_UNIT_WATT_METER_QUADRAT "W/m²"
// Log message prefix
#define D_LOG_APPLICATION "APP: " // Application

View File

@ -163,7 +163,14 @@
#define D_USER "User"
#define D_UTC_TIME "UTC"
#define D_UV_INDEX "UV Index"
#define D_UV_INDEX_2 "Mid"
#define D_UV_INDEX_3 "High"
#define D_UV_INDEX_4 "Danger"
#define D_UV_INDEX_5 "BurnL1/2"
#define D_UV_INDEX_6 "BurnL3"
#define D_UV_INDEX_7 "OoR"
#define D_UV_LEVEL "UV Level"
#define D_UV_POWER "UV Power"
#define D_VERSION "Version"
#define D_VOLTAGE "Voltage"
#define D_WARMLIGHT "Warm"
@ -514,6 +521,7 @@
#define D_UNIT_WATT "W"
#define D_UNIT_WATTHOUR "Wh"
#define D_UNIT_HERTZ "Hz"
#define D_UNIT_WATT_METER_QUADRAT "W/m²"
// Log message prefix
#define D_LOG_APPLICATION "APP: " // Application

View File

@ -163,7 +163,14 @@
#define D_USER "Usuario"
#define D_UTC_TIME "UTC"
#define D_UV_INDEX "Índice UV"
#define D_UV_INDEX_2 "Mid"
#define D_UV_INDEX_3 "High"
#define D_UV_INDEX_4 "Danger"
#define D_UV_INDEX_5 "BurnL1/2"
#define D_UV_INDEX_6 "BurnL3"
#define D_UV_INDEX_7 "OoR"
#define D_UV_LEVEL "Nivel UV"
#define D_UV_POWER "UV Power"
#define D_VERSION "Versión"
#define D_VOLTAGE "Tensión"
#define D_WARMLIGHT "Cálida"
@ -514,6 +521,7 @@
#define D_UNIT_VOLT "V"
#define D_UNIT_WATT "W"
#define D_UNIT_WATTHOUR "Wh"
#define D_UNIT_WATT_METER_QUADRAT "W/m²"
// Log message prefix
#define D_LOG_APPLICATION "APP: " // Application

View File

@ -163,7 +163,14 @@
#define D_USER "Utilisateur"
#define D_UTC_TIME "UTC"
#define D_UV_INDEX "Indice UV"
#define D_UV_INDEX_2 "Mid"
#define D_UV_INDEX_3 "High"
#define D_UV_INDEX_4 "Danger"
#define D_UV_INDEX_5 "BurnL1/2"
#define D_UV_INDEX_6 "BurnL3"
#define D_UV_INDEX_7 "OoR"
#define D_UV_LEVEL "Niveau UV"
#define D_UV_POWER "UV Power"
#define D_VERSION "Version"
#define D_VOLTAGE "Tension"
#define D_WARMLIGHT "Chaud"
@ -514,6 +521,7 @@
#define D_UNIT_VOLT "V"
#define D_UNIT_WATT "W"
#define D_UNIT_WATTHOUR "Wh"
#define D_UNIT_WATT_METER_QUADRAT "W/m²"
// Log message prefix
#define D_LOG_APPLICATION "APP: " // Application

View File

@ -163,7 +163,14 @@
#define D_USER "Felhasználó"
#define D_UTC_TIME "UTC"
#define D_UV_INDEX "UV Index"
#define D_UV_INDEX_2 "Mid"
#define D_UV_INDEX_3 "High"
#define D_UV_INDEX_4 "Danger"
#define D_UV_INDEX_5 "BurnL1/2"
#define D_UV_INDEX_6 "BurnL3"
#define D_UV_INDEX_7 "OoR"
#define D_UV_LEVEL "UV Szint"
#define D_UV_POWER "UV Power"
#define D_VERSION "Verzió"
#define D_VOLTAGE "Feszültség"
#define D_WARMLIGHT "Meleg"
@ -514,6 +521,7 @@
#define D_UNIT_VOLT "V"
#define D_UNIT_WATT "W"
#define D_UNIT_WATTHOUR "Wh"
#define D_UNIT_WATT_METER_QUADRAT "W/m²"
// Log message prefix
#define D_LOG_APPLICATION "APP: " // Application

View File

@ -163,7 +163,14 @@
#define D_USER "Utente"
#define D_UTC_TIME "UTC"
#define D_UV_INDEX "Indice UV"
#define D_UV_INDEX_2 "Mid"
#define D_UV_INDEX_3 "High"
#define D_UV_INDEX_4 "Danger"
#define D_UV_INDEX_5 "BurnL1/2"
#define D_UV_INDEX_6 "BurnL3"
#define D_UV_INDEX_7 "OoR"
#define D_UV_LEVEL "Livello UV"
#define D_UV_POWER "UV Power"
#define D_VERSION "Versione"
#define D_VOLTAGE "Tensione"
#define D_WARMLIGHT "Calda"
@ -514,6 +521,7 @@
#define D_UNIT_VOLT "V"
#define D_UNIT_WATT "W"
#define D_UNIT_WATTHOUR "Wh"
#define D_UNIT_WATT_METER_QUADRAT "W/m²"
// Log message prefix
#define D_LOG_APPLICATION "APP: " // Application

View File

@ -163,7 +163,14 @@
#define D_USER "Gebruiker"
#define D_UTC_TIME "UTC"
#define D_UV_INDEX "UV-index"
#define D_UV_INDEX_2 "Mid"
#define D_UV_INDEX_3 "High"
#define D_UV_INDEX_4 "Danger"
#define D_UV_INDEX_5 "BurnL1/2"
#define D_UV_INDEX_6 "BurnL3"
#define D_UV_INDEX_7 "OoR"
#define D_UV_LEVEL "UV niveau"
#define D_UV_POWER "UV Power"
#define D_VERSION "Versie"
#define D_VOLTAGE "Spanning"
#define D_WARMLIGHT "Warm"
@ -514,6 +521,7 @@
#define D_UNIT_VOLT "V"
#define D_UNIT_WATT "W"
#define D_UNIT_WATTHOUR "Wh"
#define D_UNIT_WATT_METER_QUADRAT "W/m²"
// Log message prefix
#define D_LOG_APPLICATION "APP: " // Application

View File

@ -163,7 +163,14 @@
#define D_USER "Użytkownik"
#define D_UTC_TIME "UTC"
#define D_UV_INDEX "UV Index"
#define D_UV_INDEX_2 "Mid"
#define D_UV_INDEX_3 "High"
#define D_UV_INDEX_4 "Danger"
#define D_UV_INDEX_5 "BurnL1/2"
#define D_UV_INDEX_6 "BurnL3"
#define D_UV_INDEX_7 "OoR"
#define D_UV_LEVEL "Poziom UV"
#define D_UV_POWER "UV Power"
#define D_VERSION "Wersja"
#define D_VOLTAGE "Napięcie"
#define D_WARMLIGHT "Nagrzanie"
@ -514,6 +521,7 @@
#define D_UNIT_VOLT "V"
#define D_UNIT_WATT "W"
#define D_UNIT_WATTHOUR "Wh"
#define D_UNIT_WATT_METER_QUADRAT "W/m²"
// Log message prefix
#define D_LOG_APPLICATION "APP: " // Application

View File

@ -163,7 +163,14 @@
#define D_USER "Usuário"
#define D_UTC_TIME "UTC"
#define D_UV_INDEX "Índice UV"
#define D_UV_INDEX_2 "Mid"
#define D_UV_INDEX_3 "High"
#define D_UV_INDEX_4 "Danger"
#define D_UV_INDEX_5 "BurnL1/2"
#define D_UV_INDEX_6 "BurnL3"
#define D_UV_INDEX_7 "OoR"
#define D_UV_LEVEL "Nível UV"
#define D_UV_POWER "UV Power"
#define D_VERSION "Versão"
#define D_VOLTAGE "Voltagem"
#define D_WARMLIGHT "Luz quente"
@ -514,6 +521,7 @@
#define D_UNIT_VOLT "V"
#define D_UNIT_WATT "W"
#define D_UNIT_WATTHOUR "W/h"
#define D_UNIT_WATT_METER_QUADRAT "W/m²"
// Log message prefix
#define D_LOG_APPLICATION "APP: " // Application

View File

@ -163,7 +163,14 @@
#define D_USER "Utilizador"
#define D_UTC_TIME "UTC"
#define D_UV_INDEX "Indíce UV"
#define D_UV_INDEX_2 "Mid"
#define D_UV_INDEX_3 "High"
#define D_UV_INDEX_4 "Danger"
#define D_UV_INDEX_5 "BurnL1/2"
#define D_UV_INDEX_6 "BurnL3"
#define D_UV_INDEX_7 "OoR"
#define D_UV_LEVEL "Nível UV"
#define D_UV_POWER "UV Power"
#define D_VERSION "Versão"
#define D_VOLTAGE "Voltagem"
#define D_WARMLIGHT "Luz Quente"
@ -514,6 +521,7 @@
#define D_UNIT_VOLT "V"
#define D_UNIT_WATT "W"
#define D_UNIT_WATTHOUR "Wh"
#define D_UNIT_WATT_METER_QUADRAT "W/m²"
// Log message prefix
#define D_LOG_APPLICATION "APP: " // Application

View File

@ -163,7 +163,14 @@
#define D_USER "Пользователь"
#define D_UTC_TIME "UTC"
#define D_UV_INDEX "UV Index"
#define D_UV_INDEX_2 "Mid"
#define D_UV_INDEX_3 "High"
#define D_UV_INDEX_4 "Danger"
#define D_UV_INDEX_5 "BurnL1/2"
#define D_UV_INDEX_6 "BurnL3"
#define D_UV_INDEX_7 "OoR"
#define D_UV_LEVEL "УФ уровень"
#define D_UV_POWER "UV Power"
#define D_VERSION "Версия"
#define D_VOLTAGE "Напряжение"
#define D_WARMLIGHT "Тепло"
@ -514,6 +521,7 @@
#define D_UNIT_VOLT "В"
#define D_UNIT_WATT "Вт"
#define D_UNIT_WATTHOUR "ВтЧ"
#define D_UNIT_WATT_METER_QUADRAT "W/m²"
// Log message prefix
#define D_LOG_APPLICATION "APP: " // Application

View File

@ -163,7 +163,14 @@
#define D_USER "Kullanıcı"
#define D_UTC_TIME "UTC"
#define D_UV_INDEX "UV Indeksi"
#define D_UV_INDEX_2 "Mid"
#define D_UV_INDEX_3 "High"
#define D_UV_INDEX_4 "Danger"
#define D_UV_INDEX_5 "BurnL1/2"
#define D_UV_INDEX_6 "BurnL3"
#define D_UV_INDEX_7 "OoR"
#define D_UV_LEVEL "UV Seviyesi"
#define D_UV_POWER "UV Power"
#define D_VERSION "Versiyon"
#define D_VOLTAGE "Voltaj"
#define D_WARMLIGHT "Sıcak"
@ -514,6 +521,7 @@
#define D_UNIT_VOLT "V"
#define D_UNIT_WATT "W"
#define D_UNIT_WATTHOUR "Wh"
#define D_UNIT_WATT_METER_QUADRAT "W/m²"
#define D_UNIT_HERTZ "Hz"
// Log message prefix

View File

@ -163,7 +163,14 @@
#define D_USER "Користувач"
#define D_UTC_TIME "UTC"
#define D_UV_INDEX "УФ індекс"
#define D_UV_INDEX_2 "Mid"
#define D_UV_INDEX_3 "High"
#define D_UV_INDEX_4 "Danger"
#define D_UV_INDEX_5 "BurnL1/2"
#define D_UV_INDEX_6 "BurnL3"
#define D_UV_INDEX_7 "OoR"
#define D_UV_LEVEL "УФ рівень"
#define D_UV_POWER "UV Power"
#define D_VERSION "Версія"
#define D_VOLTAGE "Напруга"
#define D_WARMLIGHT "Тепло"
@ -515,6 +522,7 @@
#define D_UNIT_VOLT "В"
#define D_UNIT_WATT "Вт"
#define D_UNIT_WATTHOUR "ВтГод"
#define D_UNIT_WATT_METER_QUADRAT "W/m²"
// Log message prefix
#define D_LOG_APPLICATION "APP: " // Application

View File

@ -163,7 +163,14 @@
#define D_USER "用户名"
#define D_UTC_TIME "UTC"
#define D_UV_INDEX "紫外线指数"
#define D_UV_INDEX_2 "Mid"
#define D_UV_INDEX_3 "High"
#define D_UV_INDEX_4 "Danger"
#define D_UV_INDEX_5 "BurnL1/2"
#define D_UV_INDEX_6 "BurnL3"
#define D_UV_INDEX_7 "OoR"
#define D_UV_LEVEL "紫外线水平"
#define D_UV_POWER "UV Power"
#define D_VERSION "版本"
#define D_VOLTAGE "电压"
#define D_WARMLIGHT "暖"
@ -514,6 +521,7 @@
#define D_UNIT_WATT "瓦"
#define D_UNIT_WATTHOUR "瓦时"
#define D_UNIT_HERTZ "赫兹"
#define D_UNIT_WATT_METER_QUADRAT "W/m²"
// Log message prefix
#define D_LOG_APPLICATION "APP: " // Application

View File

@ -163,7 +163,14 @@
#define D_USER "用戶名"
#define D_UTC_TIME "UTC"
#define D_UV_INDEX "UV Index"
#define D_UV_INDEX_2 "Mid"
#define D_UV_INDEX_3 "High"
#define D_UV_INDEX_4 "Danger"
#define D_UV_INDEX_5 "BurnL1/2"
#define D_UV_INDEX_6 "BurnL3"
#define D_UV_INDEX_7 "OoR"
#define D_UV_LEVEL "紫外線等級"
#define D_UV_POWER "UV Power"
#define D_VERSION "版本"
#define D_VOLTAGE "電壓"
#define D_WARMLIGHT "暖"
@ -514,6 +521,7 @@
#define D_UNIT_VOLT "伏"
#define D_UNIT_WATT "瓦"
#define D_UNIT_WATTHOUR "瓦時"
#define D_UNIT_WATT_METER_QUADRAT "W/m²"
// Log message prefix
#define D_LOG_APPLICATION "APP: " // Application

View File

@ -283,6 +283,8 @@
// #define USE_BME680 // Enable support for BME680 sensor using Bosch BME680 library (+4k code)
#define USE_BH1750 // Enable BH1750 sensor (I2C address 0x23 or 0x5C) (+0k5 code)
// #define USE_VEML6070 // Enable VEML6070 sensor (I2C addresses 0x38 and 0x39) (+0k5 code)
// #define USE_VEML6070_RSET 270000 // VEML6070, Rset in Ohm used on PCB board, default 270K = 270000ohm, range for this sensor: 220K ... 1Meg
// #define USE_VEML6070_SHOW_RAW // VEML6070, shows the raw value of UV-A
// #define USE_ADS1115 // Enable ADS1115 16 bit A/D converter (I2C address 0x48, 0x49, 0x4A or 0x4B) based on Adafruit ADS1x15 library (no library needed) (+0k7 code)
// #define USE_ADS1115_I2CDEV // Enable ADS1115 16 bit A/D converter (I2C address 0x48, 0x49, 0x4A or 0x4B) using library i2cdevlib-Core and i2cdevlib-ADS1115 (+2k code)
// #define USE_INA219 // Enable INA219 (I2C address 0x40, 0x41 0x44 or 0x45) Low voltage and current sensor (+1k code)

View File

@ -15,25 +15,136 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-----------------------------------------------------
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
--------------------------------------------------------------------------------------------
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
added - UV Power level now named as UV Power, used W/m2 because official standards
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};)
added - USE_VEML6070_RSET
- 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
added - lots of information in one of the last postings in: https://github.com/arendst/Sonoff-Tasmota/issues/3844
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
- add a #define to select how many characters are shown benhind the decimal point for the UV Index
---
1.0.0.0 20180912 started - further development by mike2nl - https://github.com/mike2nl/Sonoff-Tasmota
forked - from arendst/tasmota - https://github.com/arendst/Sonoff-Tasmota
base - code base from arendst too
*/
#ifdef USE_I2C
#ifdef USE_VEML6070
/*********************************************************************************************\
* VEML6070 - Ultra Violet Light Intensity
* VEML6070 - Ultra Violet Light Intensity (UV-A, 100% output by 255nm)
*
* I2C Address: 0x38 and 0x39
\*********************************************************************************************/
#define VEML6070_ADDR_H 0x39
#define VEML6070_ADDR_L 0x38
#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 // 500msec integration time
#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
#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
// (resistor, differences, power coefficients and official UV index calculations (LAT & LONG will be added later)
/********************************************************************************************/
// globals
uint8_t veml6070_address;
uint8_t veml6070_type = 0;
uint16_t Veml6070ReadUv()
/********************************************************************************************/
void Veml6070Detect(void)
{
if (veml6070_type) {
return;
}
uint8_t itime = VEML6070_INTEGRATION_TIME;
veml6070_address = VEML6070_ADDR_L;
Wire.beginTransmission(veml6070_address);
Wire.write((itime << 2) | 0x02);
uint8_t status = Wire.endTransmission();
if (!status) {
veml6070_type = 1;
snprintf_P(log_data, sizeof(log_data), S_LOG_I2C_FOUND_AT, "VEML6070", veml6070_address);
AddLog(LOG_LEVEL_DEBUG);
}
}
/********************************************************************************************/
void Veml6070ModeCmd(boolean mode_cmd)
{
uint8_t itime = VEML6070_INTEGRATION_TIME;
uint8_t opmode = 0;
if (mode_cmd) {
opmode = VEML6070_ENABLE;
} else {
opmode = VEML6070_DISABLE;
}
veml6070_address = VEML6070_ADDR_L;
Wire.beginTransmission(veml6070_address);
Wire.write((opmode << 0) | 0x02 | (itime << 2));
uint8_t status = Wire.endTransmission();
if (!status) {
snprintf_P(log_data, sizeof(log_data), S_LOG_I2C_FOUND_AT, "VEML6070 opmode", veml6070_address);
AddLog(LOG_LEVEL_DEBUG);
}
}
/********************************************************************************************/
uint16_t Veml6070ReadUv(void)
{
if (Wire.requestFrom(VEML6070_ADDR_H, 1) != 1) {
return -1;
@ -50,45 +161,122 @@ uint16_t Veml6070ReadUv()
/********************************************************************************************/
void Veml6070Detect()
double Veml6070UvRiskLevel(uint16_t uv_level)
{
if (veml6070_type) {
return;
}
double risk = 0;
double uv_risk_map[VEML6070_UV_MAX_INDEX] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
// fill the uv-risk compare table based on the coefficient calculation
for (uint8_t i = 0; i < VEML6070_UV_MAX_INDEX; i++) {
#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);
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_DEBUG "VEML6070 resistor error %d"), USE_VEML6070_RSET);
AddLog(LOG_LEVEL_DEBUG);
}
#else
uv_risk_map[i] = ( (VEML6070_RSET_DEFAULT / VEML6070_TABLE_COEFFCIENT) / VEML6070_UV_MAX_DEFAULT) * (i+1);
#endif
}
uint8_t itime = VEML6070_INTEGRATION_TIME;
veml6070_address = VEML6070_ADDR_L;
Wire.beginTransmission(veml6070_address);
Wire.write((itime << 2) | 0x02);
uint8_t status = Wire.endTransmission();
if (!status) {
veml6070_type = 1;
snprintf_P(log_data, sizeof(log_data), S_LOG_I2C_FOUND_AT, "VEML6070", veml6070_address);
// get the uv-risk level
if (uv_level < uv_risk_map[VEML6070_UV_MAX_INDEX-1]) {
return ( uv_level / uv_risk_map[0] );
} else {
return ( risk = 99 ); // out of range = much to high - it must be outerspace or sensor damaged
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_DEBUG "VEML6070 out of range %d"), risk);
AddLog(LOG_LEVEL_DEBUG);
}
}
/********************************************************************************************/
double Veml6070UvPower(double uvrisk)
{
// based on calculations for effective irradiation from Karel Vanicek
return ( VEML6070_POWER_COEFFCIENT * uvrisk );
}
/********************************************************************************************/
#ifdef USE_WEBSERVER
const char HTTP_SNS_ULTRAVIOLET[] PROGMEM =
"%s{s}VEML6070 " D_UV_LEVEL "{m}%d{e}"; // {s} = <tr><th>, {m} = </th><td>, {e} = </td></tr>
// {s} = <tr><th>, {m} = </th><td>, {e} = </td></tr>
#ifdef USE_VEML6070_SHOW_RAW
const char HTTP_SNS_UV_LEVEL[] PROGMEM = "%s{s}VEML6070 " D_UV_LEVEL "{m}%d " D_UNIT_INCREMENTS "{e}";
#endif // USE_VEML6070_SHOW_RAW
// different uv index level texts
const char HTTP_SNS_UV_INDEX1[] PROGMEM = "%s{s}VEML6070 " D_UV_INDEX "{m}%s " D_UV_INDEX_1 "{e}";
const char HTTP_SNS_UV_INDEX2[] PROGMEM = "%s{s}VEML6070 " D_UV_INDEX "{m}%s " D_UV_INDEX_2 "{e}";
const char HTTP_SNS_UV_INDEX3[] PROGMEM = "%s{s}VEML6070 " D_UV_INDEX "{m}%s " D_UV_INDEX_3 "{e}";
const char HTTP_SNS_UV_INDEX4[] PROGMEM = "%s{s}VEML6070 " D_UV_INDEX "{m}%s " D_UV_INDEX_4 "{e}";
const char HTTP_SNS_UV_INDEX5[] PROGMEM = "%s{s}VEML6070 " D_UV_INDEX "{m}%s " D_UV_INDEX_5 "{e}";
const char HTTP_SNS_UV_INDEX6[] PROGMEM = "%s{s}VEML6070 " D_UV_INDEX "{m}%s " D_UV_INDEX_6 "{e}";
const char HTTP_SNS_UV_INDEX7[] PROGMEM = "%s{s}VEML6070 " D_UV_INDEX "{m}%s " D_UV_INDEX_7 "{e}";
const char HTTP_SNS_UV_POWER[] PROGMEM = "%s{s}VEML6070 " D_UV_POWER "{m}%s " D_UNIT_WATT_METER_QUADRAT "{e}";
#endif // USE_WEBSERVER
/********************************************************************************************/
void Veml6070Show(boolean json)
{
if (veml6070_type) {
// wakeup the sensor
Veml6070ModeCmd(1);
// get values from functions
uint16_t uvlevel = Veml6070ReadUv();
double uvrisk = Veml6070UvRiskLevel(uvlevel);
double uvpower = Veml6070UvPower(uvrisk);
char str_uvrisk[10];
char str_uvpower[5];
// convert double values to string
dtostrfd(uvrisk, 2, str_uvrisk);
dtostrfd(uvpower, 3, str_uvpower);
if (json) {
#ifdef USE_VEML6070_SHOW_RAW
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"VEML6070\":{\"" D_JSON_UV_LEVEL "\":%d}"), mqtt_data, uvlevel);
#endif // USE_VEML6070_SHOW_RAW
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"VEML6070\":{\"" D_JSON_UV_INDEX "\":%s}"), mqtt_data, str_uvrisk);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"VEML6070\":{\"" D_JSON_UV_POWER "\":%s}"), mqtt_data, str_uvpower);
#ifdef USE_DOMOTICZ
if (0 == tele_period) DomoticzSensor(DZ_ILLUMINANCE, uvlevel);
if (0 == tele_period) { DomoticzSensor(DZ_ILLUMINANCE, uvlevel) };
#endif // USE_DOMOTICZ
#ifdef USE_WEBSERVER
} else {
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_ULTRAVIOLET, mqtt_data, uvlevel);
#ifdef USE_VEML6070_SHOW_RAW
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_UV_LEVEL, mqtt_data, uvlevel);
#endif // USE_VEML6070_SHOW_RAW
if ( (uvrisk >= 0) && (uvrisk <= 2.9) ) {
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_UV_INDEX1, mqtt_data, str_uvrisk);
}
else if ( (uvrisk >= 3.0) && (uvrisk <= 5.9) ) {
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_UV_INDEX2, mqtt_data, str_uvrisk);
}
else if ( (uvrisk >= 6.0) && (uvrisk <= 7.9) ) {
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_UV_INDEX3, mqtt_data, str_uvrisk);
}
else if ( (uvrisk >= 8.0) && (uvrisk <= 10.9) ) {
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_UV_INDEX4, mqtt_data, str_uvrisk);
}
else if ( (uvrisk >= 11.0) && (uvrisk <= 12.9) ) {
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_UV_INDEX5, mqtt_data, str_uvrisk);
}
else if ( (uvrisk >= 13.0) && (uvrisk <= 15.9) ) {
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_UV_INDEX6, mqtt_data, str_uvrisk);
} else {
// else for Unknown or Out Of Range error = 99
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_UV_INDEX7, mqtt_data, str_uvrisk);
}
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_UV_POWER, mqtt_data, str_uvpower);
#endif // USE_WEBSERVER
}
// suspend the sensor
Veml6070ModeCmd(0);
// delay(2000); // used while messaurment of current drain
}
}
@ -105,7 +293,7 @@ boolean Xsns11(byte function)
if (i2c_flg) {
switch (function) {
case FUNC_PREP_BEFORE_TELEPERIOD:
Veml6070Detect();
Veml6070Detect(); // detect and init the sensor
break;
case FUNC_JSON_APPEND:
Veml6070Show(1);