Skip to content

Commit

Permalink
working
Browse files Browse the repository at this point in the history
  • Loading branch information
vtHydroponics committed Oct 28, 2024
1 parent 303e1fa commit 7850d6d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 30 deletions.
2 changes: 1 addition & 1 deletion lib/lib_i2c/Adafruit_TSL2591_Library/Adafruit_TSL2591.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**************************************************************************/
/*!
@file Adafruit_TSL2591.h
@file Adafruit_TSL2591.h
@author KT0WN (adafruit.com)
This is a library for the Adafruit TSL2591 breakout board
Expand Down
4 changes: 2 additions & 2 deletions lib/lib_i2c/BlueRobotics_MS5837_Library/MS5837.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,11 @@ float MS5837::temperature() {
// In order to calculate the correct depth, the actual atmospheric pressure should be measured once in air, and
// that value should subtracted for subsequent depth calculations.
float MS5837::depth() {
return (pressure(MS5837::Pa)-101300)/(fluidDensity*9.80665);
return (pressure(MS5837::Pa)-101300)/(fluidDensity*9.80665f);
}

float MS5837::altitude() {
return (1-pow((pressure()/1013.25),.190284))*145366.45*.3048;
return (1-pow((pressure()/1013.25f),.190284f))*145366.45f*.3048f;
}


Expand Down
57 changes: 35 additions & 22 deletions tasmota/tasmota_xsns_sensor/xsns_128_ms5837.ino
Original file line number Diff line number Diff line change
Expand Up @@ -56,43 +56,56 @@ void MS5837init(void) {
}

#ifdef USE_WEBSERVER
const char HTTP_SNS_MS5837[] PROGMEM =
"{s}MS5837 Temperature {m}%s " D_UNIT_DEGREE "%c{e}{s}MS5837 Pressure {m}%s %s{e}{s}Inches Water {m}%s in{e}"; // {s} = <tr><th>, {m} = </th><td>, {e} = </td></tr>
const char HTTP_SNS_MS5837_DEFAULT[] PROGMEM =
"{s}MS5837 Temperature {m}%s " D_UNIT_DEGREE "%c{e}{s}MS5837 Pressure {m}%s %s{e}"; // {s} = <tr><th>, {m} = </th><td>, {e} = </td></tr>
const char HTTP_SNS_MS5837_INCHES_WATER[] PROGMEM =
"{s}Inches Water {m}%s in{e}"; // {s} = <tr><th>, {m} = </th><td>, {e} = </td></tr>
char HTTP_SNS_MS5837_DUAL[118];
#endif // USE_WEBSERVER

void MS5837Show(bool json) {
float ms5837Temp;
float ms5837Pres;
float pressure_delta;
float inches_water;

sensor_ms5837.read();
ms5837Temp = ConvertTemp(sensor_ms5837.temperature());
ms5837Pres = ConvertPressure(sensor_ms5837.pressure());
if (I2cEnabled(XI2C_88)) { //pick up here
pressure_delta = sensor_ms5837.pressure() - bmp_sensors[0].bmp_pressure + pressureOffset;
inches_water = pressure_delta*0.401463078662f;
AddLog(LOG_LEVEL_DEBUG, PSTR("Pressure Delta: %f | Inches Water: %f"), pressure_delta, inches_water);
}
char temperature_str[8];
ext_snprintf_P(temperature_str, sizeof(temperature_str), PSTR("%1_f"), &ms5837Temp);
char pressure_str[8];
ext_snprintf_P(pressure_str, sizeof(pressure_str), PSTR("%1_f"), &ms5837Pres);
char inchesWater_str[8];
ext_snprintf_P(inchesWater_str, sizeof(inchesWater_str), PSTR("%1_f"), &inches_water);
if (json) {
// consolidate to one line
ResponseAppend_P(PSTR(",\"MS5837\":{\"Temperature\":%s,"), temperature_str);
ResponseAppend_P(PSTR("\"Pressure\":%s,"), pressure_str);
ResponseAppend_P(PSTR("\"Inches Water\":%s}"), inchesWater_str);

if (I2cEnabled(XI2C_88)) {
sensor_ms5837.read();
ms5837Temp = ConvertTemp(sensor_ms5837.temperature());
ms5837Pres = ConvertPressure(sensor_ms5837.pressure());
ext_snprintf_P(temperature_str, sizeof(temperature_str), PSTR("%1_f"), &ms5837Temp);
ext_snprintf_P(pressure_str, sizeof(pressure_str), PSTR("%1_f"), &ms5837Pres);
if (json) {
ResponseAppend_P(PSTR(",\"MS5837\":{\"Temperature\":%s,\"Pressure\":%s"), temperature_str, pressure_str);
}
if (I2cEnabled(XI2C_10)) {
pressure_delta = sensor_ms5837.pressure() - bmp_sensors[0].bmp_pressure + pressureOffset;
inches_water = pressure_delta*0.401463078662f;
ext_snprintf_P(inchesWater_str, sizeof(inchesWater_str), PSTR("%1_f"), &inches_water);
if (json) {
ResponseAppend_P(PSTR(",\"Inches Water\":%s"),inchesWater_str);
}
}
if (json) {
ResponseAppend_P(PSTR("}"));

#ifdef USE_WEBSERVER
} else {
WSContentSend_PD(HTTP_SNS_MS5837, temperature_str, TempUnit(), pressure_str, PressureUnit().c_str(), inchesWater_str);
if (I2cEnabled(XI2C_10)) {
strncat(HTTP_SNS_MS5837_DUAL,HTTP_SNS_MS5837_DEFAULT,sizeof(HTTP_SNS_MS5837_DUAL));
strncat(HTTP_SNS_MS5837_DUAL,HTTP_SNS_MS5837_INCHES_WATER,sizeof(HTTP_SNS_MS5837_DUAL));
WSContentSend_PD(HTTP_SNS_MS5837_DUAL, temperature_str, TempUnit(), pressure_str, PressureUnit().c_str(), inchesWater_str);
}
else {
WSContentSend_PD(HTTP_SNS_MS5837_DEFAULT, temperature_str, TempUnit(), pressure_str, PressureUnit().c_str());
}
#endif // USE_WEBSERVER
}
AddLog(LOG_LEVEL_DEBUG, PSTR("BMP Pressure: %f"), bmp_sensors[0].bmp_pressure);
}
}

/*********************************************************************************************\
* Interface
\*********************************************************************************************/
Expand Down
6 changes: 3 additions & 3 deletions tasmota/tasmota_xsns_sensor/xsns_57_tsl2591.ino
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ uint8_t tsl2591_type = 0;
uint8_t tsl2591_valid = 0;
float tsl2591_lux = 0;

