You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 23:53:12