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 🙏

© 2025 – Pkg Stats / Ryan Hefner

mqtt-sdk

v0.0.1

Published

## 示例用法

Downloads

17

Readme

mqtt-sdk使用文档

示例用法

// 创建新实例
const psconn = new PSConn()
// 建立连接
psconn.connect(
  'mqttbroker', 
  'gf', 
  'C15D9FA90F28534643F863A3D446E0C3', 
  '1561517671717',
)

// 监听连接成功实践,在其内订阅和发布消息
psconn.on('connect', (e) => {
  if(e) {
    console.error(e)
    return
  }

  psconn.sub(
    'mqttbroker/test-topic1',
    'B75FCB6455669502DB60243459AB93B3',
    '1561518748069'
  )

  setTimeout(() => {
    psconn.pub(
      'mqttbroker/test-topic1',
      'test-topic1:message1',
      'B75FCB6455669502DB60243459AB93B3',
      '1561518748069'
    )
    psconn.unsub('mqttbroker/test-topic1')
  }, 2000)

  setTimeout(() => {
    psconn.pub('mqttbroker/test-topic1', 'test-topic1:message2', 'B75FCB6455669502DB60243459AB93B3', '1561518748069')
  }, 4000)
})

// 监听消息,回调函数中包括topic和message参数
psconn.on('message', (topic, message) => {
  console.log(topic, message.toString())
})

// 监听连接关闭事件,手动触发disconnect后会触发
psconn.on('close', () => {
  console.log('连接已关闭!')
})

// 监听错误
psconn.on('error', (e) => {
  console.error(e)
})

术语说明

  • appkey:业务线唯一标识
  • deviceName:产品唯一标识,业务线下唯一
  • userSign:用户签名,其中签名规则参照签名规则
  • random:签名随机字符串,不超过20byte

相关接口说明

1. connect 建立连接

connect(appkey, deviceName, userSign, random)

该方法用于建立连接,共包括四个参数,分别为appkey, deviceName, userSign, random。

2. disconnect 断开连接

disconnect()

3. sub 订阅消息

sub(topic, userSign, random)

该方法用于发布消息,其中topic为消息主题。

4. pub 发布消息

pub(topic, payload, userSign, random)

该方法用于发布消息,其中topic为消息主题,payload为消息内容。

5. unsub 订阅消息

unsub(topic)

该方法用于取消发布消息,其中topic为消息主题。

6. on 事件监听

on(type, handler)

该方法用于监听连接过程中的事件,第一个参数是事件类型type(支持connect/message/close/error),第二个参数为回调函数。具体使用方法见上面的示例代码。

同一类型的事件可以多次监听。