32 lines
942 B
C
32 lines
942 B
C
#include "Adafruit_HTU21DF.h"
|
|
|
|
Adafruit_HTU21DF htu = Adafruit_HTU21DF();
|
|
|
|
struct {
|
|
char temperature[15] = {0};
|
|
char humity[15] = {0};
|
|
} htuData;
|
|
|
|
void init_HTU21(){
|
|
if (!htu.begin()) {
|
|
Serial.println("Couldn't find sensor HUT21D!");
|
|
while (1);
|
|
}
|
|
Serial.println("HUT21D gefunden");
|
|
}
|
|
|
|
void read_HTU21D() {
|
|
float t = htu.readTemperature();
|
|
dtostrf(t,10,4,htuData.temperature);
|
|
float h = htu.readHumidity();
|
|
dtostrf(h,8,2,htuData.humity);
|
|
}
|
|
|
|
void M2M_HTU21D(long deviceId = 4711) {
|
|
char topic[100];
|
|
sprintf(topic, "%s%ld%s", "hjk/devices/", deviceId, "/telemetry/temperature_Htu_21" );
|
|
client.publish(topic, htuData.temperature, true);
|
|
sprintf(topic, "%s%ld%s", "hjk/devices/", deviceId, "/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); |