Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
universal_test_unit
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pepe
pepeunit
units
universal_test_unit
Commits
820c9827
Commit
820c9827
authored
8 months ago
by
Ivan Serebrennikov
Browse files
Options
Downloads
Patches
Plain Diff
feat(main): add log for input
parent
aeb85966
No related branches found
Branches containing commit
Tags
0.0.4
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
main.py
+18
-4
18 additions, 4 deletions
main.py
test.py
+0
-0
0 additions, 0 deletions
test.py
utils/utils.py
+10
-0
10 additions, 0 deletions
utils/utils.py
with
28 additions
and
4 deletions
main.py
+
18
−
4
View file @
820c9827
...
...
@@ -12,7 +12,7 @@ import zlib
from
paho.mqtt
import
client
as
mqtt_client
from
config
import
settings
from
utils.utils
import
get_unit_schema
,
get_unit_uuid
,
get_topic_split
,
get_unit_state
,
get_input_topics
,
pub_output_topic_by_name
from
utils.utils
import
get_unit_schema
,
get_unit_uuid
,
get_topic_split
,
get_unit_state
,
get_input_topics
,
pub_output_topic_by_name
,
search_topic_in_schema
def
connect_mqtt
():
...
...
@@ -91,9 +91,23 @@ def connect_mqtt():
logging
.
info
(
"
Schema is Updated
"
)
logging
.
info
(
"
I
'
ll be back
"
)
os
.
execl
(
sys
.
executable
,
*
([
sys
.
executable
]
+
sys
.
argv
))
else
:
print
(
struct_topic
)
print
(
msg
.
payload
.
decode
())
elif
len
(
struct_topic
)
==
3
:
schema_dict
=
get_unit_schema
()
topic_type
,
topic_name
=
search_topic_in_schema
(
schema_dict
,
struct_topic
[
1
])
if
topic_type
==
'
input_topic
'
and
topic_name
==
'
input/pepeunit
'
:
print
(
'
Success load input state
'
)
value
=
msg
.
payload
.
decode
()
value
=
int
(
value
)
with
open
(
'
log.json
'
,
'
w
'
)
as
f
:
f
.
write
(
json
.
loads
({
'
value
'
:
value
,
'
input_topic
'
:
struct_topic
}))
for
topic_name
in
schema_dict
[
'
output_topic
'
].
keys
():
pub_output_topic_by_name
(
client
,
schema_dict
[
'
output_topic
'
][
'
output/pepeunit
'
],
str
(
value
))
def
on_subscribe
(
client
,
userdata
,
mid
,
granted_qos
):
print
(
"
Subscribed:
"
+
str
(
mid
)
+
"
"
+
str
(
granted_qos
))
...
...
This diff is collapsed.
Click to expand it.
test.py
0 → 100644
+
0
−
0
View file @
820c9827
This diff is collapsed.
Click to expand it.
utils/utils.py
+
10
−
0
View file @
820c9827
...
...
@@ -56,3 +56,13 @@ def pub_output_topic_by_name(client, topic_name: str, message: str) -> None:
print
(
f
"
Send `
{
message
}
` to topic `
{
topic
}
`
"
)
else
:
print
(
f
"
Failed to send message to topic
{
topic
}
"
)
def
search_topic_in_schema
(
schema_dict
:
dict
,
node_uuid
:
str
)
->
tuple
[
str
,
str
]:
for
topic_type
in
schema_dict
.
keys
():
for
topic_name
in
schema_dict
[
topic_type
].
keys
():
for
topic
in
schema_dict
[
topic_type
][
topic_name
]:
if
topic
.
find
(
node_uuid
)
>=
0
:
return
(
topic_type
,
topic_name
)
raise
ValueError
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment