tms-simulate/vehicle_receive2.html
2025-01-16 18:55:20 +08:00

48 lines
1.2 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>通过socket接收实时车辆数据假车</title>
<script src="https://unpkg.com/mqtt/dist/mqtt.min.js"></script>
<script>
const options ={
clientId:'mqttjs_a13',
username:'emqx_test',
password:'emqx_test'
}
const connectUrl = 'ws://192.168.3.112:8083/mqtt'
const client = mqtt.connect(connectUrl, options)
client.on('connect', (error) => {
console.log('连接:', error)
client.subscribe('vehicle/sim/data',{},function(e){
console.log(e)
})
})
client.on('reconnect', (error) => {
console.log('正在重连:', error)
})
client.on('error', (error) => {
console.log('连接失败:', error)
})
client.on('message', (topic, message) => {
console.log('收到消息:', topic, message.toString())
})
</script>
</head>
<body>
假车
<a href="https://docs.emqx.com/zh/emqx/latest/connect-emqx/javascript.html">使用 JavaScript SDK 连接EMQX</a>
</body>
</html>