i am working on a project in which some of the nodes are moving and enter into a network of main units. so when nodes are connected to that units , main unit sends a value '0' if disconnected and '1' if connected to the fire base real time database.These are the status of individual nodes, connected to main nodes or not.
Till now i have log in to the console of fire base and make an id there and make a project. After than i go to my command prompt and install firebase and then "login" there and run command "firebase init". After then i created a html code and .js file to send the data over the console. i want a web page which tells us that if node is connected or not.
i tried the code which i am showing here.
<html>
<head>
<meta>
<titile>VANET REALTIME DATABASE ></title>
<script
src ="https://www.gstatic.com/firebasejs/6.5.0/firebase-app.js">
</script>
</head>
<body>
<!--value -->
<pre id ="node1">
</pre>
<!--Child -->
<script src="app.js"></script>
</body>
</html>
````
here are my .js file
```` app.js
(function() {
// Initialization Firebase
const firebaseConfig = {
apiKey: "*************************",
authDomain: "***************************",
databaseURL: "https://*******************",
projectId: "van**********",
storageBucket: "*******************",
messagingSenderId: "37*************6",
appId: "1:*********************8"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
//get elements
const preObject = document.getElementById('node1');
//create referencees
const dbRefObject = firebase.database().ref().child('node1');
//sync object changes
dbRefObject.on('value',function(snapshot){
console.log(snapshot.val());
});
});
my project has node1 which i created manually and feed some value for testing purpose. but when i run the code it doesn't show me any error but when i see on console there is no output which i feeded in node1. i refresh the page. but no change. please help, i think something is missing , but i couldn't debug it. output should be like node1 1
Aucun commentaire:
Enregistrer un commentaire