About This File
0) Create HTTP -> MQTT bridge. (skip if you already have)
- $ sudo apt-get install mosquitto mosquitto-clients
- unzip attached mqtt_php.zip to www root folder, for example, /var/www/html/fibaro/mqtt.php
- call from browser http://192.168.1.28/fibaro/mqtt.php where "192.168.1.28" www server where you unzip attached mqtt_php.zip and "fibaro/mqtt.php" path in your www server
- here is valid response
-
1) import attached VD to HC2 MQTT_bridge.vfib
change VD params
change url path for HTTP bridge in main loop
2) create simple HTML test page
<!DOCTYPE html> <html> <head> <title></title> <meta charset="utf-8" /> </head> <body> <div id="log"></div> <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.0.1/mqttws31.min.js" type="text/javascript"></script> <script type="text/javascript"> (function () { if (!console) { console = {}; } var old = console.log; var logger = document.getElementById('log'); console.log = function (message) { if (typeof message == 'object') { logger.innerHTML += (JSON && JSON.stringify ? JSON.stringify(message) : String(message)) + '<br />'; } else { logger.innerHTML += message + '<br />'; } } })(); // Create a client instance client = new Paho.MQTT.Client("192.168.1.28", 1884, "clientId"); // 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("onConnect"); // Topic: home/roomID/deviceType/deviceID //client.subscribe("home/#"); // all events from all home //client.subscribe("home/4/#"); // all events from 4 room //client.subscribe("home/4/com.fibaro.binarySwitch/#"); // only binarySwitch events from 4 room client.subscribe("home/+/com.fibaro.binarySwitch/#"); // only binarySwitch events from all home } // 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("Message Arrived: " + message.payloadString); console.log("Topic: " + message.destinationName); } </script> </body> </html>
please change 192.168.1.28 in code on IP address HTTP MQTT bridge
locate on this test page
you should get page like
Good luck!
Recommended Comments
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.