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
7321a21d
Commit
7321a21d
authored
Jun 16, 2026
by
ZZH
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
opt 3rd data collector srv 2026-6-16 16:10
parent
dd7f0e02
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
22 deletions
+53
-22
ems.py
src/ems_water_grp/ems.py
+10
-6
meter_3rd.py
src/ems_water_grp/meter_3rd.py
+43
-16
No files found.
src/ems_water_grp/ems.py
View file @
7321a21d
...
@@ -362,7 +362,8 @@ async def tools():
...
@@ -362,7 +362,8 @@ async def tools():
"siteId"
:
185
,
"siteId"
:
185
,
"equipmentCode"
:
"SESBMS00003"
,
"equipmentCode"
:
"SESBMS00003"
,
"equipmentType"
:
244
,
"equipmentType"
:
244
,
"briefCodeList"
:
[
"StChargEng"
,
"StDischargEng"
,
"StCap"
,
"TotalVoltage"
]
"briefCodeList"
:
[
"StChargEng"
,
"StDischargEng"
,
"StCap"
,
"TotalVoltage"
]
}
}
pyd
,
rlt
=
await
api_client
.
fetch_realtime
(
pyd
)
pyd
,
rlt
=
await
api_client
.
fetch_realtime
(
pyd
)
print
(
"rlt"
,
rlt
)
print
(
"rlt"
,
rlt
)
...
@@ -371,11 +372,14 @@ async def tools():
...
@@ -371,11 +372,14 @@ async def tools():
async
def
main
():
async
def
main
():
try
:
while
True
:
srv
=
WaterGrpService
()
try
:
await
srv
.
start
()
srv
=
WaterGrpService
()
except
Exception
as
e
:
await
srv
.
start
()
logger
.
error
(
f
"Sync data fail, will retry next loop: {e}"
)
break
except
Exception
as
e
:
logger
.
error
(
f
"Sync data fail, will retry next loop: {e}"
)
await
asyncio
.
sleep
(
30
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
...
...
src/ems_water_grp/meter_3rd.py
View file @
7321a21d
...
@@ -141,13 +141,19 @@ class Meter3rdForward:
...
@@ -141,13 +141,19 @@ class Meter3rdForward:
async
def
stop
(
self
):
async
def
stop
(
self
):
logger
.
info
(
"Shutting down Meter3rdForward Service..."
)
logger
.
info
(
"Shutting down Meter3rdForward Service..."
)
if
self
.
client_sub
:
self
.
stop_event
.
set
()
await
self
.
client_sub
.
disconnect
()
if
self
.
client_pub
:
try
:
await
self
.
client_pub
.
disconnect
()
if
self
.
client_sub
:
await
self
.
client_sub
.
disconnect
()
except
Exception
:
pass
self
.
stop_event
.
set
()
try
:
if
self
.
client_pub
:
await
self
.
client_pub
.
disconnect
()
except
Exception
:
pass
async
def
start
(
self
):
async
def
start
(
self
):
self
.
client_sub
=
MQTTClient
(
admin_client_id
(
"Meter3rdForward"
))
self
.
client_sub
=
MQTTClient
(
admin_client_id
(
"Meter3rdForward"
))
...
@@ -162,23 +168,44 @@ class Meter3rdForward:
...
@@ -162,23 +168,44 @@ class Meter3rdForward:
self
.
client_pub
.
on_connect
=
self
.
on_pub_connect
self
.
client_pub
.
on_connect
=
self
.
on_pub_connect
self
.
client_pub
.
on_disconnect
=
self
.
on_pub_disconnect
self
.
client_pub
.
on_disconnect
=
self
.
on_pub_disconnect
await
asyncio
.
gather
(
loop
=
asyncio
.
get_running_loop
()
self
.
client_sub
.
connect
(
self
.
sub_host
,
1883
),
for
sig
in
(
signal
.
SIGINT
,
signal
.
SIGTERM
):
self
.
client_pub
.
connect
(
SETTING
.
mqtt_host
,
SETTING
.
mqtt_port
)
loop
.
add_signal_handler
(
sig
,
self
.
stop_event
.
set
)
)
while
not
self
.
stop_event
.
is_set
():
try
:
await
asyncio
.
gather
(
self
.
client_sub
.
connect
(
self
.
sub_host
,
1883
),
self
.
client_pub
.
connect
(
SETTING
.
mqtt_host
,
SETTING
.
mqtt_port
)
)
logger
.
info
(
"双向 MQTT 服务初始连接全部成功!"
)
break
except
Exception
as
e
:
logger
.
error
(
f
"MQTT 初始连接失败,30秒后重试:{e}"
)
await
asyncio
.
sleep
(
30
)
if
self
.
stop_event
.
is_set
():
return
asyncio
.
create_task
(
self
.
snapshot_sampler
())
asyncio
.
create_task
(
self
.
snapshot_sampler
())
await
self
.
stop_event
.
wait
()
logger
.
info
(
"Meter3rdForward 核心服务启动,等待退出信号..."
)
try
:
await
self
.
stop_event
.
wait
()
finally
:
await
self
.
stop
()
async
def
main
():
async
def
main
():
srv
=
Meter3rdForward
()
while
True
:
loop
=
asyncio
.
get_event_loop
()
try
:
for
sig
in
(
signal
.
SIGINT
,
signal
.
SIGTERM
):
srv
=
Meter3rdForward
()
loop
.
add_signal_handler
(
sig
,
lambda
:
asyncio
.
create_task
(
srv
.
stop
()))
await
srv
.
start
()
break
await
srv
.
start
()
except
Exception
as
e
:
logger
.
error
(
f
"转发服务发生致命异常,10秒后尝试重新初始化: {e}"
)
await
asyncio
.
sleep
(
10
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
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