Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


VD: MQTT bridge 1.0.0

   (0 reviews)

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
  • ZcO4hQPHcD.png

1) import attached VD to HC2 MQTT_bridge.vfib 

change VD params

RrG3Db3D9h.png

 

change url path for HTTP bridge in main loop

 

MR5yjjSzO9.png

 

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 

 

Spoiler

98ruEmnO89.png

 

 

Good luck!

 

  • Like 1
 Share


Other Files from 10der


User Feedback

Recommended Comments

1 hour ago, kh2 said:

Hello,

Thank you.

 

where can I call npm? if on HC2 how to get to the command line

 

best regards

sorry, can't catch ypur question

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...