mirror of
https://codeberg.org/Far-Open-Auth.en-soln/mqttcsimpl/
synced 2024-08-14 23:53:51 +00:00
33 lines
779 B
HTML
33 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>
|