I am using Paho MQTT (Internet of Things) With mobilefirst 7.1 for my hybrid application development (For iOS ,Android and windows phone devices). I tried with 'broker.mqttdashboard.com' for MQTT broker, but its not working for iOS .
libc++abi.dylib: Pure virtual function called!
function wlCommonInit(){
MQTTconnect(); //connect broker with subscribe
}
var host = 'broker.mqttdashboard.com';
var port = 8000;
var topic = 'Sensor'; // topic to subscribe to
var useTLS = false;
var username = null;
var password = null;
// username = "Nazmul";
// password = "Kp0582!";
var cleansession = true;
var mqtt;
var reconnectTimeout = 2000;
function MQTTconnect() {
mqtt = new Paho.MQTT.Client(
host,
port,
"web_" + parseInt(Math.random() * 100,
10));
var options = {
timeout: 3,
useSSL: useTLS,
cleanSession: cleansession,
onSuccess: onConnect,
onFailure: function (message) {
console.log("Connection failed: " + message.errorMessage + "Retrying")
setTimeout(MQTTconnect, reconnectTimeout);
}
};
mqtt.onConnectionLost = onConnectionLost;
mqtt.onMessageArrived = onMessageArrived;
if (username != null) {
options.userName = username;
options.password = password;
}
console.log("Host="+ host + ", port=" + port + " TLS = " + useTLS + " username=" + username + " password=" + password);
mqtt.connect(options);
};
function onConnect() {
console.log('Connected to ' + host + ':' + port)
// Connection succeeded; subscribe to our topic
mqtt.subscribe(topic, {qos: 0});
};
function onConnectionLost(response) {
setTimeout(MQTTconnect, reconnectTimeout);
console.log("connection lost: " + responseObject.errorMessage + ". Reconnecting")
};
function onMessageArrived(message) {
var topic = message.destinationName;
var payload = message.payloadString;
console.log( topic + ' = ' + payload)
alert(topic + ' = ' + payload);
};
MobileFirst: version 7.1.0.00-20151114-1616
xcode: Version 7.2 beta (7C46t)
iphone 6s plus
project uploaded here: https://github.com/nazmulkp/Mqtt-MobileFirst-Hybrid-Application
Thank you
it was a null reference error that the editor didn't catch - it ran only in code available on the iPhone.
Null reference errors: because always javascript file did not load. object throwing this error.
Now this way it is working
function wlCommonInit(){
$(document).ready(function(){
MQTTconnect(); //connect broker with subscribe
});
}