Skip to content

Commit

Permalink
Add some reconnect logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Bultman committed Feb 6, 2015
1 parent 43ed264 commit 038a1e1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions lib/chillhub.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,20 @@ function createChillHub(Date, firebase, uid, uuid, hardware_version, software_ve
}

var gotRoot = function(rootSnap) {
setDevicesToDisconnected(rootSnap);
rootSnap.ref().onDisconnect().update({"status": "disconnected"});
rootSnap.ref().on("value", function(snapshot) {
if (snapshot.val()) {
rootSnap.ref().onDisconnect().update({"status": "disconnected"});
rootSnap.ref().update({"status": "connected"});
}
})
if (rootSnap.val() != null) {
// This chillhub is on firebase already.
// Use the old created and updated times.
// Update the HW and SW versions to newest.
value.created = rootSnap.val().created;
value.updated = rootSnap.val().updated;
setDevicesToDisconnected(rootSnap);
rootSnap.ref().onDisconnect().update({"status": "disconnected"});
register(value);
} else {
register(value);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chillhub-firmware",
"version": "0.1.7",
"version": "0.1.8",
"description": "ChillHub is a system for creating USB devices that extend the functionality of your fridge. It consists of a raspberry pi (http://www.raspberrypi.org/), a green bean (https://firstbuild.com/greenbean/), and a USB hub in a refrigerator door. ChillHub acts as a mailman the delivers messages from the cloud and the fridge to USB devices and from the USB devices back to the cloud.",
"main": "chillhub.js",
"scripts": {
Expand Down

0 comments on commit 038a1e1

Please sign in to comment.