gpt4 book ai didi

javascript - 在 Meteor 中为 CloudMQTT 配置 mqttConnect 选项

转载 作者:行者123 更新时间:2023-12-03 07:35:46 25 4
gpt4 key购买 nike

我正在尝试使用 Meteor 包 perak:meteor-mqtt-collection连接到CloudMQTT ,但不确定如何解释 mqttConnect function 的语法:

Collection.mqttConnect(uri, topics, options, mqttOptions)

"where mqttOptions is an object that is supplied to mqtt.connect([url],options) in the MQTT.js library for configuring the underlying options of the MQTT.js-client. See the docs."

到目前为止,我的 Meteor 测试代码如下所示:

Goals = new Meteor.Collection('dbGoals');

if (Meteor.isClient) {
Goals.insert({
topic: "goals",
message: "Hello world from Meteor Web Client",
broadcast: true
});
}

if (Meteor.isServer) {
Meteor.startup(function () {
Goals.mqttConnect("m10.cloudmqtt.com", ["goals"], {
insert: true,
raw: true
},
{ servers: [{ host: 'm10.cloudmqtt.com', port: 12310 }],
clientId:"uniqueIdforEachMqttClient",
username: "myMqttUserName",
password: "myMqttUserPass",
clean:false
});

并出现以下错误:

C:\Users\user\AppData\Local\.meteor\packages\meteor-tool\1.1.10\mt-os.windows.x86_32\dev_bundle\server-lib\node_modules\fibers\future.js:245
throw(ex);
^
TypeError: Cannot call method 'replace' of null
at Object.connect (C:\Users\user\AppData\Local\.meteor\packages\perak_mqtt-collection\1.0.4\npm\node_modules\mqtt\lib\connect\index.js:62:35)
at [object Object].Mongo.Collection.mqttConnect (packages/perak_mqtt-collection/packages/perak_mqtt-collection.js:37:1)
at E:\Data\Projects\Project2016\design\sw\mqttColl\.meteor\local\build\programs\server\boot.js:249:5
at mqttColl.js:25:11
=> Exited with code: 8
=> Your application is crashing.

mqttColl.js:25:11是:

Goals.mqttConnect("m10.cloudmqtt.com", "goals", {

我知道我的servers:选项的对象适用于MQTT.js在 Node 和 CloudMQTT 上运行,但我不确定是否为 perak Meteor 包正确输入了 mqttConnect() 函数参数。对于初学者来说,似乎不太可能在多个地方需要 MQTT 代理的 URL,主题 goals 也不应该放在括号中,但我只是不清楚参数语法。

有什么建议吗?

最佳答案

您应该将协议(protocol)添加到 URL:mqtt://m10.cloudmqtt.com

关于javascript - 在 Meteor 中为 CloudMQTT 配置 mqttConnect 选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35621333/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com