supla-device
Loading...
Searching...
No Matches
SHT10.h
1// SPDX-FileCopyrightText: AC SOFTWARE SP. Z O.O.
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#ifndef SRC_SUPLA_SENSOR_SHT10_H_
5#define SRC_SUPLA_SENSOR_SHT10_H_
6
7#include <Arduino.h>
8#include <supla/sensor/therm_hygro_meter.h>
9#include <SHT1x-ESP.h> // https://github.com/beegee-tokyo/SHT1x-ESP
10// data pin pulled up with 10k resistor
11
12namespace Supla {
13namespace Sensor {
14class SHT10 : public ThermHygroMeter {
15 public:
16 explicit SHT10(int data_pin_, int clock_pin_)
17 : sht1x(data_pin_, clock_pin_, SHT1x::Voltage::DC_3_3v) {
18 }
19
20 double getTemp() {
21 temperature = sht1x.readTemperatureC();
22 if (isnan(temperature) || temperature < -30) {
23 temperature = TEMPERATURE_NOT_AVAILABLE;
24 }
25 return temperature;
26 }
27
28 double getHumi() {
29 humidity = sht1x.readHumidity();
30 if (isnan(humidity) || humidity < 0) {
31 humidity = HUMIDITY_NOT_AVAILABLE;
32 }
33 return humidity;
34 }
35
36 private:
37 void iterateAlways() {
38 if (millis() - lastReadTime > 10000) {
39 lastReadTime = millis();
40 channel.setNewValue(getTemp(), getHumi());
41 }
42 }
43
44 void onInit() {
45 channel.setNewValue(getTemp(), getHumi());
46 }
47
48 protected:
49 ::SHT1x sht1x;
50 double temperature = TEMPERATURE_NOT_AVAILABLE;
51 double humidity = HUMIDITY_NOT_AVAILABLE;
52};
53}; // namespace Sensor
54}; // namespace Supla
55
56#endif // SRC_SUPLA_SENSOR_SHT10_H_
Definition SHT10.h:14
Definition therm_hygro_meter.h:14