Advertisement
solielios

קריאת נתונים מן הפיירבייס לבקר

Dec 25th, 2024 (edited)
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Arduino.h>
  2. #if defined(ESP32)
  3.   #include <WiFi.h>
  4. #elif defined(ESP8266)
  5.   #include <ESP8266WiFi.h>
  6. #endif
  7. #include <Firebase_ESP_Client.h>
  8.  
  9. //Provide the token generation process info.
  10. #include "addons/TokenHelper.h"
  11. //Provide the RTDB payload printing info and other helper functions.
  12. #include "addons/RTDBHelper.h"
  13.  
  14. // Insert your network credentials
  15. #define WIFI_SSID "Galaxy S22+3663" פה לשנות!!!!!!!!!!!!!!!!
  16. #define WIFI_PASSWORD "fnyh1479" פה לשנות!!!!!!!!!!!!!!!!
  17.  
  18. // Insert Firebase project API Key
  19. #define API_KEY "AIzaSyAjG_MOsClpLU7N7o-D1PkI08_tFO84w-c" פה לשנות!!!!!!!!!!!!!!!!
  20.  
  21. // Insert RTDB URLefine the RTDB URL */
  22. #define DATABASE_URL "https://facerecognition-tank-default-rtdb.firebaseio.com"  פה לשנות!!!!!!!!!!!!!!!!
  23.  
  24. //Define Firebase Data object
  25. FirebaseData fbdo;
  26.  
  27. FirebaseAuth auth;
  28. FirebaseConfig config;
  29.  
  30. unsigned long sendDataPrevMillis = 0;
  31. int intValue;
  32. float floatValue;
  33. bool signupOK = false;
  34.  
  35. void setup() {
  36.   Serial.begin(115200);
  37.   WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  38.   Serial.print("Connecting to Wi-Fi");
  39.   while (WiFi.status() != WL_CONNECTED) {
  40.     Serial.print(".");
  41.     delay(300);
  42.   }
  43.   Serial.println();
  44.   Serial.print("Connected with IP: ");
  45.   Serial.println(WiFi.localIP());
  46.   Serial.println();
  47.  
  48.   /* Assign the api key (required) */
  49.   config.api_key = API_KEY;
  50.  
  51.   /* Assign the RTDB URL (required) */
  52.   config.database_url = DATABASE_URL;
  53.  
  54.   /* Sign up */
  55.   if (Firebase.signUp(&config, &auth, "", "")) {
  56.     Serial.println("ok");
  57.     signupOK = true;
  58.   }
  59.   else {
  60.     Serial.printf("%s\n", config.signer.signupError.message.c_str());
  61.   }
  62.  
  63.   /* Assign the callback function for the long running token generation task */
  64.   config.token_status_callback = tokenStatusCallback; //see addons/TokenHelper.h
  65.  
  66.   Firebase.begin(&config, &auth);
  67.   Firebase.reconnectWiFi(true);
  68. }
  69.  
  70. void loop() {
  71.   if (Firebase.ready() && signupOK && (millis() - sendDataPrevMillis > 15000 || sendDataPrevMillis == 0)) {
  72.     sendDataPrevMillis = millis();
  73.     if (Firebase.RTDB.getInt(&fbdo, "/test/int")) {
  74.       if (fbdo.dataType() == "int") {
  75.         intValue = fbdo.intData();
  76.         Serial.println(intValue);
  77.       }
  78.     }
  79.     else {
  80.       Serial.println(fbdo.errorReason());
  81.     }
  82.    
  83.     if (Firebase.RTDB.getFloat(&fbdo, "/test/float")) {
  84.       if (fbdo.dataType() == "float") {
  85.         floatValue = fbdo.floatData();
  86.         Serial.println(floatValue);
  87.       }
  88.     }
  89.     else {
  90.       Serial.println(fbdo.errorReason());
  91.     }
  92.   }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement