2016-02-25 44 views
0

我試圖用流星包perak:meteor-mqtt-collection連接到CloudMQTT,但我不知道如何解釋爲mqttConnect function語法:流星配置mqttConnect選項CloudMQTT

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 ."

到目前爲止我的流星測試代碼如下所示:

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工作在節點和CloudMQTT運行,但我不知道,我已經得到進入mqttConnect()功能參數正確爲perak流星包。對於初學者來說,似乎不太可能在多個地方需要MQTT代理的URL,也不應將主題goals放在括號中,但我只是不清楚參數語法。

有什麼建議嗎?

回答

1

您應該將協議添加到URL:mqtt://m10.cloudmqtt.com