return to htu
This commit is contained in:
@@ -7,25 +7,20 @@
|
|||||||
;
|
;
|
||||||
; Please visit documentation for the other options and examples
|
; Please visit documentation for the other options and examples
|
||||||
; https://docs.platformio.org/page/projectconf.html
|
; 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]
|
[env:d1_mini]
|
||||||
platform = espressif8266
|
platform = espressif8266
|
||||||
board = d1_mini
|
board = d1_mini
|
||||||
framework = arduino
|
framework = arduino
|
||||||
upload_protocol = espota
|
;upload_protocol = espota
|
||||||
upload_port = 192.168.1.136
|
;upload_port = 192.168.1.136
|
||||||
|
|
||||||
|
|
||||||
lib_deps =
|
lib_deps =
|
||||||
knolleary/PubSubClient @ ^2.8
|
knolleary/PubSubClient @ ^2.8
|
||||||
ottowinter/ESPAsyncWebServer-esphome @ ^2.1.0
|
ottowinter/ESPAsyncWebServer-esphome @ ^2.1.0
|
||||||
ayushsharma82/AsyncElegantOTA @ ^2.2.6
|
;ayushsharma82/AsyncElegantOTA @ ^2.2.9
|
||||||
ayushsharma82/WebSerial @ ^1.3.0
|
ayushsharma82/WebSerial @ ^1.3.0
|
||||||
jwrw/ESP_EEPROM @ ^2.0.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/enjoyneering/HTU2xD_SHT2x_Si70xx.git
|
||||||
https://github.com/pilotak/MeteoFunctions.git
|
https://github.com/pilotak/MeteoFunctions.git
|
||||||
https://github.com/RobTillaart/SHT31.git
|
;https://github.com/RobTillaart/SHT31.git
|
||||||
|
;ayushsharma82/ElegantOTA@^3.1.2
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
#include <ESP_EEPROM.h>
|
#include <ESP_EEPROM.h>
|
||||||
#include <PubSubClient.h>
|
#include <PubSubClient.h>
|
||||||
#include <HTU2xD_SHT2x_Si70xx.h>
|
#include <HTU2xD_SHT2x_Si70xx.h>
|
||||||
#include "SHT31.h"
|
//#include "SHT31.h"
|
||||||
#include <MeteoFunctions.h>
|
#include <MeteoFunctions.h>
|
||||||
|
|
||||||
#define WIFI_SSID "wf-home"
|
#define WIFI_SSID "wf-home"
|
||||||
@@ -29,8 +29,8 @@
|
|||||||
|
|
||||||
#define LAMP_OUT (D5)
|
#define LAMP_OUT (D5)
|
||||||
#define SHT31_ADDRESS 0x44
|
#define SHT31_ADDRESS 0x44
|
||||||
SHT31 sht(SHT31_ADDRESS);
|
//SHT31 sht;
|
||||||
//HTU2xD_SHT2x_SI70xx ht2x(HTU2xD_SENSOR, HUMD_12BIT_TEMP_14BIT); //sensor type, resolution
|
HTU2xD_SHT2x_SI70xx ht2x(HTU2xD_SENSOR, HUMD_12BIT_TEMP_14BIT); //sensor type, resolution
|
||||||
MeteoFunctions calc;
|
MeteoFunctions calc;
|
||||||
|
|
||||||
|
|
||||||
@@ -118,23 +118,22 @@ void setup() {
|
|||||||
// delay(500);
|
// delay(500);
|
||||||
// }
|
// }
|
||||||
digitalWrite(LED_WF, HIGH);
|
digitalWrite(LED_WF, HIGH);
|
||||||
//ht2x.begin();
|
ht2x.begin();
|
||||||
temp_out = NAN;
|
temp_out = NAN;
|
||||||
hum_out = NAN;
|
hum_out = NAN;
|
||||||
|
|
||||||
if(!sht.begin()){
|
// if(!sht.begin()){
|
||||||
Serial.println("SHT not ready");
|
// Serial.println("SHT not ready");
|
||||||
}
|
// }
|
||||||
|
|
||||||
uint16_t stat = sht.readStatus();
|
// uint16_t stat = sht.readStatus();
|
||||||
Serial.print(stat, HEX);
|
// Serial.print(stat, HEX);
|
||||||
//delay(500);
|
// //delay(500);
|
||||||
sht.read(false);
|
// sht.read(false);
|
||||||
temp_out = sht.getTemperature();
|
// temp_out = sht.getTemperature();
|
||||||
hum_out = sht.getRawHumidity();
|
// hum_out = sht.getRawHumidity();
|
||||||
sht.requestData();
|
// sht.requestData();
|
||||||
|
|
||||||
//ht2x.begin();
|
|
||||||
//getTiH();
|
//getTiH();
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
// dht.setup(D1, DHTesp::DHT22);
|
// dht.setup(D1, DHTesp::DHT22);
|
||||||
@@ -187,9 +186,9 @@ void loop() {
|
|||||||
//bSecs = 0;
|
//bSecs = 0;
|
||||||
digitalWrite(LED_WRK, LOW);
|
digitalWrite(LED_WRK, LOW);
|
||||||
sprintf(v, "%.1f", temp_out);
|
sprintf(v, "%.1f", temp_out);
|
||||||
//client.publish(TOPIC"tempout", v);
|
client.publish(TOPIC"tempout", v);
|
||||||
sprintf(v, "%.1f", hum_out);
|
sprintf(v, "%.1f", hum_out);
|
||||||
//client.publish(TOPIC"humout", v);
|
client.publish(TOPIC"humout", v);
|
||||||
sprintf(v, "%.1f", heatindex);
|
sprintf(v, "%.1f", heatindex);
|
||||||
client.publish(TOPIC"heatindex", v);
|
client.publish(TOPIC"heatindex", v);
|
||||||
sprintf(v, "%.1f", dewpoint);
|
sprintf(v, "%.1f", dewpoint);
|
||||||
@@ -242,6 +241,7 @@ void callback(char* topic, byte* payload, unsigned int length) {
|
|||||||
Serial.println(val);
|
Serial.println(val);
|
||||||
val[i] = 0;
|
val[i] = 0;
|
||||||
if(strcmp(topic, TOPIC"light") == 0){
|
if(strcmp(topic, TOPIC"light") == 0){
|
||||||
|
Serial.printf("MQTT light %s\n", val);
|
||||||
if(atoi(val) == 0){
|
if(atoi(val) == 0){
|
||||||
//analogWrite(LAMP_OUT, 0);
|
//analogWrite(LAMP_OUT, 0);
|
||||||
led = false;
|
led = false;
|
||||||
@@ -301,75 +301,21 @@ boolean getTiH(void)
|
|||||||
// WebSerial.println(stat, HEX);
|
// WebSerial.println(stat, HEX);
|
||||||
// int error = sht.getError();
|
// int error = sht.getError();
|
||||||
// WebSerial.println(error, HEX);
|
// WebSerial.println(error, HEX);
|
||||||
if (!sht.isConnected()){
|
// if (!sht.isConnected()){
|
||||||
WebSerial.println("SHT Not Connected");
|
// 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");
|
|
||||||
// return false;
|
// return false;
|
||||||
// }
|
// }
|
||||||
// if (htValue != HTU2XD_SHT2X_SI70XX_ERROR) //if temperature OK, measure RH & calculate compensated humidity
|
// if(sht.dataReady()){
|
||||||
// {
|
// bool success = sht.readData();
|
||||||
// htValue = ht2x.readHumidity();// getCompensatedHumidity(htValue); //accuracy +-2% in range 0%..100%/0C..80C at 12-bit, to compensates influence of T on RH
|
// sht.requestData();
|
||||||
|
// if (success){
|
||||||
// if (htValue != HTU2XD_SHT2X_SI70XX_ERROR)
|
// htValue = sht.getTemperature();
|
||||||
// {
|
// fTemp = htValue;
|
||||||
// Serial.print(htValue);
|
|
||||||
// Serial.println(" +-2%");
|
|
||||||
// hum_out = htValue;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// if (htValue != HTU2XD_SHT2X_SI70XX_ERROR)
|
|
||||||
// {
|
|
||||||
// if (!isnan(temp_out))
|
// if (!isnan(temp_out))
|
||||||
// temp_out += (fTemp - temp_out) / 30.0;
|
// temp_out += (htValue - temp_out) / 30.0;
|
||||||
// else
|
// else
|
||||||
// temp_out = fTemp;
|
// temp_out = htValue;
|
||||||
|
// htValue = sht.getHumidity();
|
||||||
// if (!isnan(hum_out))
|
// if (!isnan(hum_out))
|
||||||
// hum_out += (htValue - hum_out) / 30.0;
|
// hum_out += (htValue - hum_out) / 30.0;
|
||||||
// else
|
// else
|
||||||
@@ -381,6 +327,60 @@ boolean getTiH(void)
|
|||||||
// WebSerial.print(fTemp);
|
// WebSerial.print(fTemp);
|
||||||
// WebSerial.print(", Hum: ");
|
// WebSerial.print(", Hum: ");
|
||||||
// WebSerial.println(htValue);
|
// WebSerial.println(htValue);
|
||||||
// }
|
|
||||||
// return true;
|
// 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");
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user