return to htu
This commit is contained in:
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user