npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

iot-lorawan

v1.0.2

Published

lorawan sdk for node.js

Downloads

3

Readme

SDK

senzflow-sdk.js是 senzflow.io 提供的node.js平台网关设备开发SDK.

安装

npm install senzflow-sdk.js --save

如何使用

目前这个SDK仅仅适用于老版本网关

前提条件

使用该SDK需要先

  • 开通senzflow.io帐号
  • 在云端创建和下载数字证书
  • 在云端添加网关,定义网关ID(GATEWAY-ID)
  • 在云端添加设备,定义设备ID(DEVICE-ID)
  • 在云端添加数据流,定义数据流ID(STREAM-ID)
  • 在网关建立nodejs运行环境

请参考Getting Started

建立连接

首先创建网关对象

    var Gateway = require("senzflow-sdk.js").Device;
    var myGateway = new Gateway(options);

options为网关选项,定义如下

  1. 如果网关接入认证方式为证书

     var options = {
         clientId : "GATEWAY-ID",          //GATEWAY-ID云端定义
         caPath   : "ca.pem",              //证书从云端下载
         keyPath  : "key.pem",
         certPath : "cert.pem",
     }
  2. 如果网关接入认证方式为Token

     var options = {
         clientId : "GATEWAY-ID",          
         caPath   : "ca.pem",              
         auth     : "VENDER-ID:TOKEN"   //VENDER-ID:TOKEN云端定义
     }

    var options = {
        clientId : "GATEWAY-ID",          
        auth     : "VENDER-ID:TOKEN"
    }

当网关对象创建后,网关将自动和云端建立连接,下面代码可在控制台观察连接是否成功。

    myGateway.on("connect", function() { console.log("device connected.") });
    myGateway.on("error", function(error) { console.error("Exception here >>>", error.stack, error) });

准备数据

网关采集的数据被称为数据点。发送的数据被称为数据流。一个数据流包含多个数据点。 数据流和数据点的定义在云端添加数据流的时候已经确定。

网关侧数据流定义默认使用json格式,例如

    var myDataStream = {
            DataPoint1: value1,          //数据点名云端定义
            DataPoint2: value2,         
            ...
            $time: timestamp,
        }
  • 注意:数据点的名字必须和云端一致,否则云端无法识别。$time是系统默认的时间戳的名字。

发送数据

修正发送数据的消息或事件定义如下:

    var myEvent = {
        name     : STREAM-ID,              //STREAM-ID云端定义
        node     : DEVICE-ID,              //DEVICE-ID云端定义  
        Qos      : [取值范围0-2,系统默认为1],
        payload  : myDataStream         
    }

QoS选择

  • QoS-0(At Most Once) 异常网络环境下会丢数据, 但是具有最高吞吐率。
  • QoS-1(At Least Once) 数据不会丢失, 但是可能重复, 吞吐率适中, 适应大部分应用场景。
  • QoS-2(Exactly Once) 数据不会丢失, 也不会重复, 低吞吐率. 适应不能容忍数据重发的场景。

下面代码可将网关数据发送到云端:

    myGateway.publishEvent( myEvent,function(err){
        if (err) {console.error("error in publishing:", err)}})

获得帮助