no message

This commit is contained in:
MATRIX\29620 2025-01-16 18:55:20 +08:00
commit 70fdea9832
32 changed files with 2162 additions and 0 deletions

8
.idea/.gitignore generated vendored Normal file
View File

@ -0,0 +1,8 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

1
.idea/.name generated Normal file
View File

@ -0,0 +1 @@
SimTruckService.go

8
.idea/modules.xml generated Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/tms-simulate.iml" filepath="$PROJECT_DIR$/.idea/tms-simulate.iml" />
</modules>
</component>
</project>

19
.idea/remote-targets.xml generated Normal file
View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteTargetsManager">
<targets>
<target name="zzy@192.168.3.112:22" type="ssh/sftp" uuid="25307b42-9261-462d-8f3a-540aa232ca53">
<config>
<option name="projectRootOnTarget" value="/home/zzy/tms-simulate" />
<option name="serverName" value="zzy@192.168.3.112:22 password" />
</config>
<ContributedStateBase type="GoLanguageRuntime">
<config>
<option name="goPath" value="/opt/app/go" />
<option name="goRoot" value="/opt/app/go/bin" />
</config>
</ContributedStateBase>
</target>
</targets>
</component>
</project>

9
.idea/tms-simulate.iml generated Normal file
View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="Go" enabled="true" />
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

6
.idea/vcs.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

1
cmd/main.go Normal file
View File

@ -0,0 +1 @@
package core

1
config/config.go Normal file
View File

@ -0,0 +1 @@
package config

View File

@ -0,0 +1 @@
package controllers

View File

@ -0,0 +1 @@
package controllers

11
go.mod Normal file
View File

@ -0,0 +1,11 @@
module example.com/tms-simulate
go 1.23.4
require github.com/eclipse/paho.mqtt.golang v1.5.0
require (
github.com/gorilla/websocket v1.5.3 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/sync v0.7.0 // indirect
)

21
go.sum Normal file
View File

@ -0,0 +1,21 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/eclipse/paho.mqtt.golang v1.5.0 h1:EH+bUVJNgttidWFkLLVKaQPGmkTUfQQqjOsyvMGvD6o=
github.com/eclipse/paho.mqtt.golang v1.5.0/go.mod h1:du/2qNQVqJf/Sqs4MEL77kR8QTqANF7XU7Fk0aOTAgk=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/taosdata/driver-go/v3 v3.0.0/go.mod h1:lT4lpI3wo3hXRwP3nzm7xDs/YgYbw5YU58XingVlfsY=
golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=
golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

File diff suppressed because it is too large Load Diff

1
models/driver_status.go Normal file
View File

@ -0,0 +1 @@
package models

1
models/event.go Normal file
View File

@ -0,0 +1 @@
package models

1
models/route_point.go Normal file
View File

@ -0,0 +1 @@
package models

View File

@ -0,0 +1 @@
package models

1
models/truck.go Normal file
View File

@ -0,0 +1 @@
package models

1
routeG7干线.json Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

1
services/mqtt_service.go Normal file
View File

@ -0,0 +1 @@
package services

View File

@ -0,0 +1 @@
package services

BIN
target/tms_simulate.sh Normal file

Binary file not shown.

58
tmsTemplateAlarm.json Normal file
View File

@ -0,0 +1,58 @@
{
"12": [
{
"title": "报警状态",
"车牌": "蒙K123ER",
"time": "Time",
"pos": [89.153942, 44.757513],
"vin": "VIN",
"里程":"100",
"速度":"60",
"位置":"北京",
"车辆状态":"ACC正常",
"订单": "OrderID",
"type": "offline",
"状态": "离线"
},
{
"title": "报警状态",
"车牌": "蒙K123ER",
"time": "Time",
"pos": [89.174784, 44.78754],
"vin": "VIN",
"订单": "OrderID",
"type": "alarm",
"状态": "犯困"
},
{
"title": "报警状态",
"车牌": "蒙K123ER",
"time": "Time",
"pos": [89.316852, 44.762968],
"vin": "{{VIN}}",
"订单": "OrderID",
"type": "danger",
"状态": "车道偏离"
},
{
"title": "报警状态",
"车牌": "蒙K123ER",
"time": "Time",
"pos": [90.40854, 43.868251],
"vin": "VIN",
"订单": "OrderID",
"type": "stop",
"状态": "停车"
},
{
"title": "报警状态",
"车牌": "蒙K123ER",
"time": "Time",
"pos": [89.365738, 44.768674],
"vin": "VIN",
"订单": "OrderID",
"type": "danger",
"状态": "抽烟"
}
]
}

276
tmsTemplateroute1.json Normal file
View File

@ -0,0 +1,276 @@
{
"0":[
{
"title": "创建运单",
"车牌": "蒙K456ER",
"司机":"张三丰",
"vin": "LHGCM82633A004501",
"订单": "LD-TLXW-00007",
"运单": "PAC11AAP003576",
"货箱编号": "TRA1205B",
"净重吨数": 25.50,
"starttime":"2024-12-27 12:12:12",
"endtime":"2024-12-27 12:12:12",
"time":"2024-12-20 11:12:12",
"status": "已接单",
"线路类型":"支线",
"车辆类型":"H",
"线路": "G7线",
"起始陆港": "准东",
"from": "色连一矿",
"to": "河西电厂",
"时长": "00:00:36"
}
],
"1": [
{
"title": "司机未接单",
"tag": [
"App"
],
"msg": "司机 <司机 id='xxx' icon='xxx' phone='xxxxxxxx'>张三丰</司机> 未确认接单,等待时长<b>100s</b>。",
"车牌": "蒙K123ER",
"time": "2024-12-27 12:12:12",
"pos": [
123.456,
456.123
],
"vin": "LHGCM82633A004501",
"订单": "LD-TLXW-00006",
"运单": "PAC000000003",
"提煤单": "TMD0000003",
"时长": "00:01:40"
},
{
"title": "司机接单",
"tag": [
"秒接",
"App"
],
"msg": "司机 <司机 id='xxx' icon='xxx' phone='xxxxxxxx'>张三丰</司机> 确认接单,响应时长<b>36s</b>。",
"车牌": "蒙K123ER",
"time": "2024-12-27 12:12:12",
"pos": [
90.534388,
43.835499
],
"vin": "LHGCM82633A004501",
"订单": "LD-TLXW-00006",
"运单": "PAC000000003",
"提煤单": "TMD0000003",
"时长": "00:00:36"
},
{
"title": "司机接单",
"tag": [
"秒接",
"App"
],
"msg": "司机 <司机 id='xxx' icon='xxx' phone='xxxxxxxx'>张三丰</司机> 确认接单,响应时长<b>36s</b>。",
"车牌": "蒙K123ER",
"time": "2024-12-27 12:12:12",
"pos": [
90.534388,
43.835499
],
"vin": "LHGCM82633A004501",
"订单": "LD-TLXW-00006",
"运单": "PAC000000003",
"时长": "00:00:36"
}
],
"2": [
{
"title": "进陆港",
"msg": "<卡车>蒙K123ER</卡车> 进入<陆港>巴里坤&怪石山陆港</陆港>。",
"车牌": "蒙K123ER",
"time": "2024-12-27 12:12:12",
"pos": [
90.534388,
43.835499
],
"vin": "LHGCM82633A004501",
"订单": "LD-TLXW-00006",
"运单": "PAC000000003",
"电池容量": 160,
"前往区域": "A2"
}
],
"3": [
{
"title": "领取货箱",
"msg": "<卡车>蒙K123ER</卡车> 在 <陆港>巴里坤&怪石山陆港</陆港>领取货箱。",
"车牌": "蒙K123ER",
"time": "2024-12-27 12:12:12",
"pos": [
90.534388,
43.835499
],
"vin": "LHGCM82633A004501",
"订单": "LD-TLXW-00006",
"运单": "PAC000000003",
"货箱编号": "TRA1205B"
}
],
"4": [
{
"title": "出陆港",
"tag": [
"服务费",
"清分"
],
"msg": "<卡车>蒙K123ER</卡车> 在 <陆港>巴里坤&怪石山陆港</陆港>出陆港。",
"车牌": "蒙K123ER",
"time": "2024-12-27 12:12:12",
"pos": [
90.534388,
43.835499
],
"vin": "LHGCM82633A004501",
"订单": "LD-TLXW-00006",
"运单": "PAC000000003",
"货箱编号": "TRA1205B"
}
],
"5": [
{
"title": "收费站",
"tag": [
"ETC",
"往"
],
"msg": "<卡车>蒙K123ER</卡车> 进过包东线收费站。",
"车牌": "蒙K123ER",
"time": "2024-12-27 12:12:12",
"pos": [
90.534388,
43.835499
],
"vin": "LHGCM82633A004501",
"订单": "LD-TLXW-00006",
"运单": "PAC000000003",
"过路费": 23.00
}
],
"6": [
{
"title": "开始排队",
"msg": "<卡车>蒙K123ER</卡车> 进入<陆港>巴里坤&怪石山</陆港>排队区域预计排队25分钟。",
"车牌": "蒙K123ER",
"time": "2024-12-27 12:12:12",
"pos": [
90.534388,
43.835499
],
"vin": "LHGCM82633A004501",
"订单": "LD-TLXW-00006",
"运单": "PAC000000003",
"货箱编号": "TRA1205B",
"预计排队": "00:25:00",
"排队时长": "00:23:30"
}
],
"7": [
{
"title": "装运",
"tag": [
"运营费",
"App"
],
"msg": "<卡车>蒙K123ER</卡车> 装运完成。",
"车牌": "蒙K123ER",
"time": "2024-12-27 12:12:12",
"pos": [
90.534388,
43.835499
],
"vin": "LHGCM82633A004501",
"订单": "LD-TLXW-00006",
"运单": "PAC000000003",
"净重": 30.06,
"货箱编号": "TRA1205B",
"img": "xxxxxxx.png"
}
],
"8": [
{
"title": "收费站",
"tag": [
"反",
"清分"
],
"msg": "<卡车>蒙K123ER</卡车> 经过包东线收费站。",
"车牌": "蒙K123ER",
"time": "2024-12-27 12:12:12",
"pos": [
90.534388,
43.835499
],
"vin": "LHGCM82633A004501",
"订单": "LD-TLXW-00006",
"运单": "PAC000000003",
"过路费": 23.00
}
],
"9": [
{
"title": "进陆港",
"tag": [
"补能"
],
"msg": "<卡车'>蒙K123ER</卡车> 进入<陆港>巴里坤&怪石山陆港</陆港>。",
"车牌": "蒙K123ER",
"time": "2024-12-27 12:12:12",
"pos": [
90.534388,
43.835499
],
"vin": "LHGCM82633A004501",
"订单": "LD-TLXW-00006",
"运单": "PAC000000003",
"耗时": "02:08:00",
"电池容量": 60,
"前往区域": "B1"
}
],
"10": [
{
"title": "陆港卸货",
"tag": [
"补能"
],
"msg": "<卡车>蒙K123ER</卡车> 在<陆港>巴里坤&怪石山陆港</陆港>陆港甩箱。",
"车牌": "蒙K123ER",
"time": "2024-12-27 12:12:12",
"pos": [
90.534388,
43.835499
],
"vin": "LHGCM82633A004501",
"订单": "LD-TLXW-00006",
"运单": "PAC000000003",
"卸货区域": "B2",
"货箱编号": "TRA1205B"
}
],
"11": [
{
"title": "司机确认运单结束",
"tag": [
"清分"
],
"msg": "<卡车>蒙K123ER</卡车> 在<陆港>巴里坤&怪石山陆港</陆港>陆港结束运单。",
"车牌": "蒙K123ER",
"time": "2024-12-27 12:12:12",
"pos": [
90.534388,
43.835499
],
"vin": "LHGCM82633A004501",
"订单": "LD-TLXW-00006",
"运单": "PAC000000003",
"运单总耗时": "03:17:00",
"能耗": 127
}
]
}

276
tmsTemplateroute2.json Normal file
View File

@ -0,0 +1,276 @@
{
"0":[
{
"title": "创建运单",
"车牌": "蒙K456ER",
"司机": "张三丰",
"vin": "LHGCM82633A004501",
"订单": "LD-TLXW-00007",
"运单": "PAC11AAP003576",
"货箱编号": "TRA1205B",
"净重吨数": 25.50,
"starttime": "2024-12-27 12:12:12",
"endtime": "2024-12-27 12:12:12",
"time": "2024-12-27 12:12:12",
"status": "已接单",
"线路类型": "干线",
"车辆类型": "E",
"线路": "G7线",
"起始陆港": "准东",
"from": "色连一矿",
"to": "河西电厂",
"时长": "00:00:36"
}
],
"1": [
{
"title": "司机未接单",
"tag": [
"App"
],
"msg": "司机 <司机 id='xxx' icon='xxx' phone='xxxxxxxx'>张三丰</司机> 未确认接单,等待时长<b>100s</b>。",
"车牌": "蒙K123ER",
"time": "2024-12-27 12:12:12",
"pos": [
90.534388,
43.835499
],
"vin": "LHGCM82633A004501",
"订单": "LD-TLXW-00006",
"运单": "PAC000000003",
"提煤单": "TMD0000003",
"时长": "00:01:40"
},
{
"title": "司机接单",
"tag": [
"秒接",
"App"
],
"msg": "司机 <司机 id='xxx' icon='xxx' phone='xxxxxxxx'>张三丰</司机> 确认接单,响应时长<b>36s</b>。",
"车牌": "蒙K123ER",
"time": "2024-12-27 12:12:12",
"pos": [
90.534388,
43.835499
],
"vin": "LHGCM82633A004501",
"订单": "LD-TLXW-00006",
"运单": "PAC000000003",
"提煤单": "TMD0000003",
"时长": "00:00:36"
},
{
"title": "司机接单",
"tag": [
"秒接",
"App"
],
"msg": "司机 <司机 id='xxx' icon='xxx' phone='xxxxxxxx'>张三丰</司机> 确认接单,响应时长<b>36s</b>。",
"车牌": "蒙K123ER",
"time": "2024-12-27 12:12:12",
"pos": [
90.534388,
43.835499
],
"vin": "LHGCM82633A004501",
"订单": "LD-TLXW-00006",
"运单": "PAC000000003",
"时长": "00:00:36"
}
],
"2": [
{
"title": "进陆港",
"msg": "<卡车>蒙K123ER</卡车> 进入<陆港>巴里坤&怪石山陆港</陆港>。",
"车牌": "蒙K123ER",
"time": "2024-12-27 12:12:12",
"pos": [
90.534388,
43.835499
],
"vin": "LHGCM82633A004501",
"订单": "LD-TLXW-00006",
"运单": "PAC000000003",
"电池容量": 160,
"前往区域": "A2"
}
],
"3": [
{
"title": "领取货箱",
"msg": "<卡车>蒙K123ER</卡车> 在 <陆港>巴里坤&怪石山陆港</陆港>领取货箱。",
"车牌": "蒙K123ER",
"time": "2024-12-27 12:12:12",
"pos": [
90.534388,
43.835499
],
"vin": "LHGCM82633A004501",
"订单": "LD-TLXW-00006",
"运单": "PAC000000003",
"货箱编号": "TRA1205B"
}
],
"4": [
{
"title": "出陆港",
"tag": [
"服务费",
"清分"
],
"msg": "<卡车>蒙K123ER</卡车> 在 <陆港>巴里坤&怪石山陆港</陆港>出陆港。",
"车牌": "蒙K123ER",
"time": "2024-12-27 12:12:12",
"pos": [
90.534388,
43.835499
],
"vin": "LHGCM82633A004501",
"订单": "LD-TLXW-00006",
"运单": "PAC000000003",
"货箱编号": "TRA1205B"
}
],
"5": [
{
"title": "收费站",
"tag": [
"ETC",
"往"
],
"msg": "<卡车>蒙K123ER</卡车> 进过包东线收费站。",
"车牌": "蒙K123ER",
"time": "2024-12-27 12:12:12",
"pos": [
90.534388,
43.835499
],
"vin": "LHGCM82633A004501",
"订单": "LD-TLXW-00006",
"运单": "PAC000000003",
"过路费": 23.00
}
],
"6": [
{
"title": "开始排队",
"msg": "<卡车>蒙K123ER</卡车> 进入<陆港>巴里坤&怪石山</陆港>排队区域预计排队25分钟。",
"车牌": "蒙K123ER",
"time": "2024-12-27 12:12:12",
"pos": [
90.534388,
43.835499
],
"vin": "LHGCM82633A004501",
"订单": "LD-TLXW-00006",
"运单": "PAC000000003",
"货箱编号": "TRA1205B",
"预计排队": "00:25:00",
"排队时长": "00:23:30"
}
],
"7": [
{
"title": "装运",
"tag": [
"运营费",
"App"
],
"msg": "<卡车>蒙K123ER</卡车> 装运完成。",
"车牌": "蒙K123ER",
"time": "2024-12-27 12:12:12",
"pos": [
90.534388,
43.835499
],
"vin": "LHGCM82633A004501",
"订单": "LD-TLXW-00006",
"运单": "PAC000000003",
"净重": 30.06,
"货箱编号": "TRA1205B",
"img": "xxxxxxx.png"
}
],
"8": [
{
"title": "收费站",
"tag": [
"反",
"清分"
],
"msg": "<卡车>蒙K123ER</卡车> 经过包东线收费站。",
"车牌": "蒙K123ER",
"time": "2024-12-27 12:12:12",
"pos": [
90.534388,
43.835499
],
"vin": "LHGCM82633A004501",
"订单": "LD-TLXW-00006",
"运单": "PAC000000003",
"过路费": 23.00
}
],
"9": [
{
"title": "进陆港",
"tag": [
"补能"
],
"msg": "<卡车'>蒙K123ER</卡车> 进入<陆港>巴里坤&怪石山陆港</陆港>。",
"车牌": "蒙K123ER",
"time": "2024-12-27 12:12:12",
"pos": [
90.534388,
43.835499
],
"vin": "LHGCM82633A004501",
"订单": "LD-TLXW-00006",
"运单": "PAC000000003",
"耗时": "02:08:00",
"电池容量": 60,
"前往区域": "B1"
}
],
"10": [
{
"title": "陆港卸货",
"tag": [
"补能"
],
"msg": "<卡车>蒙K123ER</卡车> 在<陆港>巴里坤&怪石山陆港</陆港>陆港甩箱。",
"车牌": "蒙K123ER",
"time": "2024-12-27 12:12:12",
"pos": [
90.534388,
43.835499
],
"vin": "LHGCM82633A004501",
"订单": "LD-TLXW-00006",
"运单": "PAC000000003",
"卸货区域": "B2",
"货箱编号": "TRA1205B"
}
],
"11": [
{
"title": "司机确认运单结束",
"tag": [
"清分"
],
"msg": "<卡车>蒙K123ER</卡车> 在<陆港>巴里坤&怪石山陆港</陆港>陆港结束运单。",
"车牌": "蒙K123ER",
"time": "2024-12-27 12:12:12",
"pos": [
90.534388,
43.835499
],
"vin": "LHGCM82633A004501",
"订单": "LD-TLXW-00006",
"运单": "PAC000000003",
"运单总耗时": "03:17:00",
"能耗": 127
}
]
}

1
utils/helper.go Normal file
View File

@ -0,0 +1 @@
package utils

1
utils/logger.go Normal file
View File

@ -0,0 +1 @@
package utils

47
vehicle_receive.html Normal file
View File

@ -0,0 +1,47 @@
<!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_a11233',//确保全局唯一
username:'emqx_test',
password:'emqx_test'
}
const connectUrl = 'ws://123.6.102.119:8083/mqtt'
const client = mqtt.connect(connectUrl, options)
client.on('connect', (error) => {
console.log('连接:', error)
client.subscribe('vehicle/#',{},function(e){//监听所有车辆数据若仅仅监听位置vehicle/position
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>

48
vehicle_receive2.html Normal file
View File

@ -0,0 +1,48 @@
<!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>