Created
March 26, 2019 22:21
-
-
Save gantrim/7bef2aa59519c2627aabc658273bb9ab to your computer and use it in GitHub Desktop.
Server Room Temperature Monitor - Full Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <PietteTech_DHT.h> | |
#define DHTTYPE DHT22 | |
#define DHTPIN D4 | |
PietteTech_DHT DHT(DHTPIN, DHTTYPE); | |
double serverTempMax = 81; | |
double serverHumidityMax = 60; | |
double serverTemp; | |
double serverHumidity; | |
bool overheatDetected = false; | |
bool tooHumid = false; | |
void setup() | |
{ | |
Serial.begin(9600); | |
Particle.variable("serverTemp", &serverTemp, DOUBLE); | |
Particle.variable("serverHumidity", &serverHumidity, DOUBLE); | |
} | |
void loop() | |
{ | |
int result = DHT.acquireAndWait(2000); | |
serverTemp = DHT.getFahrenheit(); | |
serverHumidity = DHT.getHumidity(); | |
if(serverTemp>=serverTempMax && !overheatDetected){ | |
Particle.publish("server_temp", "overheat"); | |
overheatDetected = true; | |
} | |
else if(serverTemp<serverTempMax && overheatDetected){ | |
Particle.publish("server_temp", "normal"); | |
overheatDetected = false; | |
} | |
if(serverHumidity>=serverHumidityMax && !tooHumid){ | |
Particle.publish("server_humidity", "tooHumid"); | |
tooHumid = true; | |
} | |
else if(serverHumidity<serverHumidityMax && tooHumid){ | |
Particle.publish("server_humidity", "normal"); | |
tooHumid = false; | |
} | |
delay(10000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment