var IoTFconnector = function (orgId, api_key, auth_token, $rootScope) { //this.connected = ''; this.clientId = "a:" + orgId + ":" + Date.now(); console.log("clientId: " + this.clientId); this.hostname = orgId + ".messaging.internetofthings.ibmcloud.com"; this.client = ''; this.initialize = function () { client = new Messaging.Client(this.hostname, 8883, this.clientId); client.onMessageArrived = function (msg) { console.log("Message from :" + msg.destinationName); }; var connectOptions = new Object(); connectOptions.keepAliveInterval = 3600; connectOptions.useSSL = true; connectOptions.userName = api_key; connectOptions.password = auth_token; connectOptions.onSuccess = function () { IoTFconnector.prototype.clientStatus.connected = true; // $rootScope.$broadcast("clientStatusUpdated", clientStatus); console.log("MQTT connected to host: " + client.host + " port : " + client.port + " at " + Date.now()); } connectOptions.onFailure = function (e) { console.log("MQTT connection failed at " + Date.now() + "\nerror: " + e.errorCode + " : " + e.errorMessage); } console.log("about to connect to " + client.host); client.connect(connectOptions); //client = new Messaging.Client(this.hostname, 8883, this.clientId); //// Initialize the Realtime Graph ////var rtGraph = new RealtimeGraph(); //client.onMessageArrived = function(msg) { // //var topic = msg.destinationName; // //var payload = JSON.parse(msg.payloadString); // ////First message, instantiate the graph // //if (firstMessage) { // // $('#chart').empty(); // // firstMessage = false; // // rtGraph.displayChart(null, payload); // //} else { // // rtGraph.graphData(payload); // //} // console.log("Message from :" + msg.destinationName); //}; //client.onConnectionLost = function(e) { // console.log("Connection Lost at " + Date.now() + " : " + e.errorCode + " : " + e.errorMessage); // this.connect(connectOptions); //} //var connectOptions = new Object(); //connectOptions.keepAliveInterval = 3600; //connectOptions.useSSL = true; //connectOptions.userName = api_key; //connectOptions.password = auth_token; //connectOptions.onSuccess = function() { // IoTFconnector.prototype.connected = true; // console.log("MQTT connected to host: " + client.host + " port : " + client.port + " at " + Date.now()); //} //connectOptions.onFailure = function(e) { // console.log("MQTT connection failed at " + Date.now() + "\nerror: " + e.errorCode + " : " + e.errorMessage); //} //console.log("about to connect to " + client.host); //client.connect(connectOptions); } this.initialize(); //var imageHTML = '