- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 Meteor 包 perak:meteor-mqtt-collection连接到CloudMQTT ,但不确定如何解释 mqttConnect function 的语法:
Collection.mqttConnect(uri, topics, options, mqttOptions)
"where
mqttOptions
is an object that is supplied tomqtt.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/
我正在尝试使用 Meteor 包 perak:meteor-mqtt-collection连接到CloudMQTT ,但不确定如何解释 mqttConnect function 的语法: Collec
我是一名优秀的程序员,十分优秀!