Firebase实时数据库问题:ESP8266上传数据无法在网站显示
Firebase实时数据库异常问题
- 手动录入的数据可在网站正常展示,但ESP8266上传的数据无法被网站读取,页面显示为
null - 已确认手动与ESP8266上传的值、数据类型完全一致
- ESP8266上传数据时会重复创建同名条目
(注:出于安全考虑,firebaseConfig已留空)
前端JavaScript代码
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.0.2/firebase-app.js"; import { getDatabase, ref, onValue } from "https://www.gstatic.com/firebasejs/9.0.2/firebase-database.js"; // Initialize Firebase with your configuration const firebaseConfig = { apiKey: "", authDomain: "", databaseURL: "", projectId: "", storageBucket: "", messagingSenderId: "", appId: "", measurementId: "" }; const app = initializeApp(firebaseConfig); // Reference to your data in the database for Humidity 3x1 and Humidity 4x1 var humidity3x1Ref = ref(getDatabase(), "Humidity3x1"); var humidity4x1Ref = ref(getDatabase(), "Humidity4x1"); // Get the data and update the HTML for Humidity 3x1 onValue(humidity3x1Ref, function(snapshot) { var dataValue = snapshot.val(); var pathElement = document.querySelector(".circular-chart.orange .circle"); var textElement = document.querySelector(".circular-chart.orange .percentage"); // Update the circular chart and percentage text updateCircularChart(pathElement, textElement, dataValue); }); // Get the data and update the HTML for Humidity 4x1 onValue(humidity4x1Ref, function(snapshot) { var dataValue = snapshot.val(); var pathElement = document.querySelector(".circular-chart.green .circle"); var textElement = document.querySelector(".circular-chart.green .percentage"); // Update the circular chart and percentage text updateCircularChart(pathElement, textElement, dataValue); }); // Function to update circular chart and percentage text function updateCircularChart(pathElement, textElement, dataValue) { pathElement.setAttribute("stroke-dasharray", `${dataValue}, 100`); textElement.textContent = `${dataValue}%`; }
内容的提问来源于stack exchange,提问作者Filip GG
相关产品推荐
相关产品推荐

