how to publish data in mqtt browerify code in at browser side
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
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",
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.
This issue was automatically closed due to inactivity.