Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sumnerboy12 committed May 4, 2016
0 parents commit cdfb523
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
@@ -0,0 +1 @@
#wemos-dht22
59 changes: 59 additions & 0 deletions wemos-dht22.ino
@@ -0,0 +1,59 @@
#include <Homie.h>
#include <DHT.h>

#define FW_NAME "wemos-dht"
#define FW_VERSION "0.0.3"

/* Magic sequence for Autodetectable Binary Upload */
const char *__FLAGGED_FW_NAME = "\xbf\x84\xe4\x13\x54" FW_NAME "\x93\x44\x6b\xa7\x75";
const char *__FLAGGED_FW_VERSION = "\x6a\x3f\x3e\x0e\xe1" FW_VERSION "\xb0\x30\x48\xd4\x1a";
/* End of magic sequence for Autodetectable Binary Upload */

#define DHT_PIN D4
#define DHT_TYPE DHT22
#define PUB_INTERVAL 60

HomieNode temperatureNode("temperature", "temperature");
HomieNode humidityNode("humidity", "humidity");

DHT dht(DHT_PIN, DHT_TYPE);

unsigned long lastPublish = 0;

void setupHandler() {
Homie.setNodeProperty(temperatureNode, "unit", "c", true);
Homie.setNodeProperty(humidityNode, "unit", "%", true);

dht.begin();
}

void loopHandler() {
if (millis() - lastPublish >= PUB_INTERVAL * 1000UL) {
float t = dht.readTemperature();
float h = dht.readHumidity();

if (!isnan(t) && Homie.setNodeProperty(temperatureNode, "degrees", String(t), true)) {
lastPublish = millis();
}
if (!isnan(h) && Homie.setNodeProperty(humidityNode, "relative", String(h), true)) {
lastPublish = millis();
}
}
}

void setup() {
Homie.setFirmware(FW_NAME, FW_VERSION);

Homie.registerNode(temperatureNode);
Homie.registerNode(humidityNode);

Homie.setSetupFunction(setupHandler);
Homie.setLoopFunction(loopHandler);

Homie.enableBuiltInLedIndicator(false);
Homie.setup();
}

void loop() {
Homie.loop();
}

0 comments on commit cdfb523

Please sign in to comment.