mirror of https://github.com/arendst/Tasmota.git
parent
4bc3ce70dd
commit
29ed5c1a27
|
@ -175,13 +175,14 @@ void ShtEverySecond()
|
||||||
if (sht_type && !(uptime %3)) { // Update every 3 seconds
|
if (sht_type && !(uptime %3)) { // Update every 3 seconds
|
||||||
if (!ShtRead()) {
|
if (!ShtRead()) {
|
||||||
AddLogMissed(sht_types, sht_valid);
|
AddLogMissed(sht_types, sht_valid);
|
||||||
|
// if (!sht_valid) { sht_type = 0; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShtShow(boolean json)
|
void ShtShow(boolean json)
|
||||||
{
|
{
|
||||||
if (sht_type && sht_valid) {
|
if (sht_valid) {
|
||||||
char temperature[10];
|
char temperature[10];
|
||||||
char humidity[10];
|
char humidity[10];
|
||||||
|
|
||||||
|
|
|
@ -234,6 +234,7 @@ void HtuEverySecond()
|
||||||
if (htu_type) {
|
if (htu_type) {
|
||||||
if (!HtuRead()) {
|
if (!HtuRead()) {
|
||||||
AddLogMissed(htu_types, htu_valid);
|
AddLogMissed(htu_types, htu_valid);
|
||||||
|
// if (!htu_valid) { htu_type = 0; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -241,7 +242,7 @@ void HtuEverySecond()
|
||||||
|
|
||||||
void HtuShow(boolean json)
|
void HtuShow(boolean json)
|
||||||
{
|
{
|
||||||
if (htu_type && htu_valid) {
|
if (htu_valid) {
|
||||||
char temperature[10];
|
char temperature[10];
|
||||||
char humidity[10];
|
char humidity[10];
|
||||||
|
|
||||||
|
|
|
@ -33,14 +33,20 @@
|
||||||
uint8_t bh1750_address;
|
uint8_t bh1750_address;
|
||||||
uint8_t bh1750_addresses[] = { BH1750_ADDR1, BH1750_ADDR2 };
|
uint8_t bh1750_addresses[] = { BH1750_ADDR1, BH1750_ADDR2 };
|
||||||
uint8_t bh1750_type = 0;
|
uint8_t bh1750_type = 0;
|
||||||
|
uint8_t bh1750_valid = 0;
|
||||||
|
uint16_t bh1750_illuminance = 0;
|
||||||
|
char bh1750_types[] = "BH1750";
|
||||||
|
|
||||||
uint16_t Bh1750ReadLux()
|
bool Bh1750Read()
|
||||||
{
|
{
|
||||||
Wire.requestFrom(bh1750_address, (uint8_t)2);
|
if (bh1750_valid) { bh1750_valid--; }
|
||||||
|
|
||||||
|
if (2 != Wire.requestFrom(bh1750_address, (uint8_t)2)) { return false; }
|
||||||
byte msb = Wire.read();
|
byte msb = Wire.read();
|
||||||
byte lsb = Wire.read();
|
byte lsb = Wire.read();
|
||||||
uint16_t value = ((msb << 8) | lsb) / 1.2;
|
bh1750_illuminance = ((msb << 8) | lsb) / 1.2;
|
||||||
return value;
|
bh1750_valid = SENSOR_MAX_MISS;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************************************************************************************/
|
/********************************************************************************************/
|
||||||
|
@ -57,31 +63,46 @@ void Bh1750Detect()
|
||||||
Wire.write(BH1750_CONTINUOUS_HIGH_RES_MODE);
|
Wire.write(BH1750_CONTINUOUS_HIGH_RES_MODE);
|
||||||
if (!Wire.endTransmission()) {
|
if (!Wire.endTransmission()) {
|
||||||
bh1750_type = 1;
|
bh1750_type = 1;
|
||||||
snprintf_P(log_data, sizeof(log_data), S_LOG_I2C_FOUND_AT, "BH1750", bh1750_address);
|
snprintf_P(log_data, sizeof(log_data), S_LOG_I2C_FOUND_AT, bh1750_types, bh1750_address);
|
||||||
AddLog(LOG_LEVEL_DEBUG);
|
AddLog(LOG_LEVEL_DEBUG);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Bh1750EverySecond()
|
||||||
|
{
|
||||||
|
if (90 == (uptime %100)) {
|
||||||
|
Bh1750Detect();
|
||||||
|
}
|
||||||
|
else if (uptime &1) {
|
||||||
|
if (bh1750_type) {
|
||||||
|
if (!Bh1750Read()) {
|
||||||
|
AddLogMissed(bh1750_types, bh1750_valid);
|
||||||
|
// if (!bh1750_valid) { bh1750_type = 0; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef USE_WEBSERVER
|
#ifdef USE_WEBSERVER
|
||||||
const char HTTP_SNS_ILLUMINANCE[] PROGMEM =
|
const char HTTP_SNS_ILLUMINANCE[] PROGMEM =
|
||||||
"%s{s}BH1750 " D_ILLUMINANCE "{m}%d " D_UNIT_LUX "{e}"; // {s} = <tr><th>, {m} = </th><td>, {e} = </td></tr>
|
"%s{s}%s " D_ILLUMINANCE "{m}%d " D_UNIT_LUX "{e}"; // {s} = <tr><th>, {m} = </th><td>, {e} = </td></tr>
|
||||||
#endif // USE_WEBSERVER
|
#endif // USE_WEBSERVER
|
||||||
|
|
||||||
void Bh1750Show(boolean json)
|
void Bh1750Show(boolean json)
|
||||||
{
|
{
|
||||||
if (bh1750_type) {
|
if (bh1750_valid) {
|
||||||
uint16_t illuminance = Bh1750ReadLux();
|
|
||||||
|
|
||||||
if (json) {
|
if (json) {
|
||||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"BH1750\":{\"" D_JSON_ILLUMINANCE "\":%d}"), mqtt_data, illuminance);
|
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"%s\":{\"" D_JSON_ILLUMINANCE "\":%d}"), mqtt_data, bh1750_types, bh1750_illuminance);
|
||||||
#ifdef USE_DOMOTICZ
|
#ifdef USE_DOMOTICZ
|
||||||
if (0 == tele_period) DomoticzSensor(DZ_ILLUMINANCE, illuminance);
|
if (0 == tele_period) {
|
||||||
|
DomoticzSensor(DZ_ILLUMINANCE, bh1750_illuminance);
|
||||||
|
}
|
||||||
#endif // USE_DOMOTICZ
|
#endif // USE_DOMOTICZ
|
||||||
#ifdef USE_WEBSERVER
|
#ifdef USE_WEBSERVER
|
||||||
} else {
|
} else {
|
||||||
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_ILLUMINANCE, mqtt_data, illuminance);
|
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_ILLUMINANCE, mqtt_data, bh1750_types, bh1750_illuminance);
|
||||||
#endif // USE_WEBSERVER
|
#endif // USE_WEBSERVER
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -99,9 +120,12 @@ boolean Xsns10(byte function)
|
||||||
|
|
||||||
if (i2c_flg) {
|
if (i2c_flg) {
|
||||||
switch (function) {
|
switch (function) {
|
||||||
case FUNC_PREP_BEFORE_TELEPERIOD:
|
case FUNC_INIT:
|
||||||
Bh1750Detect();
|
Bh1750Detect();
|
||||||
break;
|
break;
|
||||||
|
case FUNC_EVERY_SECOND:
|
||||||
|
Bh1750EverySecond();
|
||||||
|
break;
|
||||||
case FUNC_JSON_APPEND:
|
case FUNC_JSON_APPEND:
|
||||||
Bh1750Show(1);
|
Bh1750Show(1);
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue