Created
April 7, 2019 18:02
-
-
Save jibin2706/832a0c5ad9e6639a3582cbf0a4b39f26 to your computer and use it in GitHub Desktop.
Sample code for using Firebase database with NodeMCU
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> | |
// Firebase | |
#define FIREBASE_HOST "yourfirebasedatabase.firebaseio.com" | |
#define FIREBASE_AUTH "*****" | |
// Wifi | |
#define WIFI_SSID "your_wifi_ssid" | |
#define WIFI_PASSWORD "your_wifi_password" | |
const int led = D1; | |
void setup() | |
{ | |
Serial.begin(115200); | |
pinMode(led, OUTPUT); | |
// connect to wifi. | |
WiFi.begin(WIFI_SSID, WIFI_PASSWORD); | |
Serial.println("connecting..."); | |
while (WiFi.status() != WL_CONNECTED) | |
{ | |
Serial.println("."); | |
delay(3000); | |
} | |
Serial.println(WiFi.localIP()); | |
// Setting up connection to firebase | |
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH); | |
} | |
void loop() | |
{ | |
bool isLedOn = Firebase.getBool("/led"); | |
if (isLedOn) { | |
digitalWrite(led, HIGH); | |
} | |
else { | |
digitalWrite(led, LOW); | |
} | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment