udrone/gui.html

47 lines
1.3 KiB
HTML
Raw Normal View History

2022-08-18 22:20:07 +03:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://cdn.jsdelivr.net/npm/relaxed-json@1.0.3/relaxed-json.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mqtt/4.3.7/mqtt.js" integrity="sha512-yX4jaiU9Ai9dzaimFoTq+tQYOrAMNP+EWiiUVsru3ypsAi76c0zCPBfxKagLkKjC4ZeLMEQTa7aE7CtjTmlgDA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
</head>
<body>
</body>
<script>
//const mqtt = require('mqtt')
const options = {
// Clean session
clean: true,
connectTimeout: 4000,
// Auth
clientId: 'emqx_test'
}
const client = mqtt.connect('ws://localhost:9001', options)
client.on('connect', function () {
console.log('Connected!')
client.subscribe('a1/#', function (err) {
if (!err) {
console.log('Subscribed!');
}
})
})
client.on('message', function (topic, message) {
let relaxedString = message.toString();
try {
let jsonString = RJSON.transform(relaxedString);
let obj = JSON.parse(jsonString);
console.log(topic, obj);
} catch {
console.log(relaxedString)
}
//client.end()
})
</script>
</html>