Wetterstation_Boris/include/mess_htu21.h

50 lines
1.4 KiB
C
Raw Normal View History

2023-05-18 12:10:48 +02:00
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_I2CDevice.h>
#include <Adafruit_HTU21DF.h>
Adafruit_HTU21DF htu = Adafruit_HTU21DF();
bool F_HTU_21D;
2023-05-18 13:17:57 +02:00
float K_HTU= -0.00;
2023-05-18 12:10:48 +02:00
struct {
char temperature[15] = {0};
char humity[15] = {0};
} htuData;
void init_HTU21(){
F_HTU_21D = false;
if (!htu.begin()) {
Serial.println("Couldn't find sensor HUT21D!");
2023-05-19 14:15:31 +02:00
SystemStatus = SystemStatus | HTU21noReady;
2023-05-18 12:10:48 +02:00
}
F_HTU_21D = true;
Serial.println("HUT21D gefunden");
}
void read_HTU21D() {
float t = htu.readTemperature();
t = t + K_HTU;
dtostrf(t,7,1,htuData.temperature);
float h = htu.readHumidity();
dtostrf(h,7,1,htuData.humity);
Serial.print("Temperature (HTU21D):\t");
Serial.print(htuData.temperature);
Serial.println(" °C");
Serial.print("Luftfeuchtigkeit:\t");
Serial.print(htuData.humity);
Serial.println(" %");
}
void M2M_HTU21D(String deviceId = "4711") {
char topic[100];
sprintf(topic, "%s%s%s", "hjk/devices/", deviceId.c_str(), "/telemetry/temperature_Htu_21" );
client.publish(topic, htuData.temperature, true);
sprintf(topic, "%s%s%s", "hjk/devices/", deviceId.c_str(), "/telemetry/humity" );
client.publish(topic, htuData.humity, true);
/* Serial.printf("HTU21:\t\t %s °C\n", htuData.temperature);
Serial.printf("HTU21:\t\t %s %%\n", htuData.humity); */
}