MQTT.js icon indicating copy to clipboard operation
MQTT.js copied to clipboard

how to publish data in mqtt browerify code in at browser side

Open shenhome opened this issue 4 years ago • 2 comments

const cmd = Buffer.alloc(32); cmd[0] = 0xA2; cmd[1] = 0x01; client.publish('topic, cmd);

Above code is ok when at node.js server. But it's not ok when doing the same thing at browser side. I tried to change buffer.alloc to new ArrayBuffer(32). It's also failed.

So how to make binary data exchange between browser and device?

AB#9241266

shenhome avatar Jan 31 '21 09:01 shenhome

https://github.com/stonehiy/wechat-im/blob/master/libs/mqtt/mybuffer.js

weapp side:

import mybuffer from '../xx/xx/mybuffer'

const buf = mybuffer.Buffer.from([0xA2,0x01])

client.publish('topic, buf);

browser side:

<script src="./mybuffer.js"/>

const buf = mybuffer.Buffer.from([0xA2,0x01])

client.publish('topic, buf);

desc:

https://github.com/feross/buffer

mybuffer.js generated with browserify

bracket-notation.js :

var BrowserBuffer = require('../').Buffer

module.exports.Buffer = BrowserBuffer

package.json:

"perf": "browserify perf/bracket-notation.js -s mybuffer > perf/mybuffer.js && open perf/index.html",

stonehiy avatar Apr 24 '21 14:04 stonehiy

This is an automated message to let you know that this issue has gone 365 days without any activity. In order to ensure that we work on issues that still matter, this issue will be closed in 14 days.

If this issue is still important, you can simply comment with a "bump" to keep it open.

Thank you for your contribution.

github-actions[bot] avatar Sep 17 '22 02:09 github-actions[bot]

This issue was automatically closed due to inactivity.

github-actions[bot] avatar Oct 17 '22 02:10 github-actions[bot]