JSFiddle - React, Tailwind, and code Playground

by jasonwilczak

HTML

<body onload ="heartbeat()">

<h2>A demo for showing the pub/sub between clients and the message     broker</h2> <h3>IoTGateway</h3>
Topic :
<input type="text" name="pub"/>
Message:
<input type="text" name="pub"/>
<button onclick="connect()">
    Connect
</button>
<br>
<button onclick="publish()">
    Publish
</button>
<br>

<h3>BluetoothID</h3> Topic:
<input type="text" name="sub"/>
<button onclick="heartbeat()">
    Subscribe
</button>
<br>
<p id = "test"></p>
<p id="sub"></p>

JavaScript

var MqttPlugin = {
    subscribe:function(data){alert(data.topic);} ,
    publish: function() {alert('publish');}
} 

function heartbeat() {
            alert("hello");
            try{
            MqttPlugin.subscribe({topic: "$EDC/plugin"});
            }
            catch(err){
            alert(err.message);
            }
        //window.onload = heartbeat;
        }
       /* try{
        MqttPlugin.heartbeat({topic: "$EDC/tum/B8:27:EB:A6:A9:8A/HEARTBEAT-V1/mqtt/heartbeat"});
        }
        catch(err){
        alert(err.message);
        }*/


        function publish() {

            MqttPlugin.publish({
            topic:"$EDC/plugin",
            data:"Mqtt data"

            });
        }

        function subscribe() {
            MqttPlugin.subscribe({topic: "$EDC/plugin"});
        }