mqttcsimpl/index.html
Captain Nick Lucifer* 01236ad8fb .
2023-03-12 12:24:20 +05:45

32 lines
779 B
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<title>Testing</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://unpkg.com/mqtt@4.3.7/dist/mqtt.min.js"></script> <!-- Load client mqtt via CDN. -->
</head>
<body>
<script type="module">
const mqtt = require('mqtt')
const client = mqtt.connect('mqtt://mosquitto.domain.tld') // testoo
client.on('connect', function () {
client.subscribe('presence', function (err) {
if (!err) {
client.publish('presence', 'Hello mqtt')
}
})
})
client.on('message', function (topic, message) {
// message is Buffer
console.log(message.toString())
client.end()
})
</script>
</body>
</html>