3

I'm prototyping a web-app to continuously monitor my nest for updates using the Firebase library, and I would like to discuss methods for doing it. Nest has examples of mobile apps and web apps that use user-side javascript for nest-developers, but there are no examples using node.js that implement continuous monitoring. In lieu of a working example, I hoped to discuss a few ideas here.

For an example of what I want to do: If my smoke alarm goes off I want to send an email blast to me and my family (the mechanics of issuing the blast are not important). I'm using node.js and express.js and I don't want to need to keep a webpage open to monitor my home. Thus I want to implement my monitoring on the server side.

My current plan is to incorporate the functionality into a class that I use in my route controller, so that the user can issue a request to a URL to activate the monitoring and have the connection and relevant data persist after the user's left the website. In my tests the web app continues to monitor my nest after I have disconnected from it, but I'm not sure if the connection will eventually timeout. Anyways, connection issues are common, so it's something I need to address regardless.

So here are the general questions I'm considering:

Is it appropriate to place monitoring code in routes/controllers? Or would another framework, like Ruby on Rails (I saw something about using RESTful streaming), be better suited for continuously monitoring?

How should overhead data for monitoring connections be stored (like the device_ID)? Is there a better way to store overhead data than creating a "connection" object?

Lastly, will monitoring connections eventually timeout? Regardless, what ways are there to re-establish interrupted connections (I read the documentation for .onDisconnect, but it didn't allow for custom callbacks)?

sgussman
  • 123
  • 1
  • 10
  • 1
    Firebase in general (all clients including the nodejs one) automatically maintains a persistent connection to the server. i.e it reconnects if disconnected. So you can very well use a nodejs server that has a persistent connection to Nest servers to monitor your smoke alarm – Nagesh Susarla Jul 30 '14 at 05:37

2 Answers2

4

I've written a couple of node.js servers that maintain persistent connections to Firebase and take action when relevant data changes. I think it's awesome. The Firebase API is virtually identical on the server and client, so you can subscribe to data as usual, but you can also (optionally) provide an auth key and have full access/control to the entire DB:

Firebase = require("firebase")
ref = new Firebase("https://<my firebase>.firebaseio.com")
ref.auth(<my key>)

ref.child("smoke-status").on("value", function(snap) {
  if (snap.val() == "FIRE") {
    // send email
  }
})
mhuebert
  • 71
  • 2
  • 6
0

Firebase uses a connection - you open the connection and listen to whatever url you have set within your root. the connection needs to be opened from the device triggering the action and the device which needs to be notified.

I thing what you are probably looking for is Firebase.goOnline() and Firebase.goOffline(), checkout documentation

The device triggering the action can goOnline when the action happens and update Firebase.

On client side your options are limited as client is listening for any update and it can be done only while the connection is open. You can make a compromise and goOnline every 5 min for 20s to collect the updates.

webduvet
  • 4,220
  • 2
  • 28
  • 39