更新我的问题。
这是我在没有安全配置的情况下使用Realtime数据库的代码。
const admin = require('firebase-admin'); const functions = require('firebase-functions'); admin.initializeApp(); exports.helloWorld = functions.https.onRequest((req, res) => { res.send('identifiant: ' + req.body.identifiant); }); exports.insertMesure = functions.https.onRequest((req, res) => { const identifiant = req.body.identifiant; const temperatureAir = req.body.temperatureAir; const humiditeSol = req.body.humiditeSol; const humiditeAir = req.body.humiditeAir; const niveauEau = req.body.niveauEau; const phSol = req.body.phSol; const dateMesure = Date.now(); const mesure = { temperatureAir: temperatureAir, humiditeSol: humiditeSol, humiditeAir: humiditeAir, niveauEau: niveauEau, phSol: phSol, dateMesure: dateMesure }; const dbRef = admin.database().ref('/users/' + identifiant + '/mesures'); dbRef.push(mesure) .then(() => { return res.status(200).send('oK'); }) .catch(err => { res.status(500).send('Error: ' + err); }); });
我的数据库的结构:
- users - {user_id} - mesures
更换
用户身份
由标识符属性
identifiant
Arduino发送的请求