tsl2591Gain_t gain_enum_array[4] = {TSL2591_GAIN_LOW,TSL2591_GAIN_MED,TSL2591_GAIN_HIGH,TSL2591_GAIN_MAX};
tsl2591IntegrationTime_t int_enum_array[6] = {TSL2591_INTEGRATIONTIME_100MS,TSL2591_INTEGRATIONTIME_200MS,TSL2591_INTEGRATIONTIME_300MS,TSL2591_INTEGRATIONTIME_400MS,TSL2591_INTEGRATIONTIME_500MS,TSL2591_INTEGRATIONTIME_600MS};
tsl2591Gain_t const gain_enum_array[4] PROGMEM = {TSL2591_GAIN_LOW,TSL2591_GAIN_MED,TSL2591_GAIN_HIGH,TSL2591_GAIN_MAX};
tsl2591IntegrationTime_t const int_enum_array[6] PROGMEM = {TSL2591_INTEGRATIONTIME_100MS,TSL2591_INTEGRATIONTIME_200MS,TSL2591_INTEGRATIONTIME_300MS,TSL2591_INTEGRATIONTIME_400MS,TSL2591_INTEGRATIONTIME_500MS,TSL2591_INTEGRATIONTIME_600MS};

void Tsl2591Init(void)
{
Expand Down Expand Up @@ -81,7 +81,7 @@ void Tsl2591Show(bool json)
char lux_str[10];
dtostrf(tsl2591_lux, sizeof(lux_str)-1, 3, lux_str);
if (json) {
ResponseAppend_P(PSTR(",\"TSL2591\":{\"" D_JSON_ILLUMINANCE "\":%s}"), lux_str);
ResponseAppend_P(PSTR(",\"TSL2591\":{\"" D_JSON_ILLUMINANCE "\":%s}"), lux_str);
#ifdef USE_DOMOTICZ
if (0 == TasmotaGlobal.tele_period) { DomoticzSensor(DZ_ILLUMINANCE, tsl2591_lux); }
#endif // USE_DOMOTICZ
Expand Down
4 changes: 2 additions & 2 deletions tools/decode-status.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@
"USE_INA219","USE_SHT3X","USE_MHZ19","USE_TSL2561",
"USE_SENSEAIR","USE_PMS5003","USE_MGS","USE_NOVA_SDS",
"USE_SGP30","USE_SR04","USE_SDM120","USE_SI1145",
"USE_SDM630","USE_LM75AD","USE_APDS9960","USE_TM1638","USE_MS5837"
],[
"USE_SDM630","USE_LM75AD","USE_APDS9960","USE_TM1638"
],[
"USE_MCP230xx","USE_MPR121","USE_CCS811","USE_MPU6050",
"USE_MCP230xx_OUTPUT","USE_MCP230xx_DISPLAYOUTPUT","USE_HLW8012","USE_CSE7766",
"USE_MCP39F501","USE_PZEM_AC","USE_DS3231","USE_HX711",
Expand Down

0 comments on commit 7850d6d

Please sign in to comment.