提交 949209b5 authored 作者: 陈泽健's avatar 陈泽健

2024-10-24

   - 优化MQTT底层方法,通过判断topic的值来发送不同的消息体。
   - 优化安卓信息上报.py脚本通过读配置文件中的topic,调用build_message时传入topic进行主题判断。后续方便进行MQTT主题与消息体的管理。
上级 94f15b04
......@@ -5,6 +5,7 @@
</component>
<component name="ChangeListManager">
<list default="true" id="1b298f03-b3a2-4f3f-9fa2-7f833ec35924" name="更改" comment="">
<change afterPath="$PROJECT_DIR$/预定系统/测试数据/MQTT心跳上报.csv" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/预定系统/README.md" beforeDir="false" afterPath="$PROJECT_DIR$/预定系统/README.md" afterDir="false" />
<change beforePath="$PROJECT_DIR$/预定系统/base/Mqtt_Android.py" beforeDir="false" afterPath="$PROJECT_DIR$/预定系统/base/Mqtt_Android.py" afterDir="false" />
......@@ -109,7 +110,7 @@
<workItem from="1729481397357" duration="2465000" />
<workItem from="1729519480013" duration="13278000" />
<workItem from="1729685636638" duration="4482000" />
<workItem from="1729690521898" duration="160000" />
<workItem from="1729690521898" duration="1942000" />
</task>
<servers />
</component>
......@@ -127,6 +128,6 @@
</breakpoint-manager>
</component>
<component name="com.intellij.coverage.CoverageDataManagerImpl">
<SUITE FILE_PATH="coverage/ubains_module_test$.coverage" NAME="安卓信息上报 覆盖结果" MODIFIED="1729688892458" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/预定系统/安卓信息模块" />
<SUITE FILE_PATH="coverage/ubains_module_test$.coverage" NAME="安卓信息上报 覆盖结果" MODIFIED="1729740841195" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/预定系统/安卓信息模块" />
</component>
</project>
\ No newline at end of file
......@@ -10,4 +10,7 @@
- 将MQTT上报消息通过csv进行读取,方便后续维护。
3. 2024-10-23
- 优化安卓信息模块代码,MQTT一次性上报csv文件中的每行数据,并重复执行上报。
- 了解清楚安卓信息的状态判断,后续将调试redis连接以及将键值对存入redis。
\ No newline at end of file
- 了解清楚安卓信息的状态判断,后续将调试redis连接以及将键值对存入redis。
4. 2024-10-24
- 优化MQTT底层方法,通过判断topic的值来发送不同的消息体。
- 优化安卓信息上报.py脚本通过读配置文件中的topic,调用build_message时传入topic进行主题判断。后续方便进行MQTT主题与消息体的管理。
\ No newline at end of file
......@@ -5,6 +5,8 @@ from time import sleep
from datetime import datetime
import paho.mqtt.client as mqtt
from 运维集控.项目测试.国信证券.用户管理.发送设备信息_ZXB import topic
# 配置日志
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
......@@ -119,7 +121,7 @@ class Mqtt:
return list(reader)
@staticmethod
def build_message(config, current_time):
def build_message(config, current_time,topic):
"""
构建消息内容
......@@ -127,60 +129,70 @@ class Mqtt:
:param current_time: 当前时间
:return: 消息字典
"""
return {
"method": "/system/readSystemInfo",
"clientId": config['clientId'],
"result": json.dumps({
"result": {
"buildInfo": {
"appToken": config['appToken'],
"companyNumber": config['companyNumber'],
"cnum": config['cnum'],
"conferenceName": "测试会议室",
"conferenceId": int(config['conferenceId']),
"defaultQrCodeUrl": "http://192.168.5.218:8888/group1/M00/00/21/wKgFyGNBWZmADtnNAAAwrxR0X8s016.png",
"aliasName": "zt",
"serverBaseUrl": "http://192.168.5.218:8996/",
"localBindTime": current_time,
"generalField": "{\"conferencePhone\":\"\",\"chooseTimeType\":1,\"meetingTopicSwitch\":\"1\",\"meetingContentSwitch\":\"1\",\"meetingReverseTypeSwitch\":\"1\",\"seatArrangeSwitch\":\"1\",\"meetingVoteSwitch\":\"1\",\"floorPlanPath\":\"\",\"jumpToPaperless\":2,\"approvalList\":[],\"isLeaderJoin\":false,\"meetingPublishScreenSwitch\":\"1\"}"
},
"faceVersion": "4.2.12021020201.1",
"wgtVersion": "0.0.81",
"deviceModel": "yx_rk3288",
"abiList": ["armeabi-v7a", "armeabi"],
"androidId": "48134e6047a19aaf",
"appName": "UBAINS",
"appPackageName": "com.ubains.local.gviewer",
"appVersion": 78,
"appVersionName": "1.1.78",
"battery": 0,
"bluetoothEnabled": False,
"camerasCount": 1,
"charging": True,
"density": 1,
"freeAndTotalMemory": "1176M/1997M",
"internalAvailableSize": 4306395136,
"internalTotalSize": 4877451264,
"ipAddress": "192.168.5.129",
"macAddress": config['macAddress'],
"networkType": "NETWORK_ETHERNET",
"processCpuUsage": "0.82%",
"resolution": "1280x800",
"romName": "rockchip",
"rooted": True,
"sdkVersionCode": 25,
"sdkVersionName": "7.1.2",
"sysDate": "Tue Oct 22 18:24:52 GMT+08:00 2024",
"sysDateStr": current_time,
"sysElapsedRealtime": "342:26:11",
"sysLanguage": "zh",
"sysSupportedSensors": ["Accelerometer sensor", "Gyroscope sensor", "Game Rotation Vector Sensor",
"Gravity Sensor"],
"authCode": config['authCode'],
"conferenceName": "测试会议室"
}
if topic == "rebootResponseTopic":
return {
"method": "/system/readSystemInfo",
"clientId": config['clientId'],
"result": json.dumps({
"result": {
"buildInfo": {
"appToken": config['appToken'],
"companyNumber": config['companyNumber'],
"cnum": config['cnum'],
"conferenceName": "测试会议室",
"conferenceId": int(config['conferenceId']),
"defaultQrCodeUrl": "http://192.168.5.218:8888/group1/M00/00/21/wKgFyGNBWZmADtnNAAAwrxR0X8s016.png",
"aliasName": "zt",
"serverBaseUrl": "http://192.168.5.218:8996/",
"localBindTime": current_time,
"generalField": "{\"conferencePhone\":\"\",\"chooseTimeType\":1,\"meetingTopicSwitch\":\"1\",\"meetingContentSwitch\":\"1\",\"meetingReverseTypeSwitch\":\"1\",\"seatArrangeSwitch\":\"1\",\"meetingVoteSwitch\":\"1\",\"floorPlanPath\":\"\",\"jumpToPaperless\":2,\"approvalList\":[],\"isLeaderJoin\":false,\"meetingPublishScreenSwitch\":\"1\"}"
},
"faceVersion": "4.2.12021020201.1",
"wgtVersion": "0.0.81",
"deviceModel": "yx_rk3288",
"abiList": ["armeabi-v7a", "armeabi"],
"androidId": "48134e6047a19aaf",
"appName": "UBAINS",
"appPackageName": "com.ubains.local.gviewer",
"appVersion": 78,
"appVersionName": "1.1.78",
"battery": 0,
"bluetoothEnabled": False,
"camerasCount": 1,
"charging": True,
"density": 1,
"freeAndTotalMemory": "1176M/1997M",
"internalAvailableSize": 4306395136,
"internalTotalSize": 4877451264,
"ipAddress": "192.168.5.129",
"macAddress": config['macAddress'],
"networkType": "NETWORK_ETHERNET",
"processCpuUsage": "0.82%",
"resolution": "1280x800",
"romName": "rockchip",
"rooted": True,
"sdkVersionCode": 25,
"sdkVersionName": "7.1.2",
"sysDate": "Tue Oct 22 18:24:52 GMT+08:00 2024",
"sysDateStr": current_time,
"sysElapsedRealtime": "342:26:11",
"sysLanguage": "zh",
"sysSupportedSensors": ["Accelerometer sensor", "Gyroscope sensor",
"Game Rotation Vector Sensor",
"Gravity Sensor"],
"authCode": config['authCode'],
"conferenceName": "测试会议室"
}
})
}
elif topic == "/uams/android/broadcast":
return json.dumps({
"type":"heartbeat",
"clientId" : config['clientId'],
"appId":"com.ubains.uniplatform",
"deviceId": config['deviceId']
})
}
def send_and_receive_messages(self, topic, message, num_times=1, timeout=5, interval=0.2):
"""
......
# main.py
# -*- coding: utf-8 -*-
# cython: language_level=3
from 预定系统.base.Mqtt_Android import Mqtt
from datetime import datetime
import logging
......@@ -8,13 +5,13 @@ import time
if __name__ == "__main__":
# 读取配置文件
configs = Mqtt.read_config_from_csv('../测试数据/MQTT上报数据.csv')
configs = Mqtt.read_config_from_csv('../测试数据/MQTT心跳上报.csv')
broker_address = "192.168.5.218"
port = 1883
topic = "rebootResponseTopic"
# topic = "rebootResponseTopic"
num_repeats = 100 # 重复执行的次数
interval_between_repeats = 0.5 # 每次重复之间的间隔时间(秒)
interval_between_repeats = 0.2 # 每次重复之间的间隔时间(秒)
# 创建 MQTT 客户端实例
mqtt_client = Mqtt(broker_address, port)
......@@ -29,8 +26,9 @@ if __name__ == "__main__":
# 遍历配置文件中的每一行数据
for config in configs:
# 构建消息内容
topic = config["topic"]
current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
message = Mqtt.build_message(config, current_time)
message = Mqtt.build_message(config, current_time, topic)
# 发送消息
mqtt_client.publish(topic, message)
......
clientId,appToken,companyNumber,cnum,conferenceId,macAddress,authCode
48134e6047a19aaf,AND-8AJ-0021,CN-8AJ-UBAINS,22tcji1m49t45ro0r3zyaj0zqd1863yh,219,20:59:20:00:28:81,AND-8AJ-0021
48134e6047a19aac,AND-8AJ-0022,CN-8AJ-UBAINS,9arvn9am36cjzlimxm4ojd9xzdzusaup,219,20:59:20:00:28:82,AND-8AJ-0022
48134e6047a19aab,AND-8AJ-0023,CN-8AJ-UBAINS,v3ydnq9u34ocunzanac6l3q8atkvvic3,219,20:59:20:00:28:83,AND-8AJ-0023
48134e6047a19aaz,AND-8AJ-0024,CN-8AJ-UBAINS,r8xvvvs4r7hhzhfi4i2zldoxoe4estss,219,20:59:20:00:28:84,AND-8AJ-0024
48134e6047a19aax,AND-8AJ-0025,CN-8AJ-UBAINS,r8xvvvs4r7hhzhfi4i2zldoxoe4estss,219,20:59:20:00:28:85,AND-8AJ-0025
\ No newline at end of file
topic,clientId,appToken,companyNumber,cnum,conferenceId,macAddress,authCode
rebootResponseTopic,48134e6047a19aaf,AND-8AJ-0021,CN-8AJ-UBAINS,22tcji1m49t45ro0r3zyaj0zqd1863yh,219,20:59:20:00:28:81,AND-8AJ-0021
rebootResponseTopic,48134e6047a19aac,AND-8AJ-0022,CN-8AJ-UBAINS,9arvn9am36cjzlimxm4ojd9xzdzusaup,219,20:59:20:00:28:82,AND-8AJ-0022
rebootResponseTopic,48134e6047a19aab,AND-8AJ-0023,CN-8AJ-UBAINS,v3ydnq9u34ocunzanac6l3q8atkvvic3,219,20:59:20:00:28:83,AND-8AJ-0023
rebootResponseTopic,48134e6047a19aaz,AND-8AJ-0024,CN-8AJ-UBAINS,r8xvvvs4r7hhzhfi4i2zldoxoe4estss,219,20:59:20:00:28:84,AND-8AJ-0024
rebootResponseTopic,48134e6047a19aax,AND-8AJ-0025,CN-8AJ-UBAINS,r8xvvvs4r7hhzhfi4i2zldoxoe4estss,219,20:59:20:00:28:85,AND-8AJ-0025
\ No newline at end of file
topic,clientId,deviceId
/uams/android/broadcast,48134e6047a19aaf,aa44e258a4e1e571
/uams/android/broadcast,48134e6047a19aac,aa44e258a4e1e572
/uams/android/broadcast,48134e6047a19aab,aa44e258a4e1e573
/uams/android/broadcast,48134e6047a19aaz,aa44e258a4e1e574
/uams/android/broadcast,48134e6047a19aax,aa44e258a4e1e575
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论