3

I am trying to read basic information about thermostats using the methods in the thermostat control example (https://developer.nest.com/documentation/control), but when I connect to firebase I only see the structure object (which only contains name, away, smoke_co_alarms, structure_id and thermostats) in the snapshot– There is no devices object. I am connecting to firebase using

    var nestToken = $.cookie('nest_token');
    var dataRef = new Firebase('wss://developer-api.nest.com/');
    dataRef.auth(nestToken);

I tried to connect directly to devices using wss://developer-api.nest.com/devices, but that only returns an undefined data-structure.

I've also tried connecting to firebase using https://developer-api.nest.com/ and https://developer-api.nest.com/, but they raised an authorization error and caused my javascript to go into an infinite loop sending requests.

I'm reading data using:

dataRef.on('value', function (snapshot) {
    var data = snapshot.val();
    structure = firstChild(data.structures);
    console.log(data);
    console.log(data.structures);
    console.log(data.devices);
    console.log(data.devices.thermostats);
    console.log(structure.thermostats);
};

Lastly, I tried it on an account with real devices and one with virtual devices, so I know that couldn't be causing it (even though I didn't expect it to).

Any ideas what I am doing wrong? The issue couldn't be in my App.js file, could it? Is there some configuration I need to do on the user's end in addition to the authentication? I get the feeling it's probably something really simple that's staring me in the face.

sgussman
  • 123
  • 1
  • 10

2 Answers2

3

So I figured it out: It's a permissions issue. When my client-profile was setup, it only requested permission to read the away/home status. So when I query Firebase it only returns the a snapshot with structure because that is where the away/home status can be read. So, in summary, if you're not seeing the devices structure, even though devices are associated with the user, check your client permissions.

sgussman
  • 123
  • 1
  • 10
  • Seem to remember someone else got caught with that on a related question. This hasn't been a problem for me because I set-up with full permissions, but it's worth knowing. It's also the sort of thing which you'd hope Nest were watching for here, and stepping in with a quick answer (particularly since StackOverflow is the only option for support with this API). – thesimm Jul 24 '14 at 11:10
1

Using (some of) your code, I have no trouble seeing the devices object:

var dataRef = new Firebase('wss://developer-api.nest.com');
dataRef.auth(nestTokenLive);
dataRef.on('value', function (snapshot) {
    var data = snapshot.val();
    console.log(data);
    console.log(data.devices);
});

Results in:

> Object {devices: Object, structures: Object}
> Object {thermostats: Object}
thesimm
  • 774
  • 3
  • 12
  • Thanks for letting me know that code isn't buggy. What version of firebase are you using? The example used 1.0.15, but I know the current release is 1.0.17. – sgussman Jul 23 '14 at 16:15
  • Scratch that. I just updated my version of firebase and it didn't change anything. – sgussman Jul 23 '14 at 16:22
  • Bit late, but in answer to your question, I'm on 1.0.17 - I only came across Firebase because of the Nest API and initially viewed it as an unnecessary extra framework, and one more thing to have to learn. But the REST streaming is fantastic and I am now considering pushing all my home monitoring stats up to Firebase, just so that I can stream back to my own clients. – thesimm Jul 24 '14 at 11:15