Skip to content

Commit

Permalink
Added MQTT JS examples for MQTTnet.Server.
Browse files Browse the repository at this point in the history
  • Loading branch information
chkr1011 committed May 16, 2020
1 parent e80d19b commit 3f5d4e9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Source/MQTTnet.Server/MQTTnet.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@
<None Update="Web\wwwroot\Hello.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Web\wwwroot\mqtt_Test.html">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Web\wwwroot\pahoJS_Test.html">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
Expand Down
33 changes: 33 additions & 0 deletions Source/MQTTnet.Server/Web/wwwroot/mqtt_Test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<html>

<head>
<title>MQTT JS Example</title>

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/mqtt.min.js" type="text/javascript"></script>

<script type="text/javascript">
var client = mqtt.connect('ws://localhost:80/mqtt')

client.on('connect', function () {
client.subscribe('mqtt_subscription', function (err) {
console.log("Subscribed");
})
})

client.on('message', function (topic, message) {
console.log(topic);
console.log(message.toString())
})

function buttonClick() {
client.publish("MQTT_JS_TOPIC", "payload");
}
</script>

</head>

<body>
<button onclick="buttonClick()">Publish</button>
</body>

</html>

0 comments on commit 3f5d4e9

Please sign in to comment.