MQTT Things

8 Servos:

???  WiFi connected
IP address: 10.11.12.23
esp8266.01-23 Attempting MQTT connection......MQTT Connected____________

Topic: TxNamib/servo.0001/01
Topic End: 01
1
Servo 01 received: Payload received: 1
1
esp8266.01-23 TxNamib/servo.0001/01 1
_


             if ( myPayload == "0" ) {     myServo.Normal();
  } else if ( myPayload == "1" ) {     myServo.Throw();
  } else if ( myPayload == "2" ) {      myServo.Toggle();
  } else if ( myPayload == "3" ) {     myServo.Midway(); 
  } else if ( myPayload == "4" ) {     myServo.Remove();
  } else if ( myPayload == "5" ) {     myServo.Reattach();
  }
// Nxxx, Txxx, N+xxx, N-xxx, T+xxx, T-xxx
// :?;
// :~;


HTML for MQTT with mqttws31.js in same folder:
<html>
  <head>
    <title>Windhoek Humpyard</title>
  </head>
	
  <body>		
    <script src="mqttws31.js" type="text/javascript"></script>		
    <script type="text/javascript">

      client = new Paho.MQTT.Client( "10.11.12.13", 9001,"client_id" );
      client.onConnectionLost = onConnectionLost;
      client.onMessageArrived = onMessageArrived;
      var options = {
        onSuccess:onConnect,
onFailure:doFail } // options // connect the client
client.connect( options );
// called when the client connects function onConnect() { console.log( "onConnect" ); client.subscribe( "TxNamib/servo.0001/01" ); } // onConnect() function doFail(e){ console.log(e); } // doFail() function publish( topic, payload ) { message = new Paho.MQTT.Message( payload ); message.destinationName = topic; client.send(message); } // publish() // called when the client loses its connection function onConnectionLost( responseObject ) { if ( responseObject.errorCode !== 0 ) { console.log( "onConnectionLost:" + responseObject.errorMessage ); } // if() } // onConnectionLost() // called when a message arrives function onMessageArrived(message) { console.log( "onMessageArrived:" + message.payloadString ); } // onMessageArrived() function HillWVB() { publish( "TxNamib/servo.0001/01", "1" ); publish( "TxNamib/servo.0001/02", "0" ); publish( "TxNamib/servo.0001/04", "0" ); document.getElementById('route').innerHTML = 'Walvisbaai'; } function HillKZB() { publish( "TxNamib/servo.0001/01", "0" ); publish( "TxNamib/servo.0001/02", "0" ); publish( "TxNamib/servo.0001/04", "0" ); document.getElementById('route').innerHTML = 'Kranzberg'; } function HillOTA() { publish( "TxNamib/servo.0001/01", "0" ); publish( "TxNamib/servo.0001/02", "0" ); publish( "TxNamib/servo.0001/06", "1" ); document.getElementById('route').innerHTML = 'Otavi'; } function HillOTJ() { publish( "TxNamib/servo.0001/01", "0" ); publish( "TxNamib/servo.0001/02", "0" ); publish( "TxNamib/servo.0001/05", "1" ); document.getElementById('route').innerHTML = 'Otjiwarongo'; } function HillWDH3() { publish( "TxNamib/servo.0001/01", "0" ); publish( "TxNamib/servo.0001/02", "0" ); publish( "TxNamib/servo.0001/05", "0" ); document.getElementById('route').innerHTML = 'Windhoek 3'; } function HillWDH2() { publish( "TxNamib/servo.0001/01", "0" ); publish( "TxNamib/servo.0001/02", "0" ); publish( "TxNamib/servo.0001/03", "1" ); document.getElementById('route').innerHTML = 'Windhoek 2'; } function HillWDH1() { publish( "TxNamib/servo.0001/01", "0" ); publish( "TxNamib/servo.0001/02", "0" ); publish( "TxNamib/servo.0001/03", "0" ); document.getElementById('route').innerHTML = 'Windhoek 1'; } </script> <div> Humpyard Hill </div> <button onclick="HillWVB()" style="height:30px; width:150px">Walvisbaai</button><br> <button onclick="HillKZB()" style="height:30px; width:150px">Kranzberg</button><br> <button onclick="HillOTA()" style="height:30px; width:150px">Otavi</button><br> <button onclick="HillOTJ()" style="height:30px; width:150px">Otjiwarongo</button><br> <button onclick="HillWDH3()" style="height:30px; width:150px">Windhoek #3</button><br> <button onclick="HillWDH2()" style="height:30px; width:150px">Windhoek #2</button><br> <button onclick="HillWDH1()" style="height:30px; width:150px" autofocus>Windhoek #1</button><br> <br> <p id="route"></p> </body> </html>
Comments