为什么仅将数据写入 Firebase 数据库会花费我 12kB/分钟的下载量?

Why does only writing data to Firebase Database cost me 12kB/minute in downloads?

我在 IoT 设备 运行 Node-red 环境中使用本机 Firebase Javascript SDK's

尽管我没有 READ 任何数据,但当我今天早上查看 Firebase 控制台时,我看到了一张图表,其中显示了恒定的 12kB/minute 下载量和 1 峰值连接.我虽然有一些机器人连接到我的数据库。所以我关闭了我的物联网设备,我在图表中看到连接也从 1 变为 0(所以我确定只有我的物联网设备连接到数据库)。

下载量也从 12kB/minute 增加到 0kB/minute:

当我只使用 READ 方法时,为什么我的物联网设备会下载任何数据?


物联网设备开启时运行的代码:

//Load data from Global contexta
const app = global.get('app');
const database = global.get('database');
const firestore = global.get('firestore');
const auth = global.get('auth');


const firebaseConfig = {
  //my credentials 
};

//Set up Firebase
const fb_app = app.initializeApp(firebaseConfig);
const fb_db = database.getDatabase(); //kdybychom měli vice projektu tak app dame do parametru
const fb_ft = firestore.getFirestore();
const fb_auth = auth.getAuth();

//Save the database reference to Global context
global.set('fb_app', fb_app);
global.set('fb_db', fb_db);
global.set('fb_ft', fb_ft);
global.set('fb_auth', fb_auth);

每1秒写一次数据的代码:

const fb = global.get('database');
const fb_db = global.get('fb_db');

var timestamp = Math.round(msg.payload / 1000);
var UID = 'uid1';

var a1 = 0  + Math.floor(Math.random() * 100);
var p1 = 50 + Math.floor(Math.random() * 20);
var t1 = 20 + Math.floor(Math.random() * 20);

//Send data to Firebase
const ref = fb.ref(
    fb_db,
    'device_realtime/' + UID + '/' + timestamp.toString()
);

fb.set(ref, {
    a1: a1,
    p1: p1,
    t1: t1
});

删除早于 60 秒的数据的代码:

const fb = global.get('database');
const fb_db = global.get('fb_db');

var timestamp1 = Math.round(msg.payload / 1000) - 60;
var timestamp2 = Math.round(msg.payload / 1000) - 61;
var UID = 'uid1';

//Delete old data from firebase
var reference1 = fb.ref(
    fb_db,
    'device_realtime/' + UID + '/' + timestamp1.toString()
);

var reference2 = fb.ref(
    fb_db,
    'device_realtime/' + UID + '/' + timestamp2.toString()
);

fb.remove(reference1)
fb.remove(reference2)

每1分钟写入一次数据的代码:

const fb = global.get('database');
const fb_db = global.get('fb_db');

var timestamp = Math.round(msg.payload / 1000);
var UID = 'uid1';

var a1 = 0  + Math.floor(Math.random() * 100);
var p1 = 50 + Math.floor(Math.random() * 20);
var t1 = 20 + Math.floor(Math.random() * 20);

//Send data to Firebase
const ref = fb.ref(
    fb_db,
    'device_trends/' + UID + '/' + timestamp.toString()
);

fb.set(ref, {
    a1: a1,
    p1: p1,
    t1: t1
});

整个流程截图:

在评论中展开讨论:

该下载量数字考虑了来自数据库的所有出站流量,包括例如对写入的任何可能的 OK 响应。

根据引用的数字和一些餐巾纸数学,似乎每次写入对应于大约 200 字节的下载数据。