Created
October 22, 2018 21:40
-
-
Save jewel3g/bceab7a6d82fa86e55353765ac047815 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 <ESP8266WiFi.h> | |
#include <FirebaseArduino.h> | |
// Set these to run example. | |
#define FIREBASE_HOST "nasa2018-77e29.firebaseio.com" | |
#define FIREBASE_AUTH "8rwBzWLyLGo3Hs7HBNRM6KMbOvMPt5pJideg3Kjy" | |
#define WIFI_SSID "Robot1" | |
#define WIFI_PASSWORD "121121121" | |
#define flamePin 8 | |
#define smokePin A0 | |
void setup() { | |
Serial.begin(9600); | |
Serial.println("Stuck in setup"); | |
pinMode(A0,INPUT); | |
pinMode(flamePin,INPUT); | |
pinMode(smokePin,INPUT); | |
// connect to wifi. | |
WiFi.begin(WIFI_SSID, WIFI_PASSWORD); | |
Serial.print("connecting"); | |
while (WiFi.status() != WL_CONNECTED) { | |
Serial.print("."); | |
delay(500); | |
} | |
Serial.println(); | |
Serial.print("connected: "); | |
Serial.println(WiFi.localIP()); | |
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH); | |
} | |
int n = 0; | |
int flame; | |
int smoke; | |
void pushData(){ | |
Firebase.setString("/devices/device1/smoke",(String)flame); | |
if (Firebase.failed()) { | |
Serial.print("setting /number failed:"); | |
Serial.println(Firebase.error()); | |
return; | |
} | |
delay(1000); | |
Firebase.setString("/devices/device1/fire", (String)smoke); | |
if (Firebase.failed()) { | |
Serial.print("setting /number failed:"); | |
Serial.println(Firebase.error()); | |
return; | |
} | |
delay(1000); | |
} | |
void sensorData(){ | |
flame = analogRead(A0); | |
smoke = analogRead(A0); | |
Serial.print("Flame = "); | |
Serial.print(flame); | |
Serial.print("Smoke = "); | |
Serial.print(smoke); | |
Serial.println(); | |
delay(200); | |
} | |
void loop() { | |
Serial.println("i'm in loop"); | |
sensorData(); | |
pushData(); | |
} | |
// set value | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment