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

mqtt-client-node

v2.0.7

Published

MQTT Client

Downloads

3

Readme

mqtt-client-node

介绍

mqtt-client-node基于MQTT协议,按照定义的协议接入总线,实现订阅和发布的功能。使用mqtt-client-node需在智能网关后台 管理平台注册应用。

协议规则

topic: '/appToken/tar_appToken/channel/cmd/#'

| key | value | | :------------- |:-------------| | appToken | 应用的appToken | | tar_appToken | 目标appToken | | channel | 目前只有'$iot','$manager' | | cmd | '$update','$notify','$req','$rreq','$resp','$rresp' | | # | 自定义层,根据不同的channel产生不同的结果,列:channel='$iot',自定义层可能为'/iotId/attribute/messageId'或'/iotId/attribute'。 |

安装

npm install mqtt-client-node --save

例子

const App = require('mqtt-client-node').app;
const app = new App('appToken','appScrect');
//如果你只想订阅有关$iot的消息
//const app = new App('appToken','appScrect','$iot');

app.connect('mqtt://localhost').then(() => {
  console.log('connect success');

  app.req({tar: 'tar_appToken', channel: '$iot', payload:{value: 'test'}}).then((result) => {
    console.log(result);
  });
});

const Service = require('mqtt-client-node').service;
const service = new Service('appToken','appScrect');

service.connect('mqtt://localhost').then(() => {
  console.log('connect success');

  service.notify({tar: 'tar_appToken', src: 'src_appToken', channel: '$iot', payload:{value: 'test'}}).then((result) => {
    console.log(result);
  });
});

api

  • init()
  • connect()
  • app.req()
  • app.rresp()
  • app.update()
  • app.soeIotAttrs()
  • service.rreq()
  • service.resp()
  • service.notify()

init(appToken, appScrect, [options])

对连接mqtt总线验证的数据进行初始化。

  • appToken 注册应用的appToken
  • appScrect 注册应用的appScrect
  • options 配置项。这个是选择项。
    • channel 需要订阅的对象$iot/$manager
    • topicRule topic规则
    • subscribePatterns 订阅对象

connect(address, [options])

连接mqtt总线,address为总线地址。

  • address 总线地址
  • options 注册应用的appScrect。这个是选择项。

app.req({tar, channel, params, [payload], [options]})

app向service发送请求,获取tar的返回的数据。

  • tar 目标应用的appToken
  • channel '$iot','$manager'
  • params '$iot': {'iotId','attribute'}, '$manager': {'class','action'}
  • payload 传输的数据体。这个是选择项。
  • options {timeout: 1000}。这个是选择项。

app.rresp({tar, channel, params, messageId, [payload], [error]})

app向service发送tar的需要的数据。

  • tar 目标应用的appToken
  • channel '$iot','$manager'
  • params '$iot': {'iotId','attribute'}, '$manager': {'class','action'}
  • messageId service发送rreq生成的messageId
  • payload 传输的数据体。这个是选择项。
  • error 错误信息 eg.'error message'。这个是选择项。

app.update({channel, params, [payload], [error], [options]}, [mqttOptions])

app上报数据给service。

  • channel '$iot','$manager'
  • params '$iot': {'iotId','attribute'}, '$manager': {'class','action'}
  • payload 传输的数据体。这个是选择项。
  • options {type: 's'}。这个是选择项。
  • mqttOptions mqtt.publish配置,见mqtt.publish()。这个是选择项。

app.soeIotAttrs({attrs, params}, [mqttOptions])

iot设备上报数据给service。

  • attrs {1: {type: 's', payload: 'aaa'}}
  • params {iotId: 'aaa'}
  • mqttOptions mqtt.publish配置,见mqtt.publish()。这个是选择项。

service.rreq({tar, src, channel, params, [payload], [options]})

service向tar发送rreq请求,获取tar的返回的数据。

  • tar 目标应用的appToken
  • src 发送req请求来源的appToken
  • channel '$iot','$manager'
  • params '$iot': {'iotId','attribute'}, '$manager': {'class','action'}
  • payload 传输的数据体。这个是选择项。
  • options {timeout: 1000}。这个是选择项。

service.resp({tar, src, channel, params, messageId, [payload], [error]})

service向tar发送src返回的数据。

  • tar 目标应用的appToken
  • src rreq接收返回数据来源的appToken
  • channel '$iot','$manager'
  • params '$iot': {'iotId','attribute'}, '$manager': {'class','action'}
  • messageId 接收req来源的messageId
  • payload 传输的数据体。这个是选择项。
  • error 错误信息 eg.'error message'。这个是选择项。

service.notify({tar, src, channel, params, [payload], [error], [options]}, [mqttOptions])

service向tar发送通知。

  • tar 目标应用的appToken
  • src 来源的appToken
  • channel '$iot','$manager'
  • params '$iot': {'iotId','attribute'}, '$manager': {'class','action'}
  • payload 传输的数据体。这个是选择项。
  • error 错误信息 eg.'error message'。这个是选择项。
  • options {type: 's'}。这个是选择项。
  • mqttOptions mqtt.publish配置,见mqtt.publish()。这个是选择项。

License

MIT