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
dfef79c6
Commit
dfef79c6
authored
Apr 22, 2026
by
ZZH
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add stop event 2026-4-22 15:44
parent
0c04e7d4
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
2 deletions
+13
-2
meter_3rd.py
src/ems_water_grp/meter_3rd.py
+13
-2
No files found.
src/ems_water_grp/meter_3rd.py
View file @
dfef79c6
...
...
@@ -4,6 +4,7 @@ DATE:2026/4/22 14:58
"""
import
asyncio
import
signal
from
gmqtt
import
Client
as
MQTTClient
from
utils.utils
import
admin_client_id
...
...
@@ -24,6 +25,7 @@ class Meter3rdSrv:
def
__init__
(
self
):
self
.
mqtt_client
=
None
self
.
stop_event
=
asyncio
.
Event
()
@
staticmethod
def
on_subscribe
(
client
,
mid
,
qos
,
properties
):
...
...
@@ -41,12 +43,15 @@ class Meter3rdSrv:
@
staticmethod
def
on_message
(
client
,
topic
,
payload
,
qos
,
properties
):
payload
=
payload
.
decode
(
"utf-8"
)
logger
.
error
(
f
"Received message: topic={topic}, payload={payload}"
)
logger
.
info
(
f
"Received message: topic={topic}, payload={payload}"
)
async
def
stop
(
self
):
logger
.
info
(
"Shutting down Service..."
)
if
self
.
mqtt_client
:
await
self
.
mqtt_client
.
disconnect
()
self
.
stop_event
.
set
()
async
def
start
(
self
):
self
.
mqtt_client
=
MQTTClient
(
admin_client_id
(
"WaterGrpService"
))
self
.
mqtt_client
.
set_auth_credentials
(
MQTT_USER
,
MQTT_PWD
)
...
...
@@ -57,9 +62,15 @@ class Meter3rdSrv:
await
self
.
mqtt_client
.
connect
(
MQTT_BROKER
,
1883
)
await
self
.
stop_event
.
wait
()
async
def
main
():
srv
=
Meter3rdSrv
()
loop
=
asyncio
.
get_event_loop
()
for
sig
in
(
signal
.
SIGINT
,
signal
.
SIGTERM
):
loop
.
add_signal_handler
(
sig
,
lambda
:
asyncio
.
create_task
(
srv
.
stop
()))
await
srv
.
start
()
...
...
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