diff --git a/src/modules/cl2/Cl23dObject.ts b/src/modules/cl2/Cl23dObject.ts index 8d92f4b..983aafc 100644 --- a/src/modules/cl2/Cl23dObject.ts +++ b/src/modules/cl2/Cl23dObject.ts @@ -356,39 +356,59 @@ export default class Cl23dObject extends THREE.Object3D { groupPillar.add(ptrForkMesh) this.add(groupPillar) - // try { - // // 安全连接配置 - // const client = mqtt.connect('mqtt://127.0.0.1:9001', { - // path: '/mqtt', - // clientId: 'virtual-' + item.id, - // clean: true, - // connectTimeout: 10000, - // username: 'user', - // password: 'user', - // unixSocket: true, - // keepalive: 60, - // }); + try { + // 安全连接配置 + const client = mqtt.connect('mqtt://127.0.0.1:9001', { + path: '/mqtt', + clientId: 'virtual-' + item.id, + clean: true, + connectTimeout: 10000, + username: 'user', + password: 'user', + unixSocket: true, + keepalive: 60, + }); + + const m20020 = { + "content": { + "CreateMonoTime": 233701185, + "CreateTime": 1750638957541, + "CurDirection": 1, + "CurLogicX": 13, + "CurLogicY": 10, + "CurOrientation": -3.1375624383367926, + "CurX": 13, + "CurY": 10, + "MarkerType": 1, + "SendTime": 1750638957541, + "SeqNo": 11, + "VehicleId": 10, + "X": 2652.477598132277, + "Y": 3944.4427159671854 + }, + "id": 20020 + } // 事件绑定 -// client.on('connect', () => { -// console.log('Connected'); -// client.subscribe(['/wcs_server/' + item.id], { qos: 0 }); -// client.publish('/agv_robot/status', 'online', { retain: true }); -// }); -// -// client.on('message', (topic, msg) => { -// console.log(`[${topic}] ${msg}`); -// const a = JSON.parse(msg.toString()); -// this.handleMessage(a); -// -// }); -// -// client.on('error', (error) => { -// console.error('Error:', error); -// }); -// } catch (e) { -// console.error(e) -// } + client.on('connect', () => { + console.log('Connected'); + client.subscribe(['/wcs_server/' + item.id], { qos: 0 }); + client.publish('/agv_robot/status', JSON.stringify(m20020), { retain: true }); + }); + + client.on('message', (topic, msg) => { + console.log(`[${topic}] ${msg}`); + const a = JSON.parse(msg.toString()); + this.handleMessage(a); + + }); + + client.on('error', (error) => { + console.error('Error:', error); + }); + } catch (e) { + console.error(e) + } }