ESP32

ESP32 is a series of low-cost, low-power system on a chip microcontrollers with integrated Wi-Fi and dual-mode Bluetooth.


70 ₪

الناشر: متجر القطع الالكترونية

القسم: متحكمات

تاريخ النشر: 2021-11-20


Firebase with ESP32 & ESP8266

ربط الESP32 او ESP8266 مع قاعدة بيانات نوع Firebase

Json with ESP32

ارسال واستقبال بيانات على شكل json

get date time from NTP server

معرفة الوقت الحقيقي من خلال الاتصال مع سيرفر pool.ntp.org

install Esp32 board to arduino IDE

كيفية تثبيت القطعة على برنامج الاردوينو




install the library:

Go to Sketch > Include Library > Manage Libraries



ملاحظة : هذه المكتبة مستخدمة مع كل من ESP32 و ESP8266



ملاحظة : هذا الاصدار المحدد لنفس المكتبة مستخدمة مع كل من ESP32 و ESP8266 للكود المرفق مع الشرح ...



ESP32 Store Data to Firebase Database





set & get & update ==> INT , FLOAT , STRING

code
نسخ
اقتباس
عرض
تنزيل
	
								
/* * Created by K. Suwatchai (Mobizt) * * Email: k_suwatchai@hotmail.com * * Github: https://github.com/mobizt * * Copyright (c) 2019 mobizt * */ //This example shows how to read, store and update database using get, set, push and update functions. //Required HTTPClientESP32Ex library to be installed https://github.com/mobizt/HTTPClientESP32Ex #include <WiFi.h> #include "FirebaseESP32.h" #define FIREBASE_HOST "https://test-db-eb5c7-default-rtdb.firebaseio.com" //Do not include https:// in FIREBASE_HOST #define FIREBASE_AUTH "AIzaSyCLKbGgwPENpTauYEFKDEJCrCun1VorvcI" #define WIFI_SSID "admin" #define WIFI_PASSWORD "12345678" //Define Firebase Data object FirebaseData firebaseData; void setup() { Serial.begin(115200); Serial.println(); Serial.println(); 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()); Serial.println(); Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH); Firebase.reconnectWiFi(true); //Set database read timeout to 1 minute (max 15 minutes) Firebase.setReadTimeout(firebaseData, 1000 * 60); //tiny, small, medium, large and unlimited. //Size and its write timeout e.g. tiny (1s), small (10s), medium (30s) and large (60s). Firebase.setwriteSizeLimit(firebaseData, "tiny"); /* This option allows get and delete functions (PUT and DELETE HTTP requests) works for device connected behind the Firewall that allows only GET and POST requests. Firebase.enableClassicRequest(firebaseData, true); */ String path = "/ESP32_Test"; String jsonStr; //Firebase.deleteNode(firebaseData, path); Serial.println("------------------------------------"); Serial.println("Path exist test..."); if (Firebase.pathExist(firebaseData, path)) { Serial.println("Path " + path + " exists"); } else { Serial.println("Path " + path + " is not exist"); } Serial.println("------------------------------------"); Serial.println(); Serial.println("------------------------------------"); Serial.println("Set integer test..."); for (uint8_t i = 0; i < 10; i++) { if (Firebase.setInt(firebaseData, path + "/Int/Data" + (i + 1), (i + 1) * 10)) { Serial.println("PASSED"); Serial.println("PATH: " + firebaseData.dataPath()); Serial.println("TYPE: " + firebaseData.dataType()); Serial.println("ETag: " + firebaseData.ETag()); Serial.print("VALUE: "); if (firebaseData.dataType() == "int") Serial.println(firebaseData.intData()); else if (firebaseData.dataType() == "float") Serial.println(firebaseData.floatData(), 5); else if (firebaseData.dataType() == "double") printf("%.9lfn", firebaseData.doubleData()); else if (firebaseData.dataType() == "boolean") Serial.println(firebaseData.boolData() == 1 ? "true" : "false"); else if (firebaseData.dataType() == "string") Serial.println(firebaseData.stringData()); Serial.println("------------------------------------"); Serial.println(); } else { Serial.println("FAILED"); Serial.println("REASON: " + firebaseData.errorReason()); Serial.println("------------------------------------"); Serial.println(); } } Serial.println("------------------------------------"); Serial.println("Set double test..."); for (uint8_t i = 0; i < 10; i++) { if (Firebase.setDouble(firebaseData, path + "/Double/Data" + (i + 1), ((i + 1) * 10) + 0.123456789)) { Serial.println("PASSED"); Serial.println("PATH: " + firebaseData.dataPath()); Serial.println("TYPE: " + firebaseData.dataType()); Serial.println("ETag: " + firebaseData.ETag()); Serial.print("VALUE: "); if (firebaseData.dataType() == "int") Serial.println(firebaseData.intData()); else if (firebaseData.dataType() == "float") Serial.println(firebaseData.floatData(), 5); else if (firebaseData.dataType() == "double") printf("%.9lfn", firebaseData.doubleData()); else if (firebaseData.dataType() == "boolean") Serial.println(firebaseData.boolData() == 1 ? "true" : "false"); else if (firebaseData.dataType() == "string") Serial.println(firebaseData.stringData()); Serial.println("------------------------------------"); Serial.println(); } else { Serial.println("FAILED"); Serial.println("REASON: " + firebaseData.errorReason()); Serial.println("------------------------------------"); Serial.println(); } } Serial.println("------------------------------------"); Serial.println("Get double test..."); for (uint8_t i = 0; i < 10; i++) { if (Firebase.getInt(firebaseData, path + "/Double/Data" + (i + 1))) { Serial.println("PASSED"); Serial.println("PATH: " + firebaseData.dataPath()); Serial.println("TYPE: " + firebaseData.dataType()); Serial.println("ETag: " + firebaseData.ETag()); Serial.print("VALUE: "); if (firebaseData.dataType() == "int") Serial.println(firebaseData.intData()); else if (firebaseData.dataType() == "float") Serial.println(firebaseData.floatData(), 5); else if (firebaseData.dataType() == "double") printf("%.9lfn", firebaseData.doubleData()); else if (firebaseData.dataType() == "boolean") Serial.println(firebaseData.boolData() == 1 ? "true" : "false"); else if (firebaseData.dataType() == "string") Serial.println(firebaseData.stringData()); Serial.println("------------------------------------"); Serial.println(); } else { Serial.println("FAILED"); Serial.println("REASON: " + firebaseData.errorReason()); Serial.println("------------------------------------"); Serial.println(); } } Serial.println("------------------------------------"); Serial.println("Push integer test..."); for (uint8_t i = 0; i < 5; i++) { if (Firebase.pushInt(firebaseData, path + "/Push/Int", (i + 1))) { Serial.println("PASSED"); Serial.println("PATH: " + firebaseData.dataPath()); Serial.print("PUSH NAME: "); Serial.println(firebaseData.pushName()); Serial.println("ETag: " + firebaseData.ETag()); Serial.println("------------------------------------"); Serial.println(); } else { Serial.println("FAILED"); Serial.println("REASON: " + firebaseData.errorReason()); Serial.println("------------------------------------"); Serial.println(); } } Serial.println("------------------------------------"); Serial.println("Push JSON test..."); Serial.println("------------------------------------"); Serial.println("Update test..."); for (uint8_t i = 0; i < 5; i++) { jsonStr = "{"Data" + String(i + 1) + "":" + String(i + 5.5) + "}"; } } void loop() { }







سلة المشتريات افراغ السلة