This shows you the differences between two versions of the page.
| en:iot:dht [2017/09/22 11:48] – created Somepub | en:iot:dht [2020/07/20 12:00] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | <code c> | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | #include < | ||
| + | #define DHTPIN D4 // what pin we're connected to | ||
| + | #define DHTTYPE DHT22 // DHT 22 (AM2302) | ||
| + | |||
| + | DHT dht(DHTPIN, DHTTYPE); | ||
| + | |||
| + | void iot_connected() | ||
| + | { | ||
| + | Serial.println(" | ||
| + | iot.log(" | ||
| + | } | ||
| + | |||
| + | void setup() | ||
| + | { | ||
| + | Serial.begin(115200); | ||
| + | Serial.println(" | ||
| + | iot.printConfig(); | ||
| + | iot.setup(); | ||
| + | pinMode(16, OUTPUT); | ||
| + | dht.begin(); | ||
| + | |||
| + | } | ||
| + | |||
| + | void loop() | ||
| + | { | ||
| + | iot.handle(); | ||
| + | |||
| + | float h = dht.readHumidity(); | ||
| + | float t = dht.readTemperature(); | ||
| + | |||
| + | char buf[10]; // Put whatever length you need here | ||
| + | String(t).toCharArray(buf, | ||
| + | |||
| + | digitalWrite(16, | ||
| + | iot.publishMsg(" | ||
| + | delay(2000); | ||
| + | digitalWrite(16, | ||
| + | |||
| + | String(h).toCharArray(buf, | ||
| + | iot.publishMsg(" | ||
| + | delay(2000); | ||
| + | } | ||
| + | |||
| + | |||
| + | </ | ||