HTTp #663
dungcand23
started this conversation in
General
HTTp
#663
Replies: 1 comment 2 replies
-
Your database URL not a console URL. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
#include <Arduino.h>
#include <WiFi.h>
#include <Firebase_ESP_Client.h>
#include <NTPClient.h>
#include <WiFiUdp.h>
// Chèn thông tin đăng nhập mạng của bạn
#define WIFI_SSID "Thu Trang"
#define WIFI_PASSWORD "duanlanh"
// Cung cấp thông tin quy trình tạo mã thông báo.
#include <addons/TokenHelper.h>
// Cung cấp thông tin in tải trọng RTDB và các chức năng trợ giúp khác.
#include <addons/RTDBHelper.h>
// Chèn Khóa API của dự án Firebase
#define API_KEY "AIzaSyAu4ErrX0s_iULifq7pt1F-2FVOpFb70Fg"
#define DATABASE_URL "https://console.firebase.google.com/u/0/project/esp32-f1e53/database/esp32-f1e53-default-rtdb/data/~2F"
#define USER_EMAIL "dungcand123@gmail.com"
#define USER_PASSWORD "d2311200@"
FirebaseData fbdo;
FirebaseAuth auth;
FirebaseConfig config;
String giomo="";
String giotat="";
String phutmo="";
String phuttat="";
String light="";
String giomo1="";
String giotat1="";
String phutmo1="";
String phuttat1="";
String light1="";
unsigned long dataMillis = 0;
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org");
byte ngay, thang, nam, giay;
float t, h;
int s;
bool ena = 0, k = 0;
String turnOn = "on";
String turnOff = "off";
String formattedDate;
unsigned long sendDataPrevMillis = 0;
int count = 0;
bool signupOK = false;
boolean manual = false; // đánh dấu trạng thái thủ công của đèn
bool receivedData = false;
int previous_ena = -1;
String inputString = "";
boolean stringComplete = false; // Biến cờ để kiểm tra xem chuỗi đã hoàn thành chưa
void setup() {
Serial.begin(115200);
Serial2.begin(115200);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Dang ket noi");
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(1500);
}
Serial.printf("Firebase Client v%s\n\n", FIREBASE_CLIENT_VERSION);
Serial.println ("");
Serial.println ("Da ket noi WiFi!");
Serial.println(WiFi.localIP());
config.api_key = API_KEY;
/* Assign the user sign in credentials /
auth.user.email = USER_EMAIL;
auth.user.password = USER_PASSWORD;
/ Assign the RTDB URL (required) /
config.database_url = DATABASE_URL;
if (Firebase.signUp(&config, &auth, "", "")){
Serial.println("ok");
signupOK = true;
}
else{
Serial.printf("%s\n", config.signer.signupError.message.c_str());
}
/ Assign the callback function for the long running token generation task */
config.token_status_callback = tokenStatusCallback; // see addons/TokenHelper.h
// Comment or pass false value when WiFi reconnection will control by your code or third party library e.g. WiFiManager
Firebase.begin(&config, &auth);
Firebase.reconnectWiFi(true);
Serial.println();
Serial.println("------------------------------------");
Serial.println("Connected...");
delay(1000);
}
void loop() {
// Wait a few seconds between measurements.
delay(2000);
if(Firebase.RTDB.getString(&fbdo,"/ESP32/khuvuc1/giomo")) {giomo = fbdo.stringData();
} else {
// In ra lỗi nếu có
Serial.println(fbdo.errorReason());
};
if(Firebase.RTDB.getString(&fbdo,"/ESP32/khuvuc1/giotat")) {giotat = fbdo.stringData();}else {
// In ra lỗi nếu có
Serial.println(fbdo.errorReason());
};
if(Firebase.RTDB.getString(&fbdo,"/ESP32/khuvuc1/phutmo")) {phutmo = fbdo.stringData();}else {
// In ra lỗi nếu có
Serial.println(fbdo.errorReason());
};
if(Firebase.RTDB.getString(&fbdo,"/ESP32/khuvuc1/phuttat")) {phuttat = fbdo.stringData();}else {
// In ra lỗi nếu có
Serial.println(fbdo.errorReason());
};
if(Firebase.RTDB.getString(&fbdo,"/ESP32/khuvuc1/giomo1")) {giomo1 = fbdo.stringData();}else {
// In ra lỗi nếu có
Serial.println(fbdo.errorReason());
};
if(Firebase.RTDB.getString(&fbdo,"/ESP32/khuvuc1/giotat1")) {giotat1 = fbdo.stringData();}else {
// In ra lỗi nếu có
Serial.println(fbdo.errorReason());
};
if(Firebase.RTDB.getString(&fbdo,"/ESP32/khuvuc1/phutmo1")) {phutmo1 = fbdo.stringData();}else {
// In ra lỗi nếu có
Serial.println(fbdo.errorReason());
};
if(Firebase.RTDB.getString(&fbdo,"/ESP32/khuvuc1/phuttat1")) {phuttat1 = fbdo.stringData();}else {
// In ra lỗi nếu có
Serial.println(fbdo.errorReason());
};
if (Firebase.RTDB.getString(&fbdo, "/ESP32/khuvuc1/den1")) {light = fbdo.stringData();}else {
// In ra lỗi nếu có
Serial.println(fbdo.errorReason());
};
if (Firebase.RTDB.getString(& fbdo, "/ESP32/khuvuc1/den1")) {light1 = fbdo.stringData();}else {
// In ra lỗi nếu có
Serial.println(fbdo.errorReason());
};
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
String data = giomo + ";" + giotat + ";" + phutmo + ";" + phuttat + ";" + giomo1 + ";" + giotat1 + ";" + phutmo1 + ";" + phuttat1 + ";" + light + ";" + light1 + ";";
Serial.println(data);
}
I only get
HTTP/1.1 302 Found
;;HTTP/1.1 302 Found
;;HTTP/1.1 302 Found
;;HTTP/1.1 302 Found
;;HTTP/1.1 302 Found
;;
please help
Beta Was this translation helpful? Give feedback.
All reactions