diff --git a/docs/prerequisites/board.md b/docs/prerequisites/board.md index c2a0c05..0d37a1c 100644 --- a/docs/prerequisites/board.md +++ b/docs/prerequisites/board.md @@ -4,7 +4,7 @@ OpenMQTTGateway is not closed to one board or type of board, by using the power You can take a look to the [OpenMQTTGateway compatible website](https://compatible.openmqttgateway.com) to have a view of the [supported boards](https://compatible.openmqttgateway.com/index.php/boards/). -Moreover the gateways capacities can be extended with sensors; DHT, HC SR501, ADC, I2C bus, INA226, TSL2561, BME280/BMP280, HTU21D, AHTx0, DS1820 +Moreover the gateways capacities can be extended with sensors; DHT, HC SR501, ADC, I2C bus, INA226, TEMT6000, TSL2561, BME280/BMP280, HTU21D, AHTx0, DS1820 or actuators; LED, relays, PWM. ::: tip Running on a computer diff --git a/docs/setitup/sensors.md b/docs/setitup/sensors.md index 2780b39..d58ad67 100644 --- a/docs/setitup/sensors.md +++ b/docs/setitup/sensors.md @@ -12,24 +12,26 @@ |GPIO Input|Inputs|-| |GPIO KeyCode|Keycode|[parts list](https://compatible.openmqttgateway.com/index.php/parts)| |INA226|Current, Voltage|[parts list](https://compatible.openmqttgateway.com/index.php/parts)| +|TEMT6000|Luminosity|[parts list](https://compatible.openmqttgateway.com/index.php/parts)| |TSL2561|Luminosity|[parts list](https://compatible.openmqttgateway.com/index.php/parts)| ## Pinout |Module|Arduino Pin| ESP8266 Pin|ESP32 Pin| |-|-|-|-| -|DHT11/22|D8|D1|16| -|HC-SR501/HC-SR505|7|D5|5| |Analog reading|A0|A0|A0| |BH1750 SDA|A4|D2|21| |BH1750 SCL|A5|D1|22| |BME280/BMP280 SDA|A4|D2|21| |BME280/BMP280 SCL|A5|D1|22| +|DHT11/22|D8|D1|16| +|HC-SR501/HC-SR505|7|D5|5| |HTU21 SDA|A4|D2|21| |HTU21 SCL|A5|D1|22| |INA226 SDA|A4|D2|21| |INA226 SCL|A5|D1|22| +|TEMT6000 |A0|A0|A0| |TSL2561 SDA|A4|D2|21| |TSL2561 SCL|A5|D1|22| -Vcc pin of the board and the Module to a 5V supply source +Vcc pin of the board and the Module to a 3.3V or 5V supply source depending on sensor voltage requirement. Ground pins of the board and the Module to the ground of the supply source. diff --git a/environments.ini b/environments.ini index b3f0a32..87a77cc 100644 --- a/environments.ini +++ b/environments.ini @@ -98,6 +98,7 @@ build_flags = '-DBME280Correction=-3.4' '-DZsensorHTU21="HTU21"' '-DZsensorAHTx0="AHTx0"' + '-DZsensorTEMT6000="TEMT6000"' '-DZsensorTSL2561="TSL2561"' '-DZsensorDHT="DHT"' '-DZsensorDS1820="DS1820"' @@ -1104,6 +1105,7 @@ build_flags = '-DZsensorBME280="BME280"' ;'-DZsensorHTU21="HTU21"' '-DZsensorAHTx0="AHTx0"' + '-DZsensorTEMT6000="TEMT6000"' '-DZsensorTSL2561="TSL2561"' '-DZsensorDHT="DHT"' '-DZsensorDS1820="DS1820"' @@ -1675,3 +1677,4 @@ build_flags = ; '-DsimplePublishing=true' custom_description = BLE Gateway using ethernet, requires PIO configuration custom_hardware = ThingPulse gateway single ESP32 + \ No newline at end of file diff --git a/main/User_config.h b/main/User_config.h index a696e9d..1e30161 100644 --- a/main/User_config.h +++ b/main/User_config.h @@ -326,6 +326,7 @@ int lowpowermode = DEFAULT_LOW_POWER_MODE; //#define ZsensorHCSR501 "HCSR501" //ESP8266, Arduino, ESP32, Sonoff RF Bridge //#define ZsensorADC "ADC" //ESP8266, Arduino, ESP32 //#define ZsensorBH1750 "BH1750" //ESP8266, Arduino, ESP32 +//#define ZsensorTEMT6000 "TEMT6000" //ESP8266 //#define ZsensorTSL2561 "TSL2561" //ESP8266, Arduino, ESP32 //#define ZsensorBME280 "BME280" //ESP8266, Arduino, ESP32 //#define ZsensorHTU21 "HTU21" //ESP8266, Arduino, ESP32 diff --git a/main/ZmqttDiscovery.ino b/main/ZmqttDiscovery.ino index dbb1712..ac5ae7b 100644 --- a/main/ZmqttDiscovery.ino +++ b/main/ZmqttDiscovery.ino @@ -752,6 +752,29 @@ void pubMqttDiscovery() { } # endif +# ifdef ZsensorTEMT6000 +# define TEMT6000parametersCount 3 + Log.trace(F("TEMT6000Discovery" CR)); + char* TEMT6000sensor[TEMT6000parametersCount][8] = { + {"sensor", "lux", "TEMT6000", "illuminance", jsonLux, "", "", "lx"}, + {"sensor", "ftcd", "TEMT6000", "", jsonFtcd, "", "", ""}, + {"sensor", "wattsm2", "TEMT6000", "", jsonWm2, "", "", "wm²"} + //component type,name,availability topic,device class,value template,payload on, payload off, unit of measurement + }; + + for (int i = 0; i < TEMT6000parametersCount; i++) { + //trc(TEMT6000sensor[i][1]); + createDiscovery(TEMT6000sensor[i][0], + subjectTEMT6000toMQTT, TEMT6000sensor[i][1], (char*)getUniqueId(TEMT6000sensor[i][1], TEMT6000sensor[i][2]).c_str(), + will_Topic, TEMT6000sensor[i][3], TEMT6000sensor[i][4], + TEMT6000sensor[i][5], TEMT6000sensor[i][6], TEMT6000sensor[i][7], + 0, Gateway_AnnouncementMsg, will_Message, true, "", + "", "", "", "", false, // device name, device manufacturer, device model, device ID, retain + stateClassNone //State Class + ); + } +# endif + # ifdef ZsensorTSL2561 # define TSL2561parametersCount 3 Log.trace(F("TSL2561Discovery" CR)); diff --git a/main/ZsensorTEMT6000.ino b/main/ZsensorTEMT6000.ino new file mode 100644 index 0000000..bca95d3 --- /dev/null +++ b/main/ZsensorTEMT6000.ino @@ -0,0 +1,77 @@ +/* + OpenMQTTGateway Addon - ESP8266 or Arduino program for home automation + + Act as a wifi or ethernet gateway between your 433mhz/infrared IR signal and a MQTT broker + Send and receiving command by MQTT + + This is the Light Meter Addon based on modules with a TEMT6000: + - Measures ambient Light Intensity in Lux (lx), Foot Candela (ftcd) and Watt/m^2 (wattsm2) + - Required Hardware Module: TEMT6000 + - Dependencies: none + + Connection Scheme: + -------------------- + + TEMT6000------> ESP8266 + ============================================== + Vcc ---------> 3.3V + GND ---------> GND + SIG ---------> A0 + + Copyright: (c) Andre Greyling - this is a modified copy of Chris Broekema + + This file is part of OpenMQTTGateway. + + OpenMQTTGateway 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. + + OpenMQTTGateway 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 . +*/ +#include "User_config.h" + +#ifdef ZsensorTEMT6000 + +# include "Wire.h" +# include "math.h" + +void setupZsensorTEMT6000() { + Log.notice(F("Setup TEMT6000 on pin: %i" CR), TEMT6000LIGHTSENSORPIN); + pinMode(TEMT6000LIGHTSENSORPIN, INPUT); +} + +void MeasureLightIntensityTEMT6000() { + if (millis() > (timetemt6000 + TimeBetweenReadingtemt6000)) { + static uint32_t persisted_lux; + timetemt6000 = millis(); + + Log.trace(F("Creating TEMT6000 buffer" CR)); + StaticJsonDocument jsonBuffer; + JsonObject TEMT6000data = jsonBuffer.to(); + + float volts = analogRead(TEMT6000LIGHTSENSORPIN) * 5.0 / 1024.0; + float amps = volts / 10000.0; // across 10,000 Ohms + float microamps = amps * 1000000; + float lux = microamps * 2.0; + + if (persisted_lux != lux || temt6000_always) { + persisted_lux = lux; + + TEMT6000data["lux"] = (float)lux; + TEMT6000data["ftcd"] = (float)(lux) / 10.764; + TEMT6000data["wattsm2"] = (float)(lux) / 683.0; + + pub(subjectTEMT6000toMQTT, TEMT6000data); + } else { + Log.trace(F("Same lux value, do not send" CR)); + } + } +} +#endif diff --git a/main/config_TEMT6000.h b/main/config_TEMT6000.h new file mode 100644 index 0000000..c60f485 --- /dev/null +++ b/main/config_TEMT6000.h @@ -0,0 +1,55 @@ +/* + OpenMQTTGateway Addon - ESP8266 or Arduino program for home automation + + Act as a wifi or ethernet gateway between your 433mhz/infrared IR signal and a MQTT broker + Send and receiving command by MQTT + + This is the Light Meter Addon based on modules with a TEMT6000: + - Measures ambient Light Intensity in Lux (lx), Foot Candela (ftcd) and Watt/m^2 (wattsm2) + - Required Hardware Module: TEMT6000 + - Dependencies: none + + Connection Scheme: + -------------------- + + TEMT6000 ----> ESP8266 + ============================================== + Vcc ---------> 3.3V + GND ---------> GND + SIG ---------> A0 + + Copyright: (c) Andre Greyling - this is a modified copy of Chris Broekema + + This file is part of OpenMQTTGateway. + + OpenMQTTGateway 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. + + OpenMQTTGateway 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 . +*/ +#ifndef config_TEMT6000_h +#define config_TEMT6000_h + +extern void setupTEMT6000(); +extern void TEMT6000toMQTT(); + +#define temt6000_always true // if false only send current value if it has changed +#define TEMT6000LIGHTSENSORPIN A0 //Ambient light sensor reading = ADC0 +#define TimeBetweenReadingtemt6000 10000 //10000 ms + +/*----------------------------USER PARAMETERS-----------------------------*/ +/*-------------DEFINE YOUR MQTT PARAMETERS BELOW----------------*/ +#define subjectTEMT6000toMQTT "/LIGHTtoMQTT" + +//Time used to wait for an interval before resending measured values +unsigned long timetemt6000 = 0; + +#endif \ No newline at end of file diff --git a/main/main.ino b/main/main.ino index 333d5ca..70eefb7 100644 --- a/main/main.ino +++ b/main/main.ino @@ -109,6 +109,9 @@ struct GfSun2000Data {}; #ifdef ZsensorBH1750 # include "config_BH1750.h" #endif +#ifdef ZsensorTEMT6000 +# include "config_TEMT6000.h" +#endif #ifdef ZsensorTSL2561 # include "config_TSL2561.h" #endif @@ -872,6 +875,10 @@ void setup() { setupZsensorBH1750(); modules.add(ZsensorBH1750); #endif +#ifdef ZsensorTEMT6000 + setupZsensorTEMT6000(); + modules.add(ZsensorTEMT6000); +#endif #ifdef ZsensorTSL2561 setupZsensorTSL2561(); modules.add(ZsensorTSL2561); @@ -1638,6 +1645,9 @@ void loop() { #ifdef ZsensorBH1750 MeasureLightIntensity(); //Addon to measure Light Intensity with a BH1750 #endif +#ifdef ZsensorTEMT6000 + MeasureLightIntensityTEMT6000(); +#endif #ifdef ZsensorTSL2561 MeasureLightIntensityTSL2561(); #endif