first commit
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
Make sure your Firebase project's '.read' and '.write' rules are set to 'true'.
|
||||
Ignoring this will prevent the MCU from communicating with the database.
|
||||
For more details- https://github.com/Rupakpoddar/ESP32Firebase
|
||||
*/
|
||||
|
||||
#include <ESP32Firebase.h>
|
||||
|
||||
#define _SSID "ENTER HERE" // Your WiFi SSID
|
||||
#define _PASSWORD "ENTER HERE" // Your WiFi Password
|
||||
#define REFERENCE_URL "ENTER HERE" // Your Firebase project reference url
|
||||
|
||||
Firebase firebase(REFERENCE_URL);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
// pinMode(LED_BUILTIN, OUTPUT);
|
||||
// digitalWrite(LED_BUILTIN, LOW);
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.disconnect();
|
||||
delay(1000);
|
||||
|
||||
// Connect to WiFi
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
Serial.print("Connecting to: ");
|
||||
Serial.println(_SSID);
|
||||
WiFi.begin(_SSID, _PASSWORD);
|
||||
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(500);
|
||||
Serial.print("-");
|
||||
}
|
||||
|
||||
Serial.println("");
|
||||
Serial.println("WiFi Connected");
|
||||
|
||||
// Print the IP address
|
||||
Serial.print("IP Address: ");
|
||||
Serial.print("http://");
|
||||
Serial.print(WiFi.localIP());
|
||||
Serial.println("/");
|
||||
// digitalWrite(LED_BUILTIN, HIGH);
|
||||
|
||||
//================================================================//
|
||||
//================================================================//
|
||||
|
||||
// Examples of setting String, integer and float values.
|
||||
firebase.setString("Example/setString", "It's Working");
|
||||
firebase.setInt("Example/setInt", 123);
|
||||
firebase.setFloat("Example/setFloat", 45.32);
|
||||
|
||||
// Examples of pushing String, integer and float values.
|
||||
firebase.pushString("push", "Hello");
|
||||
firebase.pushInt("push", 789);
|
||||
firebase.pushFloat("push", 89.54);
|
||||
|
||||
// Example of getting a String.
|
||||
String data1 = firebase.getString("Example/setString");
|
||||
Serial.print("Received String:\t");
|
||||
Serial.println(data1);
|
||||
|
||||
// Example of getting an int.
|
||||
int data2 = firebase.getInt("Example/setInt");
|
||||
Serial.print("Received Int:\t\t");
|
||||
Serial.println(data2);
|
||||
|
||||
// Example of getting a float.
|
||||
float data3 = firebase.getFloat("Example/setFloat");
|
||||
Serial.print("Received Float:\t\t");
|
||||
Serial.println(data3);
|
||||
|
||||
// Example of data deletion.
|
||||
firebase.deleteData("Example");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Nothing
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
Make sure your Firebase project's '.read' and '.write' rules are set to 'true'.
|
||||
Ignoring this will prevent the MCU from communicating with the database.
|
||||
For more details- https://github.com/Rupakpoddar/ESP32Firebase
|
||||
*/
|
||||
|
||||
#include <ArduinoJson.h> // https://github.com/bblanchon/ArduinoJson
|
||||
#include <ESP32Firebase.h>
|
||||
|
||||
#define _SSID "ENTER HERE" // Your WiFi SSID
|
||||
#define _PASSWORD "ENTER HERE" // Your WiFi Password
|
||||
#define REFERENCE_URL "ENTER HERE" // Your Firebase project reference url
|
||||
|
||||
Firebase firebase(REFERENCE_URL);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
// pinMode(LED_BUILTIN, OUTPUT);
|
||||
// digitalWrite(LED_BUILTIN, LOW);
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.disconnect();
|
||||
delay(1000);
|
||||
|
||||
// Connect to WiFi
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
Serial.print("Connecting to: ");
|
||||
Serial.println(_SSID);
|
||||
WiFi.begin(_SSID, _PASSWORD);
|
||||
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(500);
|
||||
Serial.print("-");
|
||||
}
|
||||
|
||||
Serial.println("");
|
||||
Serial.println("WiFi Connected");
|
||||
|
||||
// Print the IP address
|
||||
Serial.print("IP Address: ");
|
||||
Serial.print("http://");
|
||||
Serial.print(WiFi.localIP());
|
||||
Serial.println("/");
|
||||
// digitalWrite(LED_BUILTIN, HIGH);
|
||||
|
||||
//================================================================//
|
||||
//================================================================//
|
||||
|
||||
// Write some data to the realtime database.
|
||||
firebase.setString("Example/setString", "It's Working");
|
||||
firebase.setInt("Example/setInt", 123);
|
||||
firebase.setFloat("Example/setFloat", 45.32);
|
||||
|
||||
firebase.json(true); // Make sure to add this line.
|
||||
|
||||
String data = firebase.getString("Example"); // Get data from the database.
|
||||
|
||||
// Deserialize the data.
|
||||
// Consider using Arduino Json Assistant- https://arduinojson.org/v6/assistant/
|
||||
const size_t capacity = JSON_OBJECT_SIZE(3) + 50;
|
||||
DynamicJsonDocument doc(capacity);
|
||||
|
||||
deserializeJson(doc, data);
|
||||
|
||||
// Store the deserialized data.
|
||||
const char* received_String = doc["setString"]; // "It's Working"
|
||||
int received_int = doc["setInt"]; // 123
|
||||
float received_float = doc["setFloat"]; // 45.32
|
||||
|
||||
// Print data
|
||||
Serial.print("Received String:\t");
|
||||
Serial.println(received_String);
|
||||
|
||||
Serial.print("Received Int:\t\t");
|
||||
Serial.println(received_int);
|
||||
|
||||
Serial.print("Received Float:\t\t");
|
||||
Serial.println(received_float);
|
||||
|
||||
// Delete data from the realtime database.
|
||||
firebase.deleteData("Example");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Nothing
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
Make sure your Firebase project's '.read' and '.write' rules are set to 'true'.
|
||||
Ignoring this will prevent the MCU from communicating with the database.
|
||||
For more details- https://github.com/Rupakpoddar/ESP32Firebase
|
||||
|
||||
Download the Android app from- https://play.google.com/store/apps/details?id=com.rupak.firebaseremote
|
||||
Online remote (Works with any web browser)- https://rupakpoddar.github.io/Firebase-automation-web-interface/
|
||||
Use Python to control devices- https://github.com/Rupakpoddar/Firebase-with-python
|
||||
*/
|
||||
|
||||
#include <ArduinoJson.h> // https://github.com/bblanchon/ArduinoJson
|
||||
#include <ESP32Firebase.h>
|
||||
|
||||
#define _SSID "ENTER HERE" // Your WiFi SSID
|
||||
#define _PASSWORD "ENTER HERE" // Your WiFi Password
|
||||
#define REFERENCE_URL "ENTER HERE" // Your Firebase project reference url
|
||||
|
||||
#define device1 3 // D5
|
||||
#define device2 4 // D6
|
||||
#define device3 5 // D7
|
||||
#define device4 6 // D8
|
||||
int device_list[4] = {device1, device2, device3, device4};
|
||||
|
||||
Firebase firebase(REFERENCE_URL);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
pinMode(device1, OUTPUT);
|
||||
pinMode(device2, OUTPUT);
|
||||
pinMode(device3, OUTPUT);
|
||||
pinMode(device4, OUTPUT);
|
||||
// pinMode(LED_BUILTIN, OUTPUT);
|
||||
// digitalWrite(LED_BUILTIN, LOW);
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.disconnect();
|
||||
delay(1000);
|
||||
|
||||
// Connect to WiFi
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
Serial.print("Connecting to: ");
|
||||
Serial.println(_SSID);
|
||||
WiFi.begin(_SSID, _PASSWORD);
|
||||
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(500);
|
||||
Serial.print("-");
|
||||
}
|
||||
|
||||
Serial.println("");
|
||||
Serial.println("WiFi Connected");
|
||||
|
||||
// Print the IP address
|
||||
Serial.print("IP Address: ");
|
||||
Serial.print("http://");
|
||||
Serial.print(WiFi.localIP());
|
||||
Serial.println("/");
|
||||
// digitalWrite(LED_BUILTIN, HIGH);
|
||||
|
||||
firebase.json(true); // Make sure to add this line.
|
||||
}
|
||||
|
||||
void loop() {
|
||||
String data = firebase.getString("cmd"); // Get data from database.
|
||||
|
||||
// Deserialize the data.
|
||||
// Consider using the Arduino Json assistant- https://arduinojson.org/v6/assistant/
|
||||
const size_t capacity = JSON_OBJECT_SIZE(5) + 60;
|
||||
DynamicJsonDocument doc(capacity);
|
||||
|
||||
deserializeJson(doc, data);
|
||||
|
||||
String Device1 = doc["Device1"];
|
||||
String Device2 = doc["Device2"];
|
||||
String Device3 = doc["Device3"];
|
||||
String Device4 = doc["Device4"];
|
||||
|
||||
// Print data
|
||||
Serial.println("Device 1: "+Device1);
|
||||
Serial.println("Device 2: "+Device2);
|
||||
Serial.println("Device 3: "+Device3);
|
||||
Serial.println("Device 4: "+Device4);
|
||||
Serial.println("");
|
||||
|
||||
String status_list[4] = {Device1, Device2, Device3, Device4};
|
||||
|
||||
for (int i=0;i<4;i++) {
|
||||
if (status_list[i] == "ON"){
|
||||
digitalWrite(device_list[i], HIGH);
|
||||
}
|
||||
else{
|
||||
digitalWrite(device_list[i], LOW);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
Make sure your Firebase project's '.read' and '.write' rules are set to 'true'.
|
||||
Ignoring this will prevent the MCU from communicating with the database.
|
||||
For more details- https://github.com/Rupakpoddar/ESP32Firebase
|
||||
|
||||
Download the Android app from- https://play.google.com/store/apps/details?id=com.rupak.firebaseremote
|
||||
*/
|
||||
|
||||
#include <ESP32Firebase.h>
|
||||
|
||||
#define _SSID "ENTER HERE" // Your WiFi SSID
|
||||
#define _PASSWORD "ENTER HERE" // Your WiFi Password
|
||||
#define REFERENCE_URL "ENTER HERE" // Your Firebase project reference url
|
||||
|
||||
#define M1A 3 // D5: Output 1 for motor driver
|
||||
#define M1B 4 // D6: Output 2 for motor driver
|
||||
#define M2A 5 // D7: Output 3 for motor driver
|
||||
#define M2B 6 // D8: Output 4 for motor driver
|
||||
|
||||
#define TURN_DELAY 100
|
||||
#define FORWARD_BACKWARD_DELAY 500
|
||||
|
||||
Firebase firebase(REFERENCE_URL);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
pinMode(M1A, OUTPUT);
|
||||
pinMode(M1B, OUTPUT);
|
||||
pinMode(M2A, OUTPUT);
|
||||
pinMode(M2B, OUTPUT);
|
||||
|
||||
digitalWrite(M1A, LOW);
|
||||
digitalWrite(M1B, LOW);
|
||||
digitalWrite(M2A, LOW);
|
||||
digitalWrite(M2B, LOW);
|
||||
|
||||
// pinMode(LED_BUILTIN, OUTPUT);
|
||||
// digitalWrite(LED_BUILTIN, LOW);
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.disconnect();
|
||||
delay(1000);
|
||||
|
||||
// Connect to WiFi
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
Serial.print("Connecting to: ");
|
||||
Serial.println(_SSID);
|
||||
WiFi.begin(_SSID, _PASSWORD);
|
||||
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(500);
|
||||
Serial.print("-");
|
||||
}
|
||||
|
||||
Serial.println("");
|
||||
Serial.println("WiFi Connected");
|
||||
|
||||
// Print the IP address
|
||||
Serial.print("IP Address: ");
|
||||
Serial.print("http://");
|
||||
Serial.print(WiFi.localIP());
|
||||
Serial.println("/");
|
||||
// digitalWrite(LED_BUILTIN, HIGH);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
int command = firebase.getInt("cmd/Robot"); // Get data from database.
|
||||
|
||||
if(command == 0){ // STOP
|
||||
digitalWrite(M1A, LOW);
|
||||
digitalWrite(M1B, LOW);
|
||||
digitalWrite(M2A, LOW);
|
||||
digitalWrite(M2B, LOW);
|
||||
}
|
||||
|
||||
if(command == 1){ // FORWARD
|
||||
digitalWrite(M1A, HIGH);
|
||||
digitalWrite(M2A, HIGH);
|
||||
delay(FORWARD_BACKWARD_DELAY);
|
||||
digitalWrite(M1A, LOW);
|
||||
digitalWrite(M2A, LOW);
|
||||
}
|
||||
|
||||
if(command == 2){ // BACKWARD
|
||||
digitalWrite(M1B, HIGH);
|
||||
digitalWrite(M2B, HIGH);
|
||||
delay(FORWARD_BACKWARD_DELAY);
|
||||
digitalWrite(M1B, LOW);
|
||||
digitalWrite(M2B, LOW);
|
||||
}
|
||||
|
||||
if(command == 3){ // LEFT
|
||||
digitalWrite(M1B, HIGH);
|
||||
digitalWrite(M2A, HIGH);
|
||||
delay(TURN_DELAY);
|
||||
digitalWrite(M1B, LOW);
|
||||
digitalWrite(M2A, LOW);
|
||||
}
|
||||
|
||||
if(command == 4){ // RIGHT
|
||||
digitalWrite(M1A, HIGH);
|
||||
digitalWrite(M2B, HIGH);
|
||||
delay(TURN_DELAY);
|
||||
digitalWrite(M1A, LOW);
|
||||
digitalWrite(M2B, LOW);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user