cloudMQTT

Ask, and ye shall receive.
steve
Posts: 2
Joined: 09:32, 04 Dec 2015

cloudMQTT

Postby steve » 09:44, 04 Dec 2015

Hi

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

Fredrik
Site Admin
Posts: 196
Joined: 15:00, 18 Nov 2013

Re: cloudMQTT

Postby Fredrik » 13:39, 04 Dec 2015

I would change the line "console.log(e);" to "console.log(JSON.stringify(e));" for more detail on the error.

steve
Posts: 2
Joined: 09:32, 04 Dec 2015

Re: cloudMQTT

Postby steve » 16:36, 05 Dec 2015

Hi Fredrik

Thanks for the tip, i made the change you suggested and got the following message

Code: Select all

LOG: {"errorCode":7,"errorMessage":"AMQJS0007E Socket error:undefined."}


I don't know what happened next... but while google-ing the error message it started working, i'm not sure why??

Its working fine now, i'll post another message when i find out the reason for the error in the first place.

Steve


Return to “Questions and answers”

Who is online

Users browsing this forum: Google [Bot] and 22 guests