提交 94f15b04 authored 作者: 陈泽健's avatar 陈泽健

2024-10-23

   - 优化安卓信息模块代码,MQTT一次性上报csv文件中的每行数据,并重复执行上报。
   - 了解清楚安卓信息的状态判断,后续将调试redis连接以及将键值对存入redis。
上级 ef4f2f62
......@@ -5,11 +5,11 @@
</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.py" beforeDir="false" afterPath="$PROJECT_DIR$/预定系统/base/Mqtt_Android.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/预定系统/base/Mqtt_Android.py" beforeDir="false" afterPath="$PROJECT_DIR$/预定系统/base/Mqtt_Android.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/预定系统/安卓信息模块/安卓信息上报.py" beforeDir="false" afterPath="$PROJECT_DIR$/预定系统/安卓信息模块/安卓信息上报.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/预定系统/测试数据/MQTT上报数据.csv" beforeDir="false" afterPath="$PROJECT_DIR$/预定系统/测试数据/MQTT上报数据.csv" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
......@@ -34,22 +34,22 @@
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"Python 测试.Python 测试 (LoginBy_ActAndPwd_PyTest.py 内).executor": "Run",
"Python.安卓信息上报.executor": "Run",
"RunOnceActivity.ShowReadmeOnStart": "true",
"git-widget-placeholder": "develop",
"last_opened_file_path": "D:/GithubData/ubains-module-test/ubains-module-test",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)",
"node.js.selected.package.tslint": "(autodetect)",
"nodejs_package_manager_path": "npm",
"settings.editor.selected.configurable": "com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable",
"vue.rearranger.settings.migration": "true"
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;Python 测试.Python 测试 (LoginBy_ActAndPwd_PyTest.py 内).executor&quot;: &quot;Run&quot;,
&quot;Python.安卓信息上报.executor&quot;: &quot;Run&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;git-widget-placeholder&quot;: &quot;develop&quot;,
&quot;last_opened_file_path&quot;: &quot;D:/GithubData/ubains-module-test/ubains-module-test&quot;,
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
&quot;settings.editor.selected.configurable&quot;: &quot;com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable&quot;,
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
}
}]]></component>
}</component>
<component name="RecentsManager">
<key name="MoveFile.RECENT_KEYS">
<recent name="D:\GithubData\ubains-module-test\ubains-module-test\预定系统\登录模块" />
......@@ -108,6 +108,8 @@
<workItem from="1728380017193" duration="171000" />
<workItem from="1729481397357" duration="2465000" />
<workItem from="1729519480013" duration="13278000" />
<workItem from="1729685636638" duration="4482000" />
<workItem from="1729690521898" duration="160000" />
</task>
<servers />
</component>
......@@ -125,6 +127,6 @@
</breakpoint-manager>
</component>
<component name="com.intellij.coverage.CoverageDataManagerImpl">
<SUITE FILE_PATH="coverage/ubains_module_test$.coverage" NAME="安卓信息上报 覆盖结果" MODIFIED="1729604974439" 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="1729688892458" 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
......@@ -7,4 +7,7 @@
2. 2024-10-22
- 补充安卓信息模块的Mqtt主题上报以及接收脚本,但目前安卓信息上报后系统界面仍显示为离线。需进一步了解业务流后进行调试。后续完整多个安卓信息上报实现大量设备同时在线的功能验证。
- 将安卓信息上报的MQTT相关函数封装到base目录下,方便后续调用以及维护管理。
- 将MQTT上报消息通过csv进行读取,方便后续维护。
\ No newline at end of file
- 将MQTT上报消息通过csv进行读取,方便后续维护。
3. 2024-10-23
- 优化安卓信息模块代码,MQTT一次性上报csv文件中的每行数据,并重复执行上报。
- 了解清楚安卓信息的状态判断,后续将调试redis连接以及将键值对存入redis。
\ No newline at end of file
# Mqtt.py
# -*- coding: utf-8 -*-
# cython: language_level=3
import json
import logging
import csv
......@@ -185,7 +182,7 @@ class Mqtt:
})
}
def send_and_receive_messages(self, topic, message, num_times=50, timeout=5, interval=0.2):
def send_and_receive_messages(self, topic, message, num_times=1, timeout=5, interval=0.2):
"""
发送并接收消息
......
......@@ -4,6 +4,7 @@
from 预定系统.base.Mqtt_Android import Mqtt
from datetime import datetime
import logging
import time
if __name__ == "__main__":
# 读取配置文件
......@@ -12,25 +13,37 @@ if __name__ == "__main__":
broker_address = "192.168.5.218"
port = 1883
topic = "rebootResponseTopic"
num_repeats = 100 # 重复执行的次数
interval_between_repeats = 0.5 # 每次重复之间的间隔时间(秒)
# 创建MQTT客户端实例
# 创建 MQTT 客户端实例
mqtt_client = Mqtt(broker_address, port)
try:
# 连接到MQTT服务器
# 连接到 MQTT 服务器
mqtt_client.connect()
# 订阅主题
mqtt_client.subscribe(topic)
for repeat in range(num_repeats):
logging.info(f"开始第 {repeat + 1} 次上报")
# 遍历每行配置数据
for config in configs:
current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
message = Mqtt.build_message(config, current_time)
mqtt_client.send_and_receive_messages(topic, message)
# 遍历配置文件中的每一行数据
for config in configs:
# 构建消息内容
current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
message = Mqtt.build_message(config, current_time)
# 发送消息
mqtt_client.publish(topic, message)
# 每次发送之间可以设置一个间隔时间
time.sleep(0.2)
# 每次重复之间设置一个间隔时间
time.sleep(interval_between_repeats)
except Exception as e:
logging.error(f"连接或订阅MQTT服务器时发生错误: {e}")
logging.error(f"发送消息时发生错误: {e}")
finally:
# 断开连接
# 断开与 MQTT 服务器的连接
mqtt_client.disconnect()
clientId,appToken,companyNumber,cnum,conferenceId,macAddress,authCode
48134e6047a19aaf,AND-8AJ-0025,CN-8AJ-UBAINS,058862a06633b59aa0fe3fe3c27e711b,219,20:59:20:00:28:87,AND-8AJ-0025
48134e6047a19aac,AND-8AJ-0026,CN-8AJ-UBAINS,9arvn9am36cjzlimxm4ojd9xzdzusaup,219,20:59:20:00:28:88,AND-8AJ-0026
\ No newline at end of file
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
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论