原本的規則長這樣,預設的帳號規則是「不能為 null」
{
"rules": {
".read": "auth != null",
".write": "auth != null"
}
}
先將規則設為公開狀態方便測試,修改後點選「發佈」 (測試完後記得將規則改回 "auth != null"
)
{
"rules": {
".read": true,
".write": true
}
}
var dht, myFirebase;
var temperature = document.getElementById("temperature");
var humidity = document.getElementById("humidity");
boardReady({device: 'kzpV'}, board => {
board.systemReset();
board.samplingInterval = 20;
dht = getDht(board, 10);
myFirebase = new Firebase("https://<Your-Firebase>.firebaseio.com/");
dht.read(evt => {
temperature.innerHTML = dht.temperature;
humidity.innerHTML = dht.humidity;
myFirebase.push({
date: get_date(),
time: get_time(),
temperature: dht.temperature,
humidity: dht.humidity
});
}, 1000);
});
function get_date() {
var nowDay = new Date(),
nowYear = nowDay.getFullYear(),
nowMonth = nowDay.getMonth() + 1,
nowDate = nowDay.getDate();
return nowYear + "/" + nowMonth + "/" + nowDate;
}
function get_time() {
var nowTime = new Date(),
nowHours = nowTime.getHours(),
nowMinutes = nowTime.getMinutes(),
nowSeconds = nowTime.getSeconds();
return nowHours + ":" + nowMinutes + ":" + nowSeconds;
}