I have built a single website page that uses the js plugin "mqttws31.js" to get MQTT messages from cloudMQTT and display them in a webpage. The following html code perfectly in chrome but when running in evothings it won't connect to the server.
I get the following error through evothings console log
LOG: used for debugging
LOG: [object Object]
LOG: error
attached is the following html file
Code: Select all
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no
initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0" />
<title>mqtt</title>
<style>
@import 'ui/css/evothings-app.css';
</style>
<script>
// Redirect console.log to Evothings Workbench.
if (window.hyper && window.hyper.log) { console.log = hyper.log }
</script>
<script src="cordova.js"></script>
<script src="libs/jquery/jquery.js"></script>
<script src="libs/evothings/evothings.js"></script>
</head>
<body ontouchstart=""><!-- ontouchstart="" enables low-delay CSS transitions. -->
<h1>Arduino LED On/Off TCP</h1>
<script src="mqttws31.js" type="text/javascript"></script>
<script type="text/javascript">
// Create a client instance
client = new Paho.MQTT.Client("m20.cloudmqtt.com", 30989,"client_id");
//Example client = new Paho.MQTT.Client("m11.cloudmqtt.com", 32903, "web_" + parseInt(Math.random() * 100, 10));
// set callback handlers
client.onConnectionLost = onConnectionLost;
client.onMessageArrived = onMessageArrived;
var options = {
useSSL: true,
userName: "eiyatsta",
password: "Q0q9xyYeOkcT",
onSuccess:onConnect,
onFailure:doFail
}
// connect the client
client.connect(options);
// called when the client connects
function onConnect() {
// Once a connection has been made, make a subscription and send a message.
console.log("onConnect");
client.subscribe("eiyatsta/feeds/temperature");
client.subscribe("eiyatsta/feeds/humidity");
message = new Paho.MQTT.Message("Hello CloudMQTT");
message.destinationName = "/cloudmqtt";
client.send(message);
}
console.log("used for debugging");
function doFail(e){
console.log(e);
console.log("error");
}
// called when the client loses its connection
function onConnectionLost(responseObject) {
if (responseObject.errorCode !== 0) {
console.log("onConnectionLost:"+responseObject.errorMessage);
}
}
// called when a message arrives
function onMessageArrived(message) {
console.log("onMessageArrived:"+message.payloadString);
document.write(message.payloadString);
}
</script>
<body>
</body>
</html>
Thanks
Steve