简体   繁体   English

如何将Nest API与Node js集成以实时监听Nest事件

[英]How integrate Nest API with node js for listen Nest event on real time

According with Nest API Client Libraries (explicitly Javascript for me). 根据Nest API客户端库(对我来说是Javascript )表示。 https://developers.nest.com/documentation/cloud/firebase-client-libraries https://developers.nest.com/documentation/cloud/firebase-client-libraries

We can listen on Client/Side all events emitted by Nest. 我们可以在客户端/侧面监听Nest发出的所有事件。
They have an EXCELLENT sample code in his documentation, I downloaded it and worked perfectly. 他们在他的文档中有一个出色的示例代码,我下载了该文件,并完美运行。

Is possible implement the same functionality in NodeJs ? 可以在NodeJ中实现相同的功能吗?

I read everything on Nest REST GUIDE https://developers.nest.com/documentation/cloud/rest-guide and I couldn't find calls that may help me. 我在Nest REST GUIDE https://developers.nest.com/documentation/cloud/rest-guide上阅读了所有内容,但找不到可以帮助我的电话

It is posible? 有可能吗?

Yes. 是。 This sample code should help you out. 此示例代码应该可以帮助您。 It uses Rest Streaming in node to display events from all three products. 它在节点中使用Rest Streaming来显示所有三个产品的事件。

https://github.com/nestlabs/rest-streaming https://github.com/nestlabs/rest-streaming

Yeah, you can do that by using firebase library version 1.1.3 for nodejs. 是的,您可以通过将Firebase库版本1.1.3用于nodejs来实现。

Here are the following Steps. 以下是以下步骤。

Install firebase version 1.1.3 by using node package manager. 使用节点程序包管理器安装firebase版本1.1.3。

 npm install firebase@1.1.3 
var Firebase = require('firebase');
var client = Firebase('wss://developer-api.nest.com');

//Authenticating firebase client by using access token
client.authWithCustomToken('Put Access Token Here', function(error) {
  if (error)
   console.log('Error in connecting Firebase Socket.', error);
  else
   console.log('Firebase socket is connected.');
});

//Now we can listen any changes in Nest Devices
client.on('value', function(snapshot) {
    var obj          =   snapshot.val();
    var nestDevices  =   obj.devices; //Getting All Nest Devices
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM