Mqtt.js 文档

使用MQTT.JS创建一个网页版的MQTT客户端 MQTT.js 是一个开源的 MQTT 协议的客户端库,使用 JavaScript 编写,主要用于 Node.js 和 浏览器环境中。是JavaScript 环境下的 MQTT 客户端库。可以用于微信小程序、支付宝小程序等定制浏览器环境。 阅读详情

mqtt.js

MQTT.js is a client library for the MQTT protocol, written
in JavaScript for node.js and the browser.

MQTT.js is an OPEN Open Source Project, see the Contributing section to find out what this means.

JavaScript StyleGuide

Important notes for existing users

v2.0.0 removes support for node v0.8, v0.10 and v0.12, and it is 3x faster in sending
packets. It also removes all the deprecated functionality in v1.0.0,
mainly mqtt.createConnection and mqtt.Server. From v2.0.0,
subscriptions are restored upon reconnection if clean: true.
v1.x.x is now in LTS, and it will keep being supported as long as
there are v0.8, v0.10 and v0.12 users.

v1.0.0 improves the overall architecture of the project, which is now
split into three components: MQTT.js keeps the Client,
mqtt-connection includes the barebone
Connection code for server-side usage, and mqtt-packet
includes the protocol parser and generator. The new Client improves
performance by a 30% factor, embeds Websocket support
(MOWS is now deprecated), and it has a better
support for QoS 1 and 2. The previous API is still supported but
deprecated, as such, it is not documented in this README.

As a breaking change, the encoding option in the old client is
removed, and now everything is UTF-8 with the exception of the
password in the CONNECT message and payload in the PUBLISH message,
which are Buffer.

Another breaking change is that MQTT.js now defaults to MQTT v3.1.1,
so to support old brokers, please read the client options doc.

MQTT v5 support is experimental as it has not been implemented by brokers yet.

Installation

npm install mqtt --save

Example

For the sake of simplicity, let’s put the subscriber and the publisher in the same file:

var mqtt = require('mqtt')
var client  = mqtt.connect('mqtt://test.mosquitto.org')

client.on('connect', function () {
  client.subscribe('presence', function (err) {
    if (!err) {
      client.publish('presence', 'Hello mqtt')
    }
  })
})

client.on('message', function (topic, message) {
  // message is Buffer
  console.log(message.toString())
  client.end()
})

output:

Hello mqtt

If you want to run your own MQTT broker, you can use
Mosquitto or
Mosca, and launch it.
You can also use a test instance: test.mosquitto.org and test.mosca.io
are both public.

If you do not want to install a separate broker, you can try using the
mqtt-connection.

to use MQTT.js in the browser see the browserify section

Promise support

If you want to use the new async-await functionality in JavaScript, or just prefer using Promises instead of callbacks, async-mqtt is a wrapper over MQTT.js which uses promises instead of callbacks when possible.

Command Line Tools

MQTT.js bundles a command to interact with a broker.
In order to have it available on your path, you should install MQTT.js
globally:

npm install mqtt -g

Then, on one terminal

mqtt sub -t 'hello' -h 'test.mosquitto.org' -v

On another

mqtt pub -t 'hello' -h 'test.mosquitto.org' -m 'from MQTT.js'

See mqtt help <command> for the command help.

API

mqtt.connect([url], options)

Connects to the broker specified by the given url and options and
returns a Client.

The URL can be on the following protocols: ‘mqtt’, ‘mqtts’, ‘tcp’,
‘tls’, ‘ws’, ‘wss’. The URL can also be an object as returned by
URL.parse(),
in that case the two objects are merged, i.e. you can pass a single
object with both the URL and the connect options.

You can also specify a servers options with content: [{ host: 'localhost', port: 1883 }, ... ], in that case that array is iterated
at every connect.

For all MQTT-related options, see the Client
constructor.

mqtt.Client(streamBuilder, options)

The Client class wraps a client connection to an
MQTT broker over an arbitrary transport method (TCP, TLS,
WebSocket, ecc).

Client automatically handles the following:

  • Regular server pings
  • QoS flow
  • Automatic reconnections
  • Start publishing before being connected

The arguments are:

  • streamBuilder is a function that returns a subclass of the Stream class that supports
    the connect event. Typically a net.Socket.
  • options is the client connection options (see: the connect packet). Defaults:
    • wsOptions: is the WebSocket connection options. Default is {}.
      It’s specific for WebSockets. For possible options have a look at: https://github.com/websockets/ws/blob/master/doc/ws.md.
    • keepalive: 60 seconds, set to 0 to disable
    • reschedulePings: reschedule ping messages after sending packets (default true)
    • clientId: 'mqttjs_' + Math.random().toString(16).substr(2, 8)
    • protocolId: 'MQTT'
    • protocolVersion: 4
    • clean: true, set to false to receive QoS 1 and 2 messages while
      offline
    • reconnectPeriod: 1000 milliseconds, interval between two
      reconnections
    • connectTimeout: 30 * 1000 milliseconds, time to wait before a
      CONNACK is received
    • username: the username required by your broker, if any
    • password: the password required by your broker, if any
    • incomingStore: a Store for the incoming packets
    • outgoingStore: a Store for the outgoing packets
    • queueQoSZero: if connection is broken, queue outgoing QoS zero messages (default true)
    • customHandleAcks: MQTT 5 feature of custom handling puback and pubrec packets. Its callback:
        customHandleAcks: function(topic, message, packet, done) {*some logic wit colling done(error, reasonCode)*}
      
    • properties: properties MQTT 5.0.
      object that supports the following properties:
      • sessionExpiryInterval: representing the Session Expiry Interval in seconds number,
      • receiveMaximum: representing the Receive Maximum value number,
      • maximumPacketSize: representing the Maximum Packet Size the Client is willing to accept number,
      • topicAliasMaximum: representing the Topic Alias Maximum value indicates the highest value that the Client will accept as a Topic Alias sent by the Server number,
      • requestResponseInformation: The Client uses this value to request the Server to return Response Information in the CONNACK boolean,
      • requestProblemInformation: The Client uses this value to indicate whether the Reason String or User Properties are sent in the case of failures boolean,
      • userProperties: The User Property is allowed to appear multiple times to represent multiple name, value pairs object,
      • authenticationMethod: the name of the authentication method used for extended authentication string,
      • authenticationData: Binary Data containing authentication data binary
    • authPacket: settings for auth packet object
    • will: a message that will sent by the broker automatically when
      the client disconnect badly. The format is:
      • topic: the topic to publish
      • payload: the message to publish
      • qos: the QoS
      • retain: the retain flag
      • properties: properties of will by MQTT 5.0:
        • willDelayInterval: representing the Will Delay Interval in seconds number,
        • payloadFormatIndicator: Will Message is UTF-8 Encoded Character Data or not boolean,
        • messageExpiryInterval: value is the lifetime of the Will Message in seconds and is sent as the Publication Expiry Interval when the Server publishes the Will Message number,
        • contentType: describing the content of the Will Message string,
        • responseTopic: String which is used as the Topic Name for a response message string,
        • correlationData: The Correlation Data is used by the sender of the Request Message to identify which request the Response Message is for when it is received binary,
        • userProperties: The User Property is allowed to appear multiple times to represent multiple name, value pairs object
    • transformWsUrl : optional (url, options, client) => url function
      For ws/wss protocols only. Can be used to implement signing
      urls which upon reconnect can have become expired.
    • resubscribe : if connection is broken and reconnects,
      subscribed topics are automatically subscribed again (default true)

In case mqtts (mqtt over tls) is required, the options object is
passed through to
tls.connect().
If you are using a self-signed certificate, pass the rejectUnauthorized: false option.
Beware that you are exposing yourself to man in the middle attacks, so it is a configuration
that is not recommended for production environments.

If you are connecting to a broker that supports only MQTT 3.1 (not
3.1.1 compliant), you should pass these additional options:

{
  protocolId: 'MQIsdp',
  protocolVersion: 3
}

This is confirmed on RabbitMQ 3.2.4, and on Mosquitto < 1.3. Mosquitto
version 1.3 and 1.4 works fine without those.

Event 'connect'

function (connack) {}

Emitted on successful (re)connection (i.e. connack rc=0).

  • connack received connack packet. When clean connection option is false and server has a previous session
    for clientId connection option, then connack.sessionPresent flag is true. When that is the case,
    you may rely on stored session and prefer not to send subscribe commands for the client.
Event 'reconnect'

function () {}

Emitted when a reconnect starts.

Event 'close'

function () {}

Emitted after a disconnection.

Event 'disconnect'

function (packet) {}

Emitted after receiving disconnect packet from broker. MQTT 5.0 feature.

Event 'offline'

function () {}

Emitted when the client goes offline.

Event 'error'

function (error) {}

Emitted when the client cannot connect (i.e. connack rc != 0) or when a
parsing error occurs.

Event 'end'

function () {}

Emitted when mqtt.Client#end() is called.
If a callback was passed to mqtt.Client#end(), this event is emitted once the
callback returns.

Event 'message'

function (topic, message, packet) {}

Emitted when the client receives a publish packet

  • topic topic of the received packet
  • message payload of the received packet
  • packet received packet, as defined in
    mqtt-packet
Event 'packetsend'

function (packet) {}

Emitted when the client sends any packet. This includes .published() packets
as well as packets used by MQTT for managing subscriptions and connections

Event 'packetreceive'

function (packet) {}

Emitted when the client receives any packet. This includes packets from
subscribed topics as well as packets used by MQTT for managing subscriptions
and connections


mqtt.Client#publish(topic, message, [options], [callback])

Publish a message to a topic

  • topic is the topic to publish to, String
  • message is the message to publish, Buffer or String
  • options is the options to publish with, including:
    • qos QoS level, Number, default 0
    • retain retain flag, Boolean, default false
    • dup mark as duplicate flag, Boolean, default false
    • properties: MQTT 5.0 properties object
      • payloadFormatIndicator: Payload is UTF-8 Encoded Character Data or not boolean,
      • messageExpiryInterval: the lifetime of the Application Message in seconds number,
      • topicAlias: value that is used to identify the Topic instead of using the Topic Name number,
      • responseTopic: String which is used as the Topic Name for a response message string,
      • correlationData: used by the sender of the Request Message to identify which request the Response Message is for when it is received binary,
      • userProperties: The User Property is allowed to appear multiple times to represent multiple name, value pairs object,
      • subscriptionIdentifier: representing the identifier of the subscription number,
      • contentType: String describing the content of the Application Message string
    • cbStorePut - function (), fired when message is put into outgoingStore if QoS is 1 or 2.
  • callback - function (err), fired when the QoS handling completes,
    or at the next tick if QoS 0. An error occurs if client is disconnecting.

mqtt.Client#subscribe(topic/topic array/topic object, [options], [callback])

Subscribe to a topic or topics

  • topic is a String topic to subscribe to or an Array of
    topics to subscribe to. It can also be an object, it has as object
    keys the topic name and as value the QoS, like {'test1': {qos: 0}, 'test2': {qos: 1}}.
    MQTT topic wildcard characters are supported (+ - for single level and # - for multi level)
  • options is the options to subscribe with, including:
    • qos qos subscription level, default 0
    • nl No Local MQTT 5.0 flag (If the value is true, Application Messages MUST NOT be forwarded to a connection with a ClientID equal to the ClientID of the publishing connection)
    • rap Retain as Published MQTT 5.0 flag (If true, Application Messages forwarded using this subscription keep the RETAIN flag they were published with. If false, Application Messages forwarded using this subscription have the RETAIN flag set to 0.)
    • rh Retain Handling MQTT 5.0 (This option specifies whether retained messages are sent when the subscription is established.)
    • properties: object
      • subscriptionIdentifier: representing the identifier of the subscription number,
      • userProperties: The User Property is allowed to appear multiple times to represent multiple name, value pairs object
  • callback - function (err, granted)
    callback fired on suback where:
    • err a subscription error or an error that occurs when client is disconnecting
    • granted is an array of {topic, qos} where:
      • topic is a subscribed to topic
      • qos is the granted qos level on it

mqtt.Client#unsubscribe(topic/topic array, [options], [callback])

Unsubscribe from a topic or topics

  • topic is a String topic or an array of topics to unsubscribe from
  • options: options of unsubscribe.
    • properties: object
      • userProperties: The User Property is allowed to appear multiple times to represent multiple name, value pairs object
  • callback - function (err), fired on unsuback. An error occurs if client is disconnecting.

mqtt.Client#end([force], [options], [cb])

Close the client, accepts the following options:

  • force: passing it to true will close the client right away, without
    waiting for the in-flight messages to be acked. This parameter is
    optional.
  • options: options of disconnect.
    • reasonCode: Disconnect Reason Code number
    • properties: object
      • sessionExpiryInterval: representing the Session Expiry Interval in seconds number,
      • reasonString: representing the reason for the disconnect string,
      • userProperties: The User Property is allowed to appear multiple times to represent multiple name, value pairs object,
      • serverReference: String which can be used by the Client to identify another Server to use string
  • cb: will be called when the client is closed. This parameter is
    optional.

mqtt.Client#removeOutgoingMessage(mid)

Remove a message from the outgoingStore.
The outgoing callback will be called with Error(‘Message removed’) if the message is removed.

After this function is called, the messageId is released and becomes reusable.

  • mid: The messageId of the message in the outgoingStore.

mqtt.Client#reconnect()

Connect again using the same options as connect()


mqtt.Client#handleMessage(packet, callback)

Handle messages with backpressure support, one at a time.
Override at will, but always call callback, or the client
will hang.


mqtt.Client#connected

Boolean : set to true if the client is connected. false otherwise.


mqtt.Client#getLastMessageId()

Number : get last message id. This is for sent messages only.


mqtt.Client#reconnecting

Boolean : set to true if the client is trying to reconnect to the server. false otherwise.


mqtt.Store(options)

In-memory implementation of the message store.

  • options is the store options:
    • clean: true, clean inflight messages when close is called (default true)

Other implementations of mqtt.Store:


mqtt.Store#put(packet, callback)

Adds a packet to the store, a packet is
anything that has a messageId property.
The callback is called when the packet has been stored.


mqtt.Store#createStream()

Creates a stream with all the packets in the store.


mqtt.Store#del(packet, cb)

Removes a packet from the store, a packet is
anything that has a messageId property.
The callback is called when the packet has been removed.


mqtt.Store#close(cb)

Closes the Store.

Browser

Via CDN

The MQTT.js bundle is available through http://unpkg.com, specifically
at https://unpkg.com/mqtt/dist/mqtt.min.js.
See http://unpkg.com for the full documentation on version ranges.

WeChat Mini Program

Support WeChat Mini Program. See Doc.

Example(js)

var mqtt = require('mqtt')
var client = mqtt.connect('wxs://test.mosquitto.org')

Example(ts)

import { connect } from 'mqtt';
const client = connect('wxs://test.mosquitto.org');

Ali Mini Program

Surport Ali Mini Program. See Doc.

Example(js)

var mqtt = require('mqtt')
var client = mqtt.connect('alis://test.mosquitto.org')

Example(ts)

import { connect } from 'mqtt';
const client  = connect('alis://test.mosquitto.org');

Browserify

In order to use MQTT.js as a browserify module you can either require it in your browserify bundles or build it as a stand alone module. The exported module is AMD/CommonJs compatible and it will add an object in the global space.

npm install -g browserify // install browserify
cd node_modules/mqtt
npm install . // install dev dependencies
browserify mqtt.js -s mqtt > browserMqtt.js // require mqtt in your client-side app

Webpack

Just like browserify, export MQTT.js as library. The exported module would be var mqtt = xxx and it will add an object in the global space. You could also export module in other formats (AMD/CommonJS/others) by setting output.libraryTarget in webpack configuration.

npm install -g webpack // install webpack

cd node_modules/mqtt
npm install . // install dev dependencies
webpack mqtt.js ./browserMqtt.js --output-library mqtt

you can then use mqtt.js in the browser with the same api than node’s one.

<html>
<head>
  <title>test Ws mqtt.js</title>
</head>
<body>
<script src="./browserMqtt.js"></script>
<script>
  var client = mqtt.connect() // you add a ws:// url here
  client.subscribe("mqtt/demo")

  client.on("message", function (topic, payload) {
    alert([topic, payload].join(": "))
    client.end()
  })

  client.publish("mqtt/demo", "hello world!")
</script>
</body>
</html>

Your broker should accept websocket connection (see MQTT over Websockets to setup Mosca).

Signed WebSocket Urls

If you need to sign an url, for example for AWS IoT,
then you can pass in a transformWsUrl function to the mqtt.connect() options
This is needed because signed urls have an expiry and eventually upon reconnects, a new signed url needs to be created:

// This module doesn't actually exist, just an example
var awsIotUrlSigner = require('awsIotUrlSigner')
mqtt.connect('wss://a2ukbzaqo9vbpb.iot.ap-southeast-1.amazonaws.com/mqtt', {
  transformWsUrl: function (url, options, client) {
    // It's possible to inspect some state on options(pre parsed url components)
    // and the client (reconnect state etc)
    return awsIotUrlSigner(url)
  }
})

// Now every time a new WebSocket connection is opened (hopefully not that
// often) we get a freshly signed url

About QoS

Here is how QoS works:

  • QoS 0 : received at most once : The packet is sent, and that’s it. There is no validation about whether it has been received.
  • QoS 1 : received at least once : The packet is sent and stored as long as the client has not received a confirmation from the server. MQTT ensures that it will be received, but there can be duplicates.
  • QoS 2 : received exactly once : Same as QoS 1 but there is no duplicates.

About data consumption, obviously, QoS 2 > QoS 1 > QoS 0, if that’s a concern to you.

Usage with TypeScript

This repo bundles TypeScript definition files for use in TypeScript projects and to support tools that can read .d.ts files.

Pre-requisites

Before you can begin using these TypeScript definitions with your project, you need to make sure your project meets a few of these requirements:

  • TypeScript >= 2.1
  • Set tsconfig.json: {"compilerOptions" : {"moduleResolution" : "node"}, ...}
  • Includes the TypeScript definitions for node. You can use npm to install this by typing the following into a terminal window:
    npm install --save-dev @types/node

Contributing

MQTT.js is an OPEN Open Source Project. This means that:

Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project.

See the CONTRIBUTING.md file for more details.

Contributors

MQTT.js is only possible due to the excellent work of the following contributors:

Adam RuddGitHub/adamvrTwitter/@adam_vr
Matteo CollinaGitHub/mcollinaTwitter/@matteocollina
Maxime AgorGitHub/4rzaelTwitter/@4rzael
Siarhei BuntsevichGitHub/scarry1992

License

MIT

微信小程序—连接MQTT 1、在微信开发小程序工具中首先安装mqtt.js与mqtt.min.js到文件utils中,并在引用的.js文件中声明。 var mqtt= require('../../utils/mqtt.min.js') 2、可以选择公共的MQTT服务器,仅用于测试,较为方便,由EMQ提供。同时可参考EMQ提供的文档 服务器链接:https://www.emqx.com/zh/mqtt/public-mqtt5-broker EMQ链接:https://www.emqx.com/zh/blog/how-to-use 阅读详情

相关推荐

微信小程序--P2P消息收发模式(MQTT)

P2P,顾名思义,是一对一的消息收发模式,即只有一个消息发送者和一个消息接收者。而Pub/Sub模式通常用于一对多或多对多的消息群发场景,即拥有一个或多个消息发送者和多个消息接收者的场景。在P2P模式中,发送者发送消息时已经明确该消息预期的接收者信息,并明确该消息只需要被特定的单个客户端消费。发送者发送消息时通过Topic信息直接指定接收者,接收者无需提前订阅即可获取该消息。P2P模式不仅可以为接收者节省注册订阅关系的成本,此外,由于收发消息的链路有单独的优化,还可以降低推送延迟。

每天都要努力学习哦~~ 4730

MQTT.js 入门教程

简介 MQTT.js 是一个开源的 MQTT 协议的客户端库,使用 JavaScript 编写,主要用于 Node.js 和 浏览器环境中。是目前 JavaScript 生态中使用最为广泛的 MQTT 客户端库。 MQTT 是一种基于发布/订阅模式的轻量级物联网消息传输协议,可以用极少的代码和带宽为联网设备提供实时可靠的消息服务,它广泛应用于物联网、移动互联网、智能硬件、车联网、电力能源等行业。 由于 JavaScript 单线程特性,MQTT.js 是全异步 MQTT 客户端,MQTT.js 支持 M

emqx_broker的博客 1万+

MQTT客户端搭建及应用(Nodejs)

需求:订阅来自数据同步程序发布的数据,并将接收到的数据写入Solr 。 下面将以搭建一个MQTT 写入 solr 的node js为例子 结构: 1.使用前必须安装npm (网上有很多种方法,这里就不介绍了) 2.安装mqtt 库 npm install mqtt 2.安装solr 库 npm install solr 3.创建index.js文件var mqtt = requi

5205

JS 连接MQTT的方法(mqtt.js的使用方法)

本文章是介绍 mqtt.js 的使用方法 本文章使用的版本是 4.1.x ,没用最新版的原因是 4.2.x 以上版本会报错,具体报错可以看我的另一篇文章。 使用的 4.1.x 版本地址:https://cdn.bootcdn.net/ajax/libs/mqtt/4.1.0/mqtt.min.js 如果遇到 无法连接/错误提示 WebSocket connection to …… 的问题,请看我另一篇文章,其中记录了我多次用到,遇见的连接问题。

qq_17627195的博客 3万+

MQTT协议中文文档和JS连接DEMO.zip

MQTT中文协议96页及js连接Demo,需要的人请下载

browserMqtt.js

在web page通過mqtt client訪問mqtt server中topic,即時呈現在網頁上,簡單好用,如果有需要的朋友可以聯繫,謝謝!

VUE中使用mqtt

vue2、vue3中使用mqtt

weixin_45938408的博客 286

STM32与威纶通触摸屏RS485通信实战:Modbus RTU协议与避坑指南

在工业自动化与嵌入式系统开发中,串行通信是实现设备间数据交换的基础技术。RS485总线凭借其差分信号传输、抗干扰能力强、支持多点通信及长距离传输等特性,成为工业现场广泛应用的物理层标准。其核心原理是利用一对双绞线进行平衡传输,有效抑制共模噪声。在协议层,Modbus RTU作为开放、简洁的主从式应用层协议,定义了统一的数据模型(如线圈、寄存器)和功能码,极大简化了不同厂商设备间的互操作性。结合STM32微控制器的UART外设与威纶通(Weinview)人机界面(HMI),可以构建稳定可靠的监控与控制系统。本

weixin_33925615的博客 344

AWS IoT MQTT 客户端开源项目推荐

AWS IoT MQTT 客户端开源项目推荐 AWS IoT MQTT 客户端是一个开源项目,该项目通过GitHub进行维护,链接为 https://github.com/kmamykin/aws-mqtt.git。该项目主要使用JavaScript编程语言开发,适用于在浏览器和Node.js环境中使用。 项目基础介绍 AWS IoT MQTT 客户端项目是一个实现了AWS IoT MQTT代理连...

gitblog_00986的博客 361

微信小程序 | 小程序开发

事实上,目前小程序在我们生活中已经随处可见(特别是这次疫情的推动,不管是什么岗位、什么年龄阶段的人,到哪都需要打开健康码)WePY是由腾讯开源的,一款让小程序支持组件化开发的框架,通过预编译的手段让开发者可以选择自己喜欢的开发风格去开发小程序。Mpvue是一个使用Vue开发小程序的前端框架,也是 支持 微信小程序、百度智能小程序,头条小程序 和 支付宝小程序;微信小程序、支付宝小程序、淘宝小程序、抖音小程序、头条小程序、QQ小程序、美团小程序等。,其他平台的小程序往往是平台本身的一些公司或者顺手开发的。

CoderHing的博客~ 1万+

RPA 财务共享中心与RPA赋能

在和集团财务官交流的时候,客户经常会提到FSSC,其中有准备建立FSSC,正在建立FSSC,以及已建成FSSC正使用的,当中会有些对FSSC的疑虑和问题,所以花费些时间对FSSC进行了深入调研,从而也有幸拜读了王兴山、陈剑、梅震、钱自严等专业人士写的几本关于FSSC的书,对FSSC的前因后果有了更深入的认识,同时结合自己在FSSC的一些项目经验,故做了本次分享。 本文章主要分享财务共享中心以及R...

weixin_40244959的博客 2760

【目录】mqtt.js、node.js项目

1

long_steve的博客 412

无人机航拍图像匹配——SIFT算法实践(含代码)

无人机航拍图像匹配——SIFT算法实践(含代码)

zhangzhao147的博客 6405

HiveMQ MQTT Web Client 项目推荐

HiveMQ MQTT Web Client 项目推荐 1. 项目基础介绍和主要编程语言 HiveMQ MQTT Web Client 是一个基于 WebSocket 的 MQTT 客户端,专为现代浏览器设计。该项目的主要编程语言包括 JavaScript、HTML 和 CSS。它允许用户在浏览器中直接进行 MQTT 消息的发布和订阅,适用于各种需要实时通信的应用场景。 2. 项目核心功能 Hiv...

gitblog_07580的博客 456

【NLG】(六)文本生成评价指标—— ROUGE原理及代码示例

前奏: 【NLG】(一)文本生成评价指标——BLEU原理及代码示例 【NLG】(二)文本生成评价指标—— METEOR原理及代码示例 【NLG】(三)文本生成评价指标—— ENTROPY原理及代码示例 【NLG】(四)文本生成评价指标—— diversity原理及代码示例 【NLG】(五)文本生成评价指标—— kl_divergence原理及代码示例 1.ROUGE原理 2.优缺点 3.如何算ROUGE ...

凝眸伏笔的博客 1万+

【软考】数据库系统工程师备考指南(一)

目录一、数据库系统工程师简介二、考试要求三、考试目标四、考试范围(一)信息系统知识(二)数据库系统设计与管理 一、数据库系统工程师简介 数据库系统工程师考试属于全国计算机技术与软件专业技术资格(水平)考试(简称计算机软件水平资格考试)中的一个中级考试。考试不设学历与资历条件,也不论年龄和专业,考生可根据自己的技术水平选择合适的级别合适的资格,但一次考试只能报考一种资格。考试采用笔试形式,考试实行全国统一大纲、统一试题、统一时间、统一标准、统一证书的考试办法。笔试安排在一天之内。 2022 年数据库系统工程

邓邓子的博客 3862

微信小程序连接阿里云物联网

utils目录 首先需要放两个文件在utils目录下方 第一个文件(文件名为mqtt.min.js) (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undef

寻梦&之璐 7026

Python爬虫实战:使用Scrapy+Playwright高效获取电力市场数据

本文将详细介绍如何使用Python构建一个高效的电力市场数据爬虫系统。我们将结合Scrapy框架和Playwright浏览器自动化工具,解决电力市场网站常见的反爬机制,实现数据的稳定抓取。文章包含完整的项目搭建流程、代码实现、数据处理方案以及部署建议,帮助读者掌握现代爬虫开发的核心技术。关键词:Python爬虫、Scrapy、Playwright、电力市场、数据采集、反爬对策python复制下载# 基本字段region = scrapy.Field() # 区域。

2201_76125261的博客 1891

微信小程序+mqtt.js实现发布订阅,及时通讯,接受消息

开篇上文档:mqtt官方文档 发布订阅基础:JS设计模式之发布订阅模式 微信小程序版mqtt.js下载:mqtt.js 在app.js中全局注册mqtt: const mqtt = require('./utils/mqtt.js') // 引入mqtt onLaunch: function() { // 防止重复注册 if (!this.globalData.client) { this.initSocket() } }, // 注册连接 initSocket() {

少吃点肉的博客 4490

嵌入式u-boot最全面试题及参考答案(5万字长文持续更新)

例如,在一个便携式设备中,U-Boot 在启动时初始化电源控制器,将输出电压设置为合适的值。命令是u-boot构建过程中用于配置u-boot选项的命令。在嵌入式系统中,启动画面(也称为启动Logo或Splash Screen)是展示给用户的第一印象,它可以包含公司的标志、产品的名称或其他相关信息。u-boot允许通过环境变量来进行配置,这使得开发者可以根据不同的硬件平台和项目需求灵活地调整u-boot的行为。写入操作可以是字节级别的,也可以是块级别的,具体取决于设备的性能和操作系统的需求。

大模型大数据攻城狮的专栏 1007

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

Node.js连接MQTT服务器

安装mqtt npm install mqtt -S 连接MQTT 创建WebsocketMqtt.js文件 const mqtt = require('mqtt') var randomCount = Math.ceil(Math.random() * 9999) + "" + Date.parse(new Date());; console.log(randomCount); // 连接选项 const options = { connectTimeout: 4000, // 超时时间 //

海森堡的博客 1702

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

关于mqtt+js前端中mqtt服务器关闭重连服务器后js前端接收不到消息的问题

关于mqtt+js前端中mqtt服务器关闭重连服务器后js前端接收不到消息的问题 解决方案 const MQTT_OPTIONS = { connectTimeout: 10000, clientId: '', username: 'admin', password: 'public', clean: true, } connectMqtt1() { MQTT_OPTIONS.clientId = v4.v4()//引入uuid库

田螺姑娘的博客 3047

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

学习笔记:如何在 Vue 项目中使用 MQTT

这一点不太好提供解决办法,只能靠读者遇到什么问题自行查询解决了(只能说,官方文档是没有问题的,鄙人曾经就调试崩溃到怀疑是官方文档的问题)(2)当读者运行到此步,浏览器还没有报错的时候那就恭喜读者接近胜利的曙光了。在VSCode中打开vue文件,新建一个终端,输入。(1)从最初接触到这一步搭建vue-MQTT项目,耗时2.5天。(1)运行项目最最令人头疼抓狂的了,因为很容易报错……----要是直接进github库进不去,就先进。自己选定一个文件夹,用于存放vue的文件,执行。.........

long_steve的博客 6172

vue中连接使用mqtt

1、安装依赖包 npm install mqtt --save 2、项目中引入 import mqtt from 'mqtt' 3、使用 var client = mqtt.connect('ws//****:8083', { // ws这个为连接类型,还有wss 为加密型 connectTimeout: 40000, clientId: '', username: 'user', password: 'password',

luckydog 3290

Blinker.js:一款跨平台的物联网设备接入库

Blinker.js 是一个开源的物联网(IoT)设备接入库,由 TypeScript 编写,同时支持 JavaScript。它为开发者提供了一种简单且高效的方式,将各种硬件设备如树莓派、香蕉派等通过 WiFi 接入到物联网中。Blinker.js 支持多种操作系统,包括 Linux、Windows、MacOS,并能够与 blinker APP 进行通信,实现设备的远程控制。 ## 2. 项目核...

gitblog_00012的博客 812

如何快速上手MQTT.js:完整的物联网通信开发指南

MQTT.js是一个开源的MQTT协议客户端库,专为JavaScript环境设计,可在Node.js和浏览器中使用,帮助开发者轻松构建物联网通信应用。无论是智能家居、工业监控还是实时数据传输场景,MQTT.js都能提供高效可靠的消息传递解决方案。 ## 📖 什么是MQTT.js? MQTT.js是GitHub加速计划中的重要项目(项目路径:gh_mirrors/mqt/MQTT.js),它实

gitblog_01098的博客 446
上一篇: Tensorflow2.0之深度残差网络resnet18实现
下一篇: C语言字符串常用操作合集
AndSonder
博客等级 码龄7年 364粉丝 154原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址