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
111596bd
Commit
111596bd
authored
Apr 24, 2026
by
ZZH
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix admin client id fmt 2026-4-24 16:06
parent
b93d4e1b
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
2 deletions
+28
-2
utils.py
src/utils/utils.py
+28
-2
No files found.
src/utils/utils.py
View file @
111596bd
...
...
@@ -15,7 +15,7 @@ logger = Logger.getLogger("utils")
def
admin_client_id
(
uid
):
host_str
=
socket
.
gethostbyname
(
socket
.
gethostname
())
.
replace
(
"."
,
"_"
)
return
f
"
/
eems/admin/{uid}@{host_str}_{os.getpid()}"
return
f
"eems/admin/{uid}@{host_str}_{os.getpid()}"
def
mqtt_pwd
(
username
):
...
...
@@ -31,6 +31,32 @@ def mqtt_pwd(username):
return
hashlib
.
sha1
(
username
.
encode
(
"utf-8"
))
.
hexdigest
()
def
conn_mqtt
():
def
on_connect
(
client
,
userdata
,
flags
,
rc
):
if
rc
==
0
:
print
(
f
"成功连接到 {SETTING.mqtt_host}!"
)
client
.
disconnect
()
else
:
print
(
f
"Failed to connect to MQTT broker. rc={rc}"
)
import
paho.mqtt.client
as
mqtt_client
username
=
"pot_emqx_super"
client_id
=
admin_client_id
(
"Meter3rdForward"
)
client
=
mqtt_client
.
Client
(
client_id
=
client_id
,
clean_session
=
True
)
client
.
username_pw_set
(
username
,
mqtt_pwd
(
username
))
client
.
on_connect
=
on_connect
print
(
f
"正在连接 {SETTING.mqtt_host}:{SETTING.mqtt_port} ..."
)
client
.
connect
(
SETTING
.
mqtt_host
,
SETTING
.
mqtt_port
)
try
:
client
.
loop_forever
()
except
KeyboardInterrupt
:
print
(
"
\n
测试已手动终止"
)
if
__name__
==
'__main__'
:
print
(
admin_client_id
(
"
admin
"
))
print
(
admin_client_id
(
"
Meter3rdForward
"
))
print
(
mqtt_pwd
(
"pot_emqx_super"
))
conn_mqtt
()
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