Fix bug trop de log (SSL error)
This commit is contained in:
parent
719ff30199
commit
f98e33b06c
@ -1,62 +1,61 @@
|
||||
#include <Arduino.h>
|
||||
#include <WiFi.h>
|
||||
#include <Firebase_ESP_Client.h>
|
||||
#include <ctrlLed.h>
|
||||
#include <ctrlSpeaker.h>
|
||||
#include <ctrlRfid.h>
|
||||
#include <branchements.h>
|
||||
#include <NTPClient.h>
|
||||
#include <Arduino.h>
|
||||
#include <WiFi.h>
|
||||
#include <Firebase_ESP_Client.h>
|
||||
#include <ctrlLed.h>
|
||||
#include <ctrlSpeaker.h>
|
||||
#include <ctrlRfid.h>
|
||||
#include <branchements.h>
|
||||
#include <NTPClient.h>
|
||||
|
||||
// WiFi Configuration
|
||||
#define WIFI_SSID "ratio"
|
||||
#define WIFI_PASSWORD "123456789"
|
||||
// WiFi Configuration
|
||||
#define WIFI_SSID "ratio"
|
||||
#define WIFI_PASSWORD "123456789"
|
||||
|
||||
// Firebase Configuration
|
||||
#define API_KEY "AIzaSyB8qf7aeI7F5l7d1NDhRQrNNLW8aPaOkl4"
|
||||
#define DATABASE_URL "https://alarmeesp32-2ca19-default-rtdb.europe-west1.firebasedatabase.app"
|
||||
#define USER_EMAIL "alarm@alarm.bip"
|
||||
#define USER_PASSWORD "123456"
|
||||
#define FIREBASE_USE_PSRAM
|
||||
// Firebase Configuration
|
||||
#define API_KEY "AIzaSyB8qf7aeI7F5l7d1NDhRQrNNLW8aPaOkl4"
|
||||
#define DATABASE_URL "https://alarmeesp32-2ca19-default-rtdb.europe-west1.firebasedatabase.app"
|
||||
#define USER_EMAIL "alarm@alarm.bip"
|
||||
#define USER_PASSWORD "123456"
|
||||
#define FIREBASE_USE_PSRAM
|
||||
|
||||
// Déclaration Firebase
|
||||
FirebaseData fbdo, stream;
|
||||
FirebaseAuth auth;
|
||||
FirebaseConfig config;
|
||||
// Déclaration Firebase
|
||||
FirebaseData fbdo, stream;
|
||||
FirebaseAuth auth;
|
||||
FirebaseConfig config;
|
||||
|
||||
// Variables Alarme
|
||||
volatile bool motionDetected = false;
|
||||
bool armed = false, triggered = false;
|
||||
// Variables Alarme
|
||||
volatile bool motionDetected = false;
|
||||
bool armed = false, triggered = false;
|
||||
|
||||
// NTP pour la gestion des logs
|
||||
WiFiUDP ntpUDP;
|
||||
NTPClient timeClient(ntpUDP, "pool.ntp.org");
|
||||
// NTP pour la gestion des logs
|
||||
WiFiUDP ntpUDP;
|
||||
NTPClient timeClient(ntpUDP, "pool.ntp.org");
|
||||
|
||||
// Gestion de l'alarme
|
||||
void IRAM_ATTR onMotionDetected() {
|
||||
// Gestion de l'alarme
|
||||
void IRAM_ATTR onMotionDetected() {
|
||||
motionDetected = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Ajout de logs Firebase
|
||||
void addLog(const char* messageLog) {
|
||||
FirebaseJson logData;
|
||||
// Ajout de logs Firebase (sans récupérer les données)
|
||||
void addLog(const char* messageLog) {
|
||||
timeClient.update();
|
||||
char timestampISO[25];
|
||||
time_t epochTime = timeClient.getEpochTime();
|
||||
strftime(timestampISO, sizeof(timestampISO), "%Y-%m-%dT%H:%M:%SZ", gmtime(&epochTime));
|
||||
|
||||
FirebaseJson logData;
|
||||
logData.add("timestamp", timestampISO);
|
||||
logData.add("sender", "ALARM");
|
||||
logData.add("message", messageLog);
|
||||
|
||||
if (!Firebase.RTDB.pushJSON(&fbdo, "/Alarm/logs", &logData)) {
|
||||
Serial.println("❌ Erreur ajout log Firebase : " + fbdo.errorReason());
|
||||
// Pousser les logs sans vérifier la réponse pour économiser la mémoire
|
||||
Firebase.RTDB.pushJSON(&fbdo, "/Alarm/logs", &logData);
|
||||
}
|
||||
}
|
||||
|
||||
// Gestion des mises à jour Firebase
|
||||
void streamCallback(FirebaseStream data) {
|
||||
Serial.printf("Firebase Update - Path: %s, Data: %s\n", data.dataPath().c_str(), data.stringData().c_str());
|
||||
void streamCallback(FirebaseStream data) {
|
||||
Serial.printf("🔥 Firebase Update - Path: %s\n", data.dataPath().c_str());
|
||||
|
||||
if (data.dataType() == "boolean") { // Vérifie qu'on reçoit bien un booléen
|
||||
if (data.dataPath() == "/armed") {
|
||||
armed = data.boolData();
|
||||
Serial.printf("🔒 Alarme %s\n", armed ? "activée" : "désactivée");
|
||||
@ -66,9 +65,10 @@ void streamCallback(FirebaseStream data) {
|
||||
triggered = data.boolData();
|
||||
if (!armed) addLog("Alarme désactivée à distance");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
// Connexion WiFi
|
||||
@ -88,12 +88,12 @@ void setup() {
|
||||
Firebase.reconnectWiFi(true);
|
||||
|
||||
// Stream Firebase
|
||||
if (!Firebase.RTDB.beginStream(&stream, "/Alarm")) {
|
||||
if (!Firebase.RTDB.beginStream(&stream, "/Alarm/state")) {
|
||||
Serial.printf("🔥 Erreur stream: %s\n", stream.errorReason().c_str());
|
||||
}
|
||||
Firebase.RTDB.setStreamCallback(&stream, streamCallback, nullptr);
|
||||
Firebase.RTDB.setBool(&fbdo, "/Alarm/triggered", false);
|
||||
Firebase.RTDB.setBool(&fbdo, "/Alarm/armed", false);
|
||||
Firebase.RTDB.setBool(&fbdo, "/Alarm/state/triggered", false);
|
||||
Firebase.RTDB.setBool(&fbdo, "/Alarm/state/armed", false);
|
||||
|
||||
addLog("Alarme connectée");
|
||||
|
||||
@ -106,9 +106,9 @@ void setup() {
|
||||
attachInterrupt(digitalPinToInterrupt(A2), onMotionDetected, RISING);
|
||||
|
||||
blinkSlowGreen();
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
void loop() {
|
||||
Firebase.ready();
|
||||
|
||||
if (armed) {
|
||||
@ -118,7 +118,7 @@ void loop() {
|
||||
Serial.println("🎯 Mouvement détecté !");
|
||||
blinkFastRed();
|
||||
startSirene();
|
||||
Firebase.RTDB.setBool(&fbdo, "/Alarm/triggered", true);
|
||||
Firebase.RTDB.setBool(&fbdo, "/Alarm/state/triggered", true);
|
||||
triggered = true;
|
||||
addLog("Mouvement détecté, alarme déclenchée");
|
||||
}
|
||||
@ -134,4 +134,4 @@ void loop() {
|
||||
|
||||
updateLed();
|
||||
updateSirene();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user