Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
E
ems_collector
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ZZH
ems_collector
Commits
eb80aa41
Commit
eb80aa41
authored
May 22, 2026
by
ZZH
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix meter data collector 2026-5-22 15:15
parent
e057286e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
5 deletions
+33
-5
helper.py
src/ems_water_grp/helper.py
+13
-0
meter_3rd.py
src/ems_water_grp/meter_3rd.py
+19
-4
aiomysql_util.py
src/infra/mysql/aiomysql_util.py
+1
-1
No files found.
src/ems_water_grp/helper.py
View file @
eb80aa41
...
...
@@ -3,6 +3,7 @@
DATE:2026/4/13 14:31
"""
from
infra.mysql.aiomysql_util
import
MysqlUtil
EMS_DEVS
=
[
# 荷坳水厂水光储一体化站
...
...
@@ -203,3 +204,15 @@ def transfer_realtime(pyd, datas):
tags
[
FIELD_MAP
[
equipmentType
][
brief_code
]]
=
r
[
"value"
]
rlt
[
"images"
]
=
[
dict
(
t
=
t
,
tags
=
tags
)]
return
rlt
async
def
load_mtype_from_sm
(
sid
):
async
with
MysqlUtil
(
"water_works"
)
as
conn
:
sql
=
f
"SELECT m_type from water_works.monitor WHERE sid=
%
s"
return
await
conn
.
fetch_value
(
sql
,
(
sid
,))
if
__name__
==
'__main__'
:
import
asyncio
asyncio
.
run
(
load_mtype_from_sm
(
"HA_JXG2"
))
src/ems_water_grp/meter_3rd.py
View file @
eb80aa41
...
...
@@ -12,6 +12,7 @@ from utils.time_format import CST, YMD_Hms
from
gmqtt
import
Client
as
MQTTClient
from
ems_water_grp.constants
import
SCADA_FIELDS_MAP
from
utils.utils
import
admin_client_id
,
mqtt_pwd
from
ems_water_grp.helper
import
load_mtype_from_sm
from
infra.config.settings
import
SETTING
from
infra.logger.logger
import
Logger
...
...
@@ -27,7 +28,7 @@ class Meter3rdForward:
sub_topic
=
"factory/data"
pub_username
=
"pot_emqx_super"
pub_topic_p
refi
x
=
"eems/td/"
pub_topic_p
f
x
=
"eems/td/"
def
__init__
(
self
):
self
.
client_sub
=
None
...
...
@@ -72,6 +73,16 @@ class Meter3rdForward:
except
Exception
as
e
:
logger
.
error
(
f
"Decode msg:{payload} error: {e}"
)
@
staticmethod
async
def
parse_topic
(
sid
):
m_type
=
await
load_mtype_from_sm
(
sid
)
if
m_type
:
if
m_type
==
137
:
return
"pcc_ele"
elif
m_type
==
136
:
return
"load_ele"
return
""
async
def
parse_and_forward
(
self
,
fid
,
raw_payload
):
""" 重新封装消息,推送至EMQX """
try
:
...
...
@@ -96,9 +107,13 @@ class Meter3rdForward:
cnt
=
0
for
sid
,
payload
in
d_pyds
.
items
():
logger
.
info
(
f
"{sid}: {payload}"
)
self
.
client_pub
.
publish
(
f
"{self.pub_topic_prefix}/load_ele/{sid}"
,
json
.
dumps
(
payload
),
qos
=
1
)
topic
=
await
self
.
parse_topic
(
sid
)
if
not
topic
:
logger
.
error
(
f
"Parse topic {sid} failed, pyd:{payload}"
)
continue
topic
=
f
"{self.pub_topic_pfx}/{topic}/{sid}"
self
.
client_pub
.
publish
(
topic
,
json
.
dumps
(
payload
),
qos
=
1
)
cnt
+=
1
logger
.
info
(
f
"forward fid:{fid} {cnt} msgs"
)
...
...
src/infra/mysql/aiomysql_util.py
View file @
eb80aa41
...
...
@@ -8,7 +8,7 @@ import asyncio
import
aiomysql
from
aiomysql
import
DictCursor
,
Cursor
from
infra.config.settings
import
SETTING
from
infra.logger
import
Logger
from
infra.logger
.logger
import
Logger
log_name
=
f
"aiomysql_util"
Logger
.
init_logger_path
(
f
"./common_util"
,
f
"{log_name}.log"
,
log_name
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment