mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-15 00:15:15 +08:00
35 lines
690 B
Plaintext
35 lines
690 B
Plaintext
@page
|
|
@model IndexModel
|
|
@{
|
|
ViewData["Title"] = "Home page";
|
|
}
|
|
|
|
<div>
|
|
<h1>MQTTnet ASP.NET Core Test App</h1>
|
|
</div>
|
|
|
|
<script src="https://unpkg.com/mqtt/dist/mqtt.min.js"></script>
|
|
|
|
<script>
|
|
const options = {
|
|
clean: true,
|
|
connectTimeout: 4000,
|
|
clientId: 'mqttnet_web_client'
|
|
}
|
|
|
|
const client = mqtt.connect('ws://localhost:5049/mqtt')
|
|
|
|
client.on('connect', function () {
|
|
console.log('Connected')
|
|
client.subscribe('#', function (err) {
|
|
if (!err) {
|
|
client.publish('test', 'Hello mqtt')
|
|
}
|
|
})
|
|
})
|
|
|
|
client.on('message', function (topic, message) {
|
|
console.log(message.toString())
|
|
})
|
|
</script>
|