├── ESP8266Firebase.cpp ├── ESP8266Firebase.h ├── LICENSE ├── README.md ├── documentation ├── tutorial_1.png ├── tutorial_2.png ├── tutorial_3.png ├── tutorial_4.png ├── tutorial_5.png └── tutorial_6.png ├── examples ├── FirebaseDemo │ └── FirebaseDemo.ino ├── FirebaseJsonDemo │ └── FirebaseJsonDemo.ino ├── HomeAutomation │ └── HomeAutomation.ino └── RobotController │ └── RobotController.ino ├── keywords.txt └── library.properties /ESP8266Firebase.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | MIT License 3 | 4 | Copyright (c) 2020 Rupak Poddar 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | */ 24 | 25 | #include "ESP8266Firebase.h" 26 | 27 | Firebase::Firebase(String referenceURL) { 28 | _host = referenceURL; 29 | 30 | if (_host.startsWith("https://")) { 31 | _host.remove(0, 8); 32 | } 33 | 34 | if (_host.endsWith("/")) { 35 | _host.remove(_host.length() - 1); 36 | } 37 | 38 | _httpsClient.setInsecure(); 39 | } 40 | 41 | int Firebase::setString(String path, String data) { 42 | Connect_to_host(); 43 | String jsonObject = String("/") + path + String(".json"); 44 | String msg = "\"" + data + "\""; 45 | 46 | _httpsClient.print(String("PUT ") + jsonObject + " HTTP/1.1\r\n" + 47 | "Host: " + _host + "\r\n" + 48 | "Connection: close\r\n" + 49 | "Accept: */*\r\n" + 50 | "User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n" + 51 | "Content-Type: application/json;charset=utf-8\r\n" + 52 | "Content-Length: " + msg.length() + "\r\n" + 53 | "\r\n" + 54 | msg + "\r\n"); 55 | 56 | while (_httpsClient.connected()) { 57 | String line = _httpsClient.readStringUntil('\n'); 58 | if (line == "\r") { 59 | break; 60 | } 61 | } 62 | 63 | String line; 64 | while(_httpsClient.available()) { 65 | line = _httpsClient.readStringUntil('\n'); 66 | if (line.length() > 0) 67 | return 200; // Success 68 | } 69 | 70 | return 400; // Failed 71 | } 72 | 73 | int Firebase::setInt(String path, int data) { 74 | String Data = String(data); 75 | return Firebase::setNum(path, Data); 76 | } 77 | 78 | int Firebase::setFloat(String path, float data) { 79 | String Data = String(data); 80 | return Firebase::setNum(path, Data); 81 | } 82 | 83 | int Firebase::setNum(String path, String msg) { 84 | Connect_to_host(); 85 | String jsonObject = String("/") + path + String(".json"); 86 | 87 | _httpsClient.print(String("PUT ") + jsonObject + " HTTP/1.1\r\n" + 88 | "Host: " + _host + "\r\n" + 89 | "Connection: close\r\n" + 90 | "Accept: */*\r\n" + 91 | "User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n" + 92 | "Content-Type: application/json;charset=utf-8\r\n" + 93 | "Content-Length: " + msg.length() + "\r\n" + 94 | "\r\n" + 95 | msg + "\r\n"); 96 | 97 | while (_httpsClient.connected()) { 98 | String line = _httpsClient.readStringUntil('\n'); 99 | if (line == "\r") { 100 | break; 101 | } 102 | } 103 | 104 | String line; 105 | while(_httpsClient.available()) { 106 | line = _httpsClient.readStringUntil('\n'); 107 | if (line.length() > 0) 108 | return 200; // Success 109 | } 110 | 111 | return 400; // Failed 112 | } 113 | 114 | int Firebase::pushString(String path, String data) { 115 | Connect_to_host(); 116 | String jsonObject = String("/") + path + String(".json"); 117 | 118 | String msg = "\"" + data + "\""; 119 | 120 | _httpsClient.print(String("POST ") + jsonObject + " HTTP/1.1\r\n" + 121 | "Host: " + _host + "\r\n" + 122 | "Connection: close\r\n" + 123 | "Accept: */*\r\n" + 124 | "User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n" + 125 | "Content-Type: application/json;charset=utf-8\r\n" + 126 | "Content-Length: " + msg.length() + "\r\n" + 127 | "\r\n" + 128 | msg + "\r\n"); 129 | 130 | while (_httpsClient.connected()) { 131 | String line = _httpsClient.readStringUntil('\n'); 132 | if (line == "\r") { 133 | break; 134 | } 135 | } 136 | 137 | String line; 138 | while(_httpsClient.available()) { 139 | line = _httpsClient.readStringUntil('\n'); 140 | if (line.length() > 0) 141 | return 200; // Success 142 | } 143 | 144 | return 400; // Failed 145 | } 146 | 147 | int Firebase::pushInt(String path, int data) { 148 | String Data = String(data); 149 | return Firebase::pushNum(path, Data); 150 | } 151 | 152 | int Firebase::pushFloat(String path, float data) { 153 | String Data = String(data); 154 | return Firebase::pushNum(path, Data); 155 | } 156 | 157 | int Firebase::pushNum(String path, String msg) { 158 | Connect_to_host(); 159 | String jsonObject = String("/") + path + String(".json"); 160 | 161 | _httpsClient.print(String("POST ") + jsonObject + " HTTP/1.1\r\n" + 162 | "Host: " + _host + "\r\n" + 163 | "Connection: close\r\n" + 164 | "Accept: */*\r\n" + 165 | "User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n" + 166 | "Content-Type: application/json;charset=utf-8\r\n" + 167 | "Content-Length: " + msg.length() + "\r\n" + 168 | "\r\n" + 169 | msg + "\r\n"); 170 | 171 | while (_httpsClient.connected()) { 172 | String line = _httpsClient.readStringUntil('\n'); 173 | if (line == "\r") { 174 | break; 175 | } 176 | } 177 | 178 | String line; 179 | while(_httpsClient.available()) { 180 | line = _httpsClient.readStringUntil('\n'); 181 | if (line.length() > 0) 182 | return 200; // Success 183 | } 184 | 185 | return 400; // Failed 186 | } 187 | 188 | String Firebase::getString(String path) { 189 | Firebase::getData(path); 190 | return _String; 191 | } 192 | 193 | int Firebase::getInt(String path) { 194 | Firebase::getData(path); 195 | return _int; 196 | } 197 | 198 | float Firebase::getFloat(String path) { 199 | Firebase::getData(path); 200 | return _float; 201 | } 202 | 203 | void Firebase::getData(String path) { 204 | Connect_to_host(); 205 | String jsonObject = String("/") + path + String(".json"); 206 | 207 | _httpsClient.print(String("GET ") + jsonObject + " HTTP/1.1\r\n" + 208 | "Host: " + _host + "\r\n" + 209 | "Connection: close\r\n\r\n"); 210 | 211 | 212 | while (_httpsClient.connected()) { 213 | String line = _httpsClient.readStringUntil('\n'); 214 | if (line == "\r") { 215 | break; 216 | } 217 | } 218 | 219 | String line; 220 | while(_httpsClient.available()) { 221 | line = _httpsClient.readStringUntil('\n'); 222 | _int = line.toInt(); 223 | _float = line.toFloat(); 224 | if (_json == false) 225 | _String = line.substring(1,line.length()-1); 226 | else 227 | _String = line; 228 | } 229 | } 230 | 231 | int Firebase::deleteData(String path) { 232 | Connect_to_host(); 233 | String jsonObject = String("/") + path + String(".json"); 234 | 235 | _httpsClient.print(String("DELETE ") + jsonObject + " HTTP/1.1\r\n" + 236 | "Host: " + _host + "\r\n" + 237 | "Connection: close\r\n\r\n"); 238 | 239 | while (_httpsClient.connected()) { 240 | String line = _httpsClient.readStringUntil('\n'); 241 | if (line == "\r") { 242 | break; 243 | } 244 | } 245 | 246 | String line; 247 | while(_httpsClient.available()) { 248 | line = _httpsClient.readStringUntil('\n'); 249 | if (line.length() > 0) 250 | return 200; // Success 251 | } 252 | 253 | return 400; // Failed 254 | } 255 | 256 | void Firebase::json(bool json) { 257 | _json = json; 258 | } 259 | 260 | void Firebase::Connect_to_host() { 261 | int r=0; 262 | while((!_httpsClient.connect(_host, PORT)) && (r < 30)) { 263 | delay(100); 264 | r++; 265 | } 266 | } 267 | -------------------------------------------------------------------------------- /ESP8266Firebase.h: -------------------------------------------------------------------------------- 1 | /* 2 | MIT License 3 | 4 | Copyright (c) 2020 Rupak Poddar 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | */ 24 | 25 | #ifndef ESP8266Firebase_h 26 | #define ESP8266Firebase_h 27 | #include "Arduino.h" 28 | 29 | #if defined(ESP8266) 30 | #include 31 | #else 32 | #error "Please select an ESP8266 board for this sketch." 33 | #endif 34 | 35 | #define PORT 443 36 | 37 | class Firebase 38 | { 39 | public: 40 | Firebase(String referenceURL); 41 | int setString(String path, String data); 42 | int setNum(String path, String data); 43 | int setInt(String path, int data); 44 | int setFloat(String path, float data); 45 | int pushString(String path, String data); 46 | int pushNum(String path, String data); 47 | int pushInt(String path, int data); 48 | int pushFloat(String path, float data); 49 | void getData(String path); 50 | String getString(String path); 51 | int getInt(String path); 52 | float getFloat(String path); 53 | int deleteData(String path); 54 | void json(bool json); 55 | void Connect_to_host(); 56 | 57 | private: 58 | String _host; 59 | bool _json = false; 60 | String _String; 61 | int _int; 62 | float _float; 63 | WiFiClientSecure _httpsClient; 64 | }; 65 | #endif 66 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Rupak Poddar 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ⚠️ Deprecated Arduino Library 2 | 3 | **This library is no longer maintained and has been officially deprecated.** 4 | 5 | ### Replacement Library 6 | 7 | We highly recommend transitioning to the new and improved Firebase Arduino library, which supports ESP8266, ESP32, Arduino UNO R4 WiFi, and offers more reliability and enhanced functionality. The new library is also fully compatible with the Arduino Cloud IDE. 8 | 9 | - **GitHub Repository:** [Firebase Arduino](https://github.com/Rupakpoddar/FirebaseArduino) 10 | - **Arduino Reference:** [Firebase Arduino](https://www.arduino.cc/reference/en/libraries/firebase/) 11 | 12 | Please update your projects to use the new library to benefit from the latest features and improvements. 13 | 14 | --- 15 | 16 | Thank you for your understanding and support! 17 | -------------------------------------------------------------------------------- /documentation/tutorial_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rupakpoddar/ESP8266Firebase/1a4c11650d6d382cb5ac0dd85e9d000e708ec7be/documentation/tutorial_1.png -------------------------------------------------------------------------------- /documentation/tutorial_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rupakpoddar/ESP8266Firebase/1a4c11650d6d382cb5ac0dd85e9d000e708ec7be/documentation/tutorial_2.png -------------------------------------------------------------------------------- /documentation/tutorial_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rupakpoddar/ESP8266Firebase/1a4c11650d6d382cb5ac0dd85e9d000e708ec7be/documentation/tutorial_3.png -------------------------------------------------------------------------------- /documentation/tutorial_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rupakpoddar/ESP8266Firebase/1a4c11650d6d382cb5ac0dd85e9d000e708ec7be/documentation/tutorial_4.png -------------------------------------------------------------------------------- /documentation/tutorial_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rupakpoddar/ESP8266Firebase/1a4c11650d6d382cb5ac0dd85e9d000e708ec7be/documentation/tutorial_5.png -------------------------------------------------------------------------------- /documentation/tutorial_6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rupakpoddar/ESP8266Firebase/1a4c11650d6d382cb5ac0dd85e9d000e708ec7be/documentation/tutorial_6.png -------------------------------------------------------------------------------- /examples/FirebaseDemo/FirebaseDemo.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Make sure your Firebase project's '.read' and '.write' rules are set to 'true'. 3 | Ignoring this will prevent the MCU from communicating with the database. 4 | For more details- https://github.com/Rupakpoddar/ESP8266Firebase 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | #define _SSID "ENTER HERE" // Your WiFi SSID 11 | #define _PASSWORD "ENTER HERE" // Your WiFi Password 12 | #define REFERENCE_URL "ENTER HERE" // Your Firebase project reference url 13 | 14 | Firebase firebase(REFERENCE_URL); 15 | 16 | void setup() { 17 | Serial.begin(115200); 18 | pinMode(LED_BUILTIN, OUTPUT); 19 | digitalWrite(LED_BUILTIN, LOW); 20 | WiFi.mode(WIFI_STA); 21 | WiFi.disconnect(); 22 | delay(1000); 23 | 24 | // Connect to WiFi 25 | Serial.println(); 26 | Serial.println(); 27 | Serial.print("Connecting to: "); 28 | Serial.println(_SSID); 29 | WiFi.begin(_SSID, _PASSWORD); 30 | 31 | while (WiFi.status() != WL_CONNECTED) { 32 | delay(500); 33 | Serial.print("-"); 34 | } 35 | 36 | Serial.println(""); 37 | Serial.println("WiFi Connected"); 38 | 39 | // Print the IP address 40 | Serial.print("IP Address: "); 41 | Serial.print("http://"); 42 | Serial.print(WiFi.localIP()); 43 | Serial.println("/"); 44 | digitalWrite(LED_BUILTIN, HIGH); 45 | 46 | //================================================================// 47 | //================================================================// 48 | 49 | // Examples of setting String, integer and float values. 50 | firebase.setString("Example/setString", "It's Working"); 51 | firebase.setInt("Example/setInt", 123); 52 | firebase.setFloat("Example/setFloat", 45.32); 53 | 54 | // Examples of pushing String, integer and float values. 55 | firebase.pushString("push", "Hello"); 56 | firebase.pushInt("push", 789); 57 | firebase.pushFloat("push", 89.54); 58 | 59 | // Example of getting a String. 60 | String data1 = firebase.getString("Example/setString"); 61 | Serial.print("Received String:\t"); 62 | Serial.println(data1); 63 | 64 | // Example of getting an int. 65 | int data2 = firebase.getInt("Example/setInt"); 66 | Serial.print("Received Int:\t\t"); 67 | Serial.println(data2); 68 | 69 | // Example of getting a float. 70 | float data3 = firebase.getFloat("Example/setFloat"); 71 | Serial.print("Received Float:\t\t"); 72 | Serial.println(data3); 73 | 74 | // Example of data deletion. 75 | firebase.deleteData("Example"); 76 | } 77 | 78 | void loop() { 79 | // Nothing 80 | } 81 | -------------------------------------------------------------------------------- /examples/FirebaseJsonDemo/FirebaseJsonDemo.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Make sure your Firebase project's '.read' and '.write' rules are set to 'true'. 3 | Ignoring this will prevent the MCU from communicating with the database. 4 | For more details- https://github.com/Rupakpoddar/ESP8266Firebase 5 | */ 6 | 7 | #include // https://github.com/bblanchon/ArduinoJson 8 | #include 9 | #include 10 | 11 | #define _SSID "ENTER HERE" // Your WiFi SSID 12 | #define _PASSWORD "ENTER HERE" // Your WiFi Password 13 | #define REFERENCE_URL "ENTER HERE" // Your Firebase project reference url 14 | 15 | Firebase firebase(REFERENCE_URL); 16 | 17 | void setup() { 18 | Serial.begin(115200); 19 | pinMode(LED_BUILTIN, OUTPUT); 20 | digitalWrite(LED_BUILTIN, LOW); 21 | WiFi.mode(WIFI_STA); 22 | WiFi.disconnect(); 23 | delay(1000); 24 | 25 | // Connect to WiFi 26 | Serial.println(); 27 | Serial.println(); 28 | Serial.print("Connecting to: "); 29 | Serial.println(_SSID); 30 | WiFi.begin(_SSID, _PASSWORD); 31 | 32 | while (WiFi.status() != WL_CONNECTED) { 33 | delay(500); 34 | Serial.print("-"); 35 | } 36 | 37 | Serial.println(""); 38 | Serial.println("WiFi Connected"); 39 | 40 | // Print the IP address 41 | Serial.print("IP Address: "); 42 | Serial.print("http://"); 43 | Serial.print(WiFi.localIP()); 44 | Serial.println("/"); 45 | digitalWrite(LED_BUILTIN, HIGH); 46 | 47 | //================================================================// 48 | //================================================================// 49 | 50 | // Write some data to the realtime database. 51 | firebase.setString("Example/setString", "It's Working"); 52 | firebase.setInt("Example/setInt", 123); 53 | firebase.setFloat("Example/setFloat", 45.32); 54 | 55 | firebase.json(true); // Make sure to add this line. 56 | 57 | String data = firebase.getString("Example"); // Get data from the database. 58 | 59 | // Deserialize the data. 60 | // Consider using Arduino Json Assistant- https://arduinojson.org/v6/assistant/ 61 | const size_t capacity = JSON_OBJECT_SIZE(3) + 50; 62 | DynamicJsonDocument doc(capacity); 63 | 64 | deserializeJson(doc, data); 65 | 66 | // Store the deserialized data. 67 | const char* received_String = doc["setString"]; // "It's Working" 68 | int received_int = doc["setInt"]; // 123 69 | float received_float = doc["setFloat"]; // 45.32 70 | 71 | // Print data 72 | Serial.print("Received String:\t"); 73 | Serial.println(received_String); 74 | 75 | Serial.print("Received Int:\t\t"); 76 | Serial.println(received_int); 77 | 78 | Serial.print("Received Float:\t\t"); 79 | Serial.println(received_float); 80 | 81 | // Delete data from the realtime database. 82 | firebase.deleteData("Example"); 83 | } 84 | 85 | void loop() { 86 | // Nothing 87 | } 88 | -------------------------------------------------------------------------------- /examples/HomeAutomation/HomeAutomation.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Make sure your Firebase project's '.read' and '.write' rules are set to 'true'. 3 | Ignoring this will prevent the MCU from communicating with the database. 4 | For more details- https://github.com/Rupakpoddar/ESP8266Firebase 5 | 6 | Download the Android app from- https://play.google.com/store/apps/details?id=com.rupak.firebaseremote 7 | Online remote (Works with any web browser)- https://rupakpoddar.github.io/Firebase-automation-web-interface/ 8 | Use Python to control devices- https://github.com/Rupakpoddar/Firebase-with-python 9 | */ 10 | 11 | #include // https://github.com/bblanchon/ArduinoJson 12 | #include 13 | #include 14 | 15 | #define _SSID "ENTER HERE" // Your WiFi SSID 16 | #define _PASSWORD "ENTER HERE" // Your WiFi Password 17 | #define REFERENCE_URL "ENTER HERE" // Your Firebase project reference url 18 | 19 | #define device1 5 // D1 20 | #define device2 4 // D2 21 | #define device3 0 // D3 22 | #define device4 14 // D5 23 | int device_list[4] = {device1, device2, device3, device4}; 24 | 25 | Firebase firebase(REFERENCE_URL); 26 | 27 | void setup() { 28 | Serial.begin(115200); 29 | pinMode(device1, OUTPUT); 30 | pinMode(device2, OUTPUT); 31 | pinMode(device3, OUTPUT); 32 | pinMode(device4, OUTPUT); 33 | pinMode(LED_BUILTIN, OUTPUT); 34 | digitalWrite(LED_BUILTIN, LOW); 35 | WiFi.mode(WIFI_STA); 36 | WiFi.disconnect(); 37 | delay(1000); 38 | 39 | // Connect to WiFi 40 | Serial.println(); 41 | Serial.println(); 42 | Serial.print("Connecting to: "); 43 | Serial.println(_SSID); 44 | WiFi.begin(_SSID, _PASSWORD); 45 | 46 | while (WiFi.status() != WL_CONNECTED) { 47 | delay(500); 48 | Serial.print("-"); 49 | } 50 | 51 | Serial.println(""); 52 | Serial.println("WiFi Connected"); 53 | 54 | // Print the IP address 55 | Serial.print("IP Address: "); 56 | Serial.print("http://"); 57 | Serial.print(WiFi.localIP()); 58 | Serial.println("/"); 59 | digitalWrite(LED_BUILTIN, HIGH); 60 | 61 | firebase.json(true); // Make sure to add this line. 62 | } 63 | 64 | void loop() { 65 | String data = firebase.getString("cmd"); // Get data from database. 66 | 67 | // Deserialize the data. 68 | // Consider using the Arduino Json assistant- https://arduinojson.org/v6/assistant/ 69 | const size_t capacity = JSON_OBJECT_SIZE(5) + 60; 70 | DynamicJsonDocument doc(capacity); 71 | 72 | deserializeJson(doc, data); 73 | 74 | String Device1 = doc["Device1"]; 75 | String Device2 = doc["Device2"]; 76 | String Device3 = doc["Device3"]; 77 | String Device4 = doc["Device4"]; 78 | 79 | // Print data 80 | Serial.println("Device 1: "+Device1); 81 | Serial.println("Device 2: "+Device2); 82 | Serial.println("Device 3: "+Device3); 83 | Serial.println("Device 4: "+Device4); 84 | Serial.println(""); 85 | 86 | String status_list[4] = {Device1, Device2, Device3, Device4}; 87 | 88 | for (int i=0;i<4;i++) { 89 | if (status_list[i] == "ON"){ 90 | digitalWrite(device_list[i], HIGH); 91 | } 92 | else{ 93 | digitalWrite(device_list[i], LOW); 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /examples/RobotController/RobotController.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Make sure your Firebase project's '.read' and '.write' rules are set to 'true'. 3 | Ignoring this will prevent the MCU from communicating with the database. 4 | For more details- https://github.com/Rupakpoddar/ESP8266Firebase 5 | 6 | Download the Android app from- https://play.google.com/store/apps/details?id=com.rupak.firebaseremote 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | #define _SSID "ENTER HERE" // Your WiFi SSID 13 | #define _PASSWORD "ENTER HERE" // Your WiFi Password 14 | #define REFERENCE_URL "ENTER HERE" // Your Firebase project reference url 15 | 16 | #define M1A 5 // D1: Output 1 for motor driver 17 | #define M1B 4 // D2: Output 2 for motor driver 18 | #define M2A 0 // D3: Output 3 for motor driver 19 | #define M2B 14 // D5: Output 4 for motor driver 20 | 21 | #define TURN_DELAY 100 22 | #define FORWARD_BACKWARD_DELAY 500 23 | 24 | Firebase firebase(REFERENCE_URL); 25 | 26 | void setup() { 27 | Serial.begin(115200); 28 | pinMode(M1A, OUTPUT); 29 | pinMode(M1B, OUTPUT); 30 | pinMode(M2A, OUTPUT); 31 | pinMode(M2B, OUTPUT); 32 | 33 | digitalWrite(M1A, LOW); 34 | digitalWrite(M1B, LOW); 35 | digitalWrite(M2A, LOW); 36 | digitalWrite(M2B, LOW); 37 | 38 | pinMode(LED_BUILTIN, OUTPUT); 39 | digitalWrite(LED_BUILTIN, LOW); 40 | WiFi.mode(WIFI_STA); 41 | WiFi.disconnect(); 42 | delay(1000); 43 | 44 | // Connect to WiFi 45 | Serial.println(); 46 | Serial.println(); 47 | Serial.print("Connecting to: "); 48 | Serial.println(_SSID); 49 | WiFi.begin(_SSID, _PASSWORD); 50 | 51 | while (WiFi.status() != WL_CONNECTED) { 52 | delay(500); 53 | Serial.print("-"); 54 | } 55 | 56 | Serial.println(""); 57 | Serial.println("WiFi Connected"); 58 | 59 | // Print the IP address 60 | Serial.print("IP Address: "); 61 | Serial.print("http://"); 62 | Serial.print(WiFi.localIP()); 63 | Serial.println("/"); 64 | digitalWrite(LED_BUILTIN, HIGH); 65 | } 66 | 67 | void loop() { 68 | int command = firebase.getInt("cmd/Robot"); // Get data from database. 69 | 70 | if(command == 0){ // STOP 71 | digitalWrite(M1A, LOW); 72 | digitalWrite(M1B, LOW); 73 | digitalWrite(M2A, LOW); 74 | digitalWrite(M2B, LOW); 75 | } 76 | 77 | if(command == 1){ // FORWARD 78 | digitalWrite(M1A, HIGH); 79 | digitalWrite(M2A, HIGH); 80 | delay(FORWARD_BACKWARD_DELAY); 81 | digitalWrite(M1A, LOW); 82 | digitalWrite(M2A, LOW); 83 | } 84 | 85 | if(command == 2){ // BACKWARD 86 | digitalWrite(M1B, HIGH); 87 | digitalWrite(M2B, HIGH); 88 | delay(FORWARD_BACKWARD_DELAY); 89 | digitalWrite(M1B, LOW); 90 | digitalWrite(M2B, LOW); 91 | } 92 | 93 | if(command == 3){ // LEFT 94 | digitalWrite(M1B, HIGH); 95 | digitalWrite(M2A, HIGH); 96 | delay(TURN_DELAY); 97 | digitalWrite(M1B, LOW); 98 | digitalWrite(M2A, LOW); 99 | } 100 | 101 | if(command == 4){ // RIGHT 102 | digitalWrite(M1A, HIGH); 103 | digitalWrite(M2B, HIGH); 104 | delay(TURN_DELAY); 105 | digitalWrite(M1A, LOW); 106 | digitalWrite(M2B, LOW); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | Firebase KEYWORD1 2 | 3 | setString KEYWORD2 4 | setInt KEYWORD2 5 | setFloat KEYWORD2 6 | 7 | pushString KEYWORD2 8 | pushInt KEYWORD2 9 | pushFloat KEYWORD2 10 | 11 | getString KEYWORD2 12 | getInt KEYWORD2 13 | getFloat KEYWORD2 14 | 15 | deleteData KEYWORD2 16 | json KEYWORD2 -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=ESP8266 Firebase 2 | version=1.3.1 3 | author=Rupak Poddar 4 | maintainer=Rupak Poddar 5 | sentence=Library for ESP8266 to read and write data to Firebase Realtime Database. 6 | paragraph=A reliable low latency library to read, write, update and delete data from Firebase Realtime Database. 7 | category=Communication 8 | url=https://github.com/Rupakpoddar/ESP8266Firebase 9 | architectures=esp8266 10 | --------------------------------------------------------------------------------