esp8266_web_settings beta
DhtSensor.h
1/*
2 * Copyright (c) 2021, 2022 G. R. McDorman
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in all
12 * copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23#pragma once
24
25#include <memory>
26
27#include <DHT.h>
28#include <Ticker.h>
29
30#include "grmcdorman/device/AbstractTemperaturePressureSensor.h"
31
32namespace grmcdorman::device
33{
52 {
53 public:
54 DhtSensor();
55
56 void setup() override;
57 void loop() override;
58
70 virtual String get_status() const;
71 private:
73 constexpr static uint32_t statusReadInterval = (30 / 5) * 1000;
74
75 void set_timer();
76 void reset_dht();
77
78 std::unique_ptr<DHT> dht;
79 Ticker ticker;
80 int last_status = 0;
81 uint32_t last_read_millis = 0;
82 uint32_t current_polling_seconds = 0;
83 bool requested = false;
84 uint32_t request_previous_mills = 0;
85 NoteSetting title;
86 ExclusiveOptionSetting dataPin;
87 ExclusiveOptionSetting dhtModel;
88 FloatSetting temperatureOffset;
89 FloatSetting temperatureScale;
90 FloatSetting humidityOffset;
91 FloatSetting humidityScale;
92 UnsignedIntegerSetting readInterval;
93 InfoSettingHtml device_status;
94 };
95}
This is an abstract base class for temperature/pressor sensors.
Definition: AbstractTemperaturePressureSensor.h:38
This class supports the DHT11 and DHT22 sensors as a device.
Definition: DhtSensor.h:52
void setup() override
Setup the device.
Definition: DhtSensor.cpp:140
void loop() override
Main loop.
Definition: DhtSensor.cpp:174
virtual String get_status() const
Get a status report.
Definition: DhtSensor.cpp:197