return to htu

This commit is contained in:
lexa
2024-07-14 14:39:19 +03:00
parent 32cba61fc0
commit 778310dec3
2 changed files with 107 additions and 112 deletions

View File

@@ -7,25 +7,20 @@
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
;enjoyneering/AHT10@^1.1.0
;ottowinter/AsyncMqttClient-esphome @ ^0.8.6
;adafruit/Adafruit AHTX0 @ ^2.0
[env:d1_mini]
platform = espressif8266
board = d1_mini
framework = arduino
upload_protocol = espota
upload_port = 192.168.1.136
;upload_protocol = espota
;upload_port = 192.168.1.136
lib_deps =
knolleary/PubSubClient @ ^2.8
ottowinter/ESPAsyncWebServer-esphome @ ^2.1.0
ayushsharma82/AsyncElegantOTA @ ^2.2.6
ayushsharma82/WebSerial @ ^1.3.0
jwrw/ESP_EEPROM @ ^2.0.0
#beegee-tokyo/DHT sensor library for ESPx @ ^1.19
https://github.com/enjoyneering/HTU2xD_SHT2x_Si70xx.git
https://github.com/pilotak/MeteoFunctions.git
https://github.com/RobTillaart/SHT31.git
knolleary/PubSubClient @ ^2.8
ottowinter/ESPAsyncWebServer-esphome @ ^2.1.0
;ayushsharma82/AsyncElegantOTA @ ^2.2.9
ayushsharma82/WebSerial @ ^1.3.0
jwrw/ESP_EEPROM @ ^2.0.0
https://github.com/enjoyneering/HTU2xD_SHT2x_Si70xx.git
https://github.com/pilotak/MeteoFunctions.git
;https://github.com/RobTillaart/SHT31.git
;ayushsharma82/ElegantOTA@^3.1.2

View File

@@ -12,7 +12,7 @@
#include <ESP_EEPROM.h>
#include <PubSubClient.h>
#include <HTU2xD_SHT2x_Si70xx.h>
#include "SHT31.h"
//#include "SHT31.h"
#include <MeteoFunctions.h>
#define WIFI_SSID "wf-home"
@@ -29,8 +29,8 @@
#define LAMP_OUT (D5)
#define SHT31_ADDRESS 0x44
SHT31 sht(SHT31_ADDRESS);
//HTU2xD_SHT2x_SI70xx ht2x(HTU2xD_SENSOR, HUMD_12BIT_TEMP_14BIT); //sensor type, resolution
//SHT31 sht;
HTU2xD_SHT2x_SI70xx ht2x(HTU2xD_SENSOR, HUMD_12BIT_TEMP_14BIT); //sensor type, resolution
MeteoFunctions calc;
@@ -118,23 +118,22 @@ void setup() {
// delay(500);
// }
digitalWrite(LED_WF, HIGH);
//ht2x.begin();
ht2x.begin();
temp_out = NAN;
hum_out = NAN;
if(!sht.begin()){
Serial.println("SHT not ready");
}
// if(!sht.begin()){
// Serial.println("SHT not ready");
// }
uint16_t stat = sht.readStatus();
Serial.print(stat, HEX);
//delay(500);
sht.read(false);
temp_out = sht.getTemperature();
hum_out = sht.getRawHumidity();
sht.requestData();
// uint16_t stat = sht.readStatus();
// Serial.print(stat, HEX);
// //delay(500);
// sht.read(false);
// temp_out = sht.getTemperature();
// hum_out = sht.getRawHumidity();
// sht.requestData();
//ht2x.begin();
//getTiH();
////////////////////////////////
// dht.setup(D1, DHTesp::DHT22);
@@ -187,9 +186,9 @@ void loop() {
//bSecs = 0;
digitalWrite(LED_WRK, LOW);
sprintf(v, "%.1f", temp_out);
//client.publish(TOPIC"tempout", v);
client.publish(TOPIC"tempout", v);
sprintf(v, "%.1f", hum_out);
//client.publish(TOPIC"humout", v);
client.publish(TOPIC"humout", v);
sprintf(v, "%.1f", heatindex);
client.publish(TOPIC"heatindex", v);
sprintf(v, "%.1f", dewpoint);
@@ -242,6 +241,7 @@ void callback(char* topic, byte* payload, unsigned int length) {
Serial.println(val);
val[i] = 0;
if(strcmp(topic, TOPIC"light") == 0){
Serial.printf("MQTT light %s\n", val);
if(atoi(val) == 0){
//analogWrite(LAMP_OUT, 0);
led = false;
@@ -301,86 +301,86 @@ boolean getTiH(void)
// WebSerial.println(stat, HEX);
// int error = sht.getError();
// WebSerial.println(error, HEX);
if (!sht.isConnected()){
WebSerial.println("SHT Not Connected");
return false;
}
if(sht.dataReady()){
bool success = sht.readData();
sht.requestData();
if (success){
htValue = sht.getTemperature();
fTemp = htValue;
if (!isnan(temp_out))
temp_out += (htValue - temp_out) / 30.0;
else
temp_out = htValue;
htValue = sht.getHumidity();
if (!isnan(hum_out))
hum_out += (htValue - hum_out) / 30.0;
else
hum_out = htValue;
heatindex = calc.heatIndex_c(temp_out, hum_out);
dewpoint = calc.dewPoint_c(temp_out, hum_out);
apptemp = calc.apparentTemp_c(temp_out, hum_out, windspeed);
WebSerial.print("Temp: ");
WebSerial.print(fTemp);
WebSerial.print(", Hum: ");
WebSerial.println(htValue);
return true;
}
else{
WebSerial.print("No data");
}
}
return false;
// htValue = ht2x.readTemperature(); //accuracy +-0.3C in range 0C..60C at 14-bit
// Serial.print("Temperature...............: ");
// if (htValue != HTU2XD_SHT2X_SI70XX_ERROR) //HTU2XD_SHT2X_SI70XX_ERROR = 255, library returns 255 if error occurs
// {
// Serial.print(htValue);
// Serial.println(F(" +-0.3C"));
// fTemp = htValue;
// }
// else
// {
// Serial.println("<error>");
// //ht2x.begin();
// //ht2x.softReset(); //last chance to make it alive, all registers (except heater bit) will set to default
// //ht2x.setHeater(false); //true=heater on, false=heater off
// //ht2x.setResolution(HUMD_12BIT_TEMP_14BIT); //humidity 12-bit, temperature 14-bit
// WebSerial.println("HTU Bad");
// if (!sht.isConnected()){
// WebSerial.println("SHT Not Connected");
// return false;
// }
// if (htValue != HTU2XD_SHT2X_SI70XX_ERROR) //if temperature OK, measure RH & calculate compensated humidity
// {
// htValue = ht2x.readHumidity();// getCompensatedHumidity(htValue); //accuracy +-2% in range 0%..100%/0C..80C at 12-bit, to compensates influence of T on RH
// if(sht.dataReady()){
// bool success = sht.readData();
// sht.requestData();
// if (success){
// htValue = sht.getTemperature();
// fTemp = htValue;
// if (!isnan(temp_out))
// temp_out += (htValue - temp_out) / 30.0;
// else
// temp_out = htValue;
// htValue = sht.getHumidity();
// if (!isnan(hum_out))
// hum_out += (htValue - hum_out) / 30.0;
// else
// hum_out = htValue;
// heatindex = calc.heatIndex_c(temp_out, hum_out);
// dewpoint = calc.dewPoint_c(temp_out, hum_out);
// apptemp = calc.apparentTemp_c(temp_out, hum_out, windspeed);
// WebSerial.print("Temp: ");
// WebSerial.print(fTemp);
// WebSerial.print(", Hum: ");
// WebSerial.println(htValue);
// return true;
// }
// else{
// WebSerial.print("No data");
// }
// }
// return false;
htValue = ht2x.readTemperature(); //accuracy +-0.3C in range 0C..60C at 14-bit
Serial.print("Temperature...............: ");
if (htValue != HTU2XD_SHT2X_SI70XX_ERROR) //HTU2XD_SHT2X_SI70XX_ERROR = 255, library returns 255 if error occurs
{
Serial.print(htValue);
Serial.println(F(" +-0.3C"));
fTemp = htValue;
}
else
{
Serial.println("<error>");
//ht2x.begin();
// if (htValue != HTU2XD_SHT2X_SI70XX_ERROR)
// {
// Serial.print(htValue);
// Serial.println(" +-2%");
// hum_out = htValue;
// }
// }
// if (htValue != HTU2XD_SHT2X_SI70XX_ERROR)
// {
// if (!isnan(temp_out))
// temp_out += (fTemp - temp_out) / 30.0;
// else
// temp_out = fTemp;
// if (!isnan(hum_out))
// hum_out += (htValue - hum_out) / 30.0;
// else
// hum_out = htValue;
// heatindex = calc.heatIndex_c(temp_out, hum_out);
// dewpoint = calc.dewPoint_c(temp_out, hum_out);
// apptemp = calc.apparentTemp_c(temp_out, hum_out, windspeed);
// WebSerial.print("Temp: ");
// WebSerial.print(fTemp);
// WebSerial.print(", Hum: ");
// WebSerial.println(htValue);
// }
// return true;
//ht2x.softReset(); //last chance to make it alive, all registers (except heater bit) will set to default
//ht2x.setHeater(false); //true=heater on, false=heater off
//ht2x.setResolution(HUMD_12BIT_TEMP_14BIT); //humidity 12-bit, temperature 14-bit
WebSerial.println("HTU Bad");
return false;
}
if (htValue != HTU2XD_SHT2X_SI70XX_ERROR) //if temperature OK, measure RH & calculate compensated humidity
{
htValue = ht2x.readHumidity();// getCompensatedHumidity(htValue); //accuracy +-2% in range 0%..100%/0C..80C at 12-bit, to compensates influence of T on RH
if (htValue != HTU2XD_SHT2X_SI70XX_ERROR)
{
Serial.print(htValue);
Serial.println(" +-2%");
hum_out = htValue;
}
}
if (htValue != HTU2XD_SHT2X_SI70XX_ERROR)
{
if (!isnan(temp_out))
temp_out += (fTemp - temp_out) / 30.0;
else
temp_out = fTemp;
if (!isnan(hum_out))
hum_out += (htValue - hum_out) / 30.0;
else
hum_out = htValue;
heatindex = calc.heatIndex_c(temp_out, hum_out);
dewpoint = calc.dewPoint_c(temp_out, hum_out);
apptemp = calc.apparentTemp_c(temp_out, hum_out, windspeed);
WebSerial.print("Temp: ");
WebSerial.print(fTemp);
WebSerial.print(", Hum: ");
WebSerial.println(htValue);
}
return true;
}