Differences

This shows you the differences between two versions of the page.

Link to this comparison view

en:iot:dht [2017/09/22 11:48] – created Somepuben:iot:dht [2020/07/20 12:00] (current) – external edit 127.0.0.1
Line 1: Line 1:
 +<code c>
  
 +#include <Arduino.h>
 +#include <ittiot.h>
 +
 +#include <DHT.h>
 +#define DHTPIN D4     // what pin we're connected to
 +#define DHTTYPE DHT22   // DHT 22  (AM2302)
 +
 +DHT dht(DHTPIN, DHTTYPE);
 +
 +void iot_connected()
 +{
 +  Serial.println("MQTT connected callback");
 +  iot.log("IoT DHT example!");
 +}
 +
 +void setup()
 +{
 +  Serial.begin(115200);
 +  Serial.println("Booting");
 +  iot.printConfig(); // print json config to serial //Peale Serial.begin ja enne iot.setup
 +  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,10);
 +
 +  digitalWrite(16,HIGH);
 +  iot.publishMsg("temp",buf);
 + delay(2000);
 +  digitalWrite(16,LOW);
 +
 + String(h).toCharArray(buf,10);
 +  iot.publishMsg("hum",buf);
 + delay(2000);
 +}
 +
 +
 +</code>
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0