title: AMQJS0011E Invalid state not connected
body: <p>I'm trying to publish a message on a MQTT Broker on a raspberry trough paho.
  I've built an &quot;app&quot; with visual studio 2015 (on windows 10) and I'm using the ripple simulator to test it but I always get this error:</p>
  <blockquote>
  <p>AMQJS0011E Invalid state not connected.</p>
  </blockquote>
  <p>I also tried to export the files and to open them as regular webpages with firefox on a linux system and I get the same kind of error so I don't think is something windows related.</p>
  <p>The function that gets triggered with a button is <code>playCanzone()</code></p>
  <pre><code>function playCanzone() {
  console.log(&quot;play premuto&quot;);
  mqttHost = '192.168.9.184';
  topic = 'testTopic';
  client = new Paho.MQTT.Client(mqttHost, 8080, &quot;myclientid_&quot; + parseInt(Math.random() * 100, 10));
  onConnect();//publish('mEssaggio', 'testtopic/bar', 2);
  }
  
  // set callback handlers
  client.onConnectionLost = onConnectionLost;
  client.onMessageArrived = onMessageArrived;
  
  // connect the client
  client.connect({ onSuccess: onConnect });
  
  // called when the client connects
  function onConnect() {
  // Once a connection has been made, make a subscription and send a message.
  console.log(&quot;onConnect&quot;);
  client.subscribe(topic);
  message = new Paho.MQTT.Message(&quot;Hello&quot;);
  message.destinationName = topic;
  client.send(message);
  }
  
  // called when the client loses its connection
  function onConnectionLost(responseObject) {
  if (responseObject.errorCode !== 0) {
      console.log(&quot;onConnectionLost:&quot; + responseObject.errorMessage);
  }
  }
  
  // called when a message arrives
  function onMessageArrived(message) {
  console.log(&quot;onMessageArrived:&quot; + message.payloadString);
  }
  </code></pre>