/********* Pleasedontcode.com **********
Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- Terms and Conditions:
You have a non-exclusive, revocable, worldwide, royalty-free license
for personal and commercial use. Attribution is optional; modifications
are allowed, but you're responsible for code maintenance. We're not
liable for any loss or damage. For full terms,
please visit pleasedontcode.com/termsandconditions.
- Project: "Wi-Fi Sync"
- Source Code NOT compiled for: ESP32 DevKit V1
- Source Code created on: 2024-06-11 15:53:49
********* Pleasedontcode.com **********/
/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
/* Develop ESP32 code for LED blinking patterns on */
/* two ESP32 devices using GPIO pins 23, 22, 21, and */
/* 19 for Yellow, Red, Green and Blue LEDs with pre- */
/* programmed delays. Integrate Firebase for web */
/* hosting, authentication, and real-time database. */
/****** SYSTEM REQUIREMENT 2 *****/
/* Firebase authentication to both esp32 devices and */
/* logins are not hardcoded but authenticated by */
/* firebase. user UIDs are stored in Firebase user */
/* can register email/password for login or use */
/* google login. */
/****** END SYSTEM REQUIREMENTS *****/
/****** DEFINITION OF LIBRARIES *****/
#include
#include //https://github.com/mobizt/Firebase-ESP32
#include // Include the token helper header
#include // Include the RTDB helper header
/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
void updateOutputs(void);
void blinkLEDs(void);
/***** DEFINITION OF DIGITAL OUTPUT PINS *****/
const uint8_t GPIO23_LED_PIN_D4 = 23;
const uint8_t GPIO22_LED_PIN_D13 = 22;
const uint8_t GPIO21_LED_PIN_D14 = 21;
const uint8_t GPIO19_LED_PIN_D16 = 19;
/***** DEFINITION OF OUTPUT RAW VARIABLES *****/
/***** used to store raw data *****/
bool GPIO23_LED_PIN_D4_rawData = 0;
bool GPIO22_LED_PIN_D13_rawData = 0;
bool GPIO21_LED_PIN_D14_rawData = 0;
bool GPIO19_LED_PIN_D16_rawData = 0;
/***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
/***** used to store data after characteristic curve transformation *****/
float GPIO23_LED_PIN_D4_phyData = 0.0;
float GPIO22_LED_PIN_D13_phyData = 0.0;
float GPIO21_LED_PIN_D14_phyData = 0.0;
float GPIO19_LED_PIN_D16_phyData = 0.0;
/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
FirebaseData fbdo;
FirebaseAuth auth;
FirebaseConfig config;
/* WiFi credentials */
#define WIFI_SSID "WIFI_AP"
#define WIFI_PASSWORD "WIFI_PASSWORD"
/* Firebase project API Key */
#define API_KEY "API_KEY"
/* Firebase Realtime Database URL */
#define DATABASE_URL "URL" //.firebaseio.com or ..firebasedatabase.app
/* Firebase user Email and password */
#define USER_EMAIL "USER_EMAIL"
#define USER_PASSWORD "USER_PASSWORD"
unsigned long previousMillis = 0; // will store last time LED was updated
const long interval = 1000; // interval at which to blink (milliseconds)
void setup(void)
{
// Initialize serial communication
Serial.begin(115200);
// Initialize GPIO pins as outputs
pinMode(GPIO23_LED_PIN_D4, OUTPUT);
pinMode(GPIO22_LED_PIN_D13, OUTPUT);
pinMode(GPIO21_LED_PIN_D14, OUTPUT);
pinMode(GPIO19_LED_PIN_D16, OUTPUT);
// Connect to Wi-Fi
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());
// Configure Firebase
config.api_key = API_KEY;
auth.user.email = USER_EMAIL;
auth.user.password = USER_PASSWORD;
config.database_url = DATABASE_URL;
// Enable automatic reconnect to Wi-Fi
Firebase.reconnectWiFi(true);
fbdo.setResponseSize(4096);
config.token_status_callback = tokenStatusCallback; // see addons/TokenHelper.h
Firebase.begin(&config, &auth);
}
void loop(void)
{
// Refresh output data
updateOutputs();
// Blink LEDs based on interval
blinkLEDs();
}
void updateOutputs()
{
// Update the state of the LEDs
digitalWrite(GPIO23_LED_PIN_D4, GPIO23_LED_PIN_D4_rawData);
digitalWrite(GPIO22_LED_PIN_D13, GPIO22_LED_PIN_D13_rawData);
digitalWrite(GPIO21_LED_PIN_D14, GPIO21_LED_PIN_D14_rawData);
digitalWrite(GPIO19_LED_PIN_D16, GPIO19_LED_PIN_D16_rawData);
}
void blinkLEDs()
{
unsigned long currentMillis = millis();
// Check if the interval has passed
if (currentMillis - previousMillis >= interval)
{
// Save the last time the LEDs were updated
previousMillis = currentMillis;
// Toggle the state of the LEDs
GPIO23_LED_PIN_D4_rawData = !GPIO23_LED_PIN_D4_rawData;
GPIO22_LED_PIN_D13_rawData = !GPIO22_LED_PIN_D13_rawData;
GPIO21_LED_PIN_D14_rawData = !GPIO21_LED_PIN_D14_rawData;
GPIO19_LED_PIN_D16_rawData = !GPIO19_LED_PIN_D16_rawData;
}
}
/* END CODE */