Last active
February 27, 2020 05:18
-
-
Save vjandrei/8cf9d532472503754344b7d9834b7ff1 to your computer and use it in GitHub Desktop.
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 "FirebaseESP8266.h" | |
#include <ESP8266WiFi.h> | |
#include <SHT1x.h> | |
// Define your wifi data | |
#define FIREBASE_HOST "example.firebaseio.com" | |
#define FIREBASE_AUTH "--" | |
#define WIFI_SSID "--" | |
#define WIFI_PASSWORD "--" | |
//Define Firebase Data objects | |
FirebaseData firebaseData; | |
// Specify data and clock connections and instantiate SHT1x object | |
#define dataPin 4 | |
#define clockPin 5 | |
SHT1x sht1x(dataPin, clockPin); | |
String path = "/mokki-sauna"; | |
void setup() { | |
Serial.begin(115200); | |
WiFi.begin(WIFI_SSID, WIFI_PASSWORD); | |
Serial.print("Connecting to Wi-Fi"); | |
while (WiFi.status() != WL_CONNECTED) | |
{ | |
Serial.print("."); | |
delay(300); | |
} | |
Serial.println(); | |
Serial.print("Connected with IP: "); | |
Serial.println(WiFi.localIP()); | |
Serial.println(); | |
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH); | |
Firebase.reconnectWiFi(true); | |
if (!Firebase.beginStream(firebaseData, "temp" )) | |
{ | |
Serial.println("Could not begin stream"); | |
Serial.println("REASON: " + firebaseData.errorReason()); | |
Serial.println(); | |
} | |
if (Firebase.getInt(firebaseData, path + "temp" )) { | |
if (firebaseData.dataType() == "int") { | |
Serial.println(firebaseData.intData()); | |
} | |
} else { | |
Serial.println(firebaseData.errorReason()); | |
} | |
} | |
void loop() | |
{ | |
float temp_c; | |
float temp_f; | |
float humidity; | |
// Read values from the sensor | |
temp_c = sht1x.readTemperatureC(); | |
temp_f = sht1x.readTemperatureF(); | |
humidity = sht1x.readHumidity(); | |
// Print the values to the serial port | |
Serial.print("Temperature: "); | |
Serial.print(temp_c, DEC); | |
Serial.print("C / "); | |
Serial.print(temp_f, DEC); | |
Serial.print("F. Humidity: "); | |
Serial.print(humidity); | |
Serial.println("%"); | |
delay(2000); | |
if (Firebase.setInt(firebaseData, "temp", temp_c)) { | |
if (temp_c) | |
Serial.println("Temp to High"); | |
else | |
Serial.println("Temp to Low"); | |
} | |
if (Firebase.setInt(firebaseData, "humidity", humidity)) { | |
if (humidity) | |
Serial.println("Humidity to High"); | |
else | |
Serial.println("Humidity to Low"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment