Skip to content

Commit 038a1e1

Browse files
author
Rob Bultman
committed
Add some reconnect logic.
1 parent 43ed264 commit 038a1e1

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

lib/chillhub.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,20 @@ function createChillHub(Date, firebase, uid, uuid, hardware_version, software_ve
142142
}
143143

144144
var gotRoot = function(rootSnap) {
145+
setDevicesToDisconnected(rootSnap);
146+
rootSnap.ref().onDisconnect().update({"status": "disconnected"});
147+
rootSnap.ref().on("value", function(snapshot) {
148+
if (snapshot.val()) {
149+
rootSnap.ref().onDisconnect().update({"status": "disconnected"});
150+
rootSnap.ref().update({"status": "connected"});
151+
}
152+
})
145153
if (rootSnap.val() != null) {
146154
// This chillhub is on firebase already.
147155
// Use the old created and updated times.
148156
// Update the HW and SW versions to newest.
149157
value.created = rootSnap.val().created;
150158
value.updated = rootSnap.val().updated;
151-
setDevicesToDisconnected(rootSnap);
152-
rootSnap.ref().onDisconnect().update({"status": "disconnected"});
153159
register(value);
154160
} else {
155161
register(value);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "chillhub-firmware",
3-
"version": "0.1.7",
3+
"version": "0.1.8",
44
"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.",
55
"main": "chillhub.js",
66
"scripts": {

0 commit comments

Comments
 (0)