Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Z
z2m
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
xAAL
Code
Go
z2m
Commits
5b53098d
Commit
5b53098d
authored
2 months ago
by
KERDREUX Jerome
Browse files
Options
Downloads
Patches
Plain Diff
Fix Subscribe API / Cleaned jsonDump API
parent
f57b637f
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
mqtt.go
+7
-7
7 additions, 7 deletions
mqtt.go
utils.go
+2
-2
2 additions, 2 deletions
utils.go
xaal.go
+1
-1
1 addition, 1 deletion
xaal.go
with
10 additions
and
10 deletions
mqtt.go
+
7
−
7
View file @
5b53098d
...
...
@@ -31,13 +31,13 @@ func MQTTSetup(cfg *Config, publishHandler mqtt.MessageHandler) mqtt.Client {
return
client
}
func
MQTTSubscribe
(
client
mqtt
.
Client
,
cfg
*
Config
)
error
{
token
:=
client
.
Subscribe
(
cfg
.
topic
+
"/#"
,
0
,
nil
)
if
err
:=
token
.
Wait
();
token
.
Error
()
!=
nil
{
return
fmt
.
Errorf
(
"failed to subscribe to topic '%s/#': %v"
,
cfg
.
topic
,
err
)
func
MQTTSubscribe
(
client
mqtt
.
Client
,
cfg
*
Config
)
{
topic
:=
cfg
.
topic
+
"/#"
token
:=
client
.
Subscribe
(
topic
,
0
,
nil
)
if
token
.
Wait
();
token
.
Error
()
!=
nil
{
slog
.
Warn
(
"MQTTSubscribe failed"
,
"topic"
,
topic
,
"err"
,
token
.
Error
())
}
slog
.
Debug
(
"Subscribed to"
,
"Topic"
,
cfg
.
topic
+
"/#"
)
return
nil
slog
.
Debug
(
"Subscribed to"
,
"Topic"
,
topic
)
}
func
MQTTLostCnx
(
client
mqtt
.
Client
,
err
error
)
{
...
...
@@ -51,5 +51,5 @@ func MQTTDumpMsg(msg mqtt.Message) {
if
err
!=
nil
{
slog
.
Error
(
"Error decoding JSON %v"
,
"topic"
,
msg
.
Topic
(),
"err"
,
err
)
}
jsonDump
(
data
)
jsonDump
(
"MQTT update"
,
data
)
}
This diff is collapsed.
Click to expand it.
utils.go
+
2
−
2
View file @
5b53098d
...
...
@@ -24,7 +24,7 @@ func hexStringToInteger(hexString string) (uint64, error) {
return
integerValue
,
nil
}
func
jsonDump
(
data
map
[
string
]
interface
{})
{
func
jsonDump
(
title
string
,
data
map
[
string
]
interface
{})
{
// sort keys
keys
:=
make
([]
string
,
0
)
for
key
:=
range
data
{
...
...
@@ -33,7 +33,7 @@ func jsonDump(data map[string]interface{}) {
sort
.
Strings
(
keys
)
// dump keys
tab
:=
table
.
NewWriter
()
tab
.
SetTitle
(
"MQTT update"
)
tab
.
SetTitle
(
title
)
tab
.
SetStyle
(
table
.
StyleRounded
)
for
_
,
key
:=
range
keys
{
if
key
!=
"update"
{
...
...
This diff is collapsed.
Click to expand it.
xaal.go
+
1
−
1
View file @
5b53098d
...
...
@@ -526,5 +526,5 @@ func NewDebugDevice(addr uuid.UUID, zDev *Z2MDevice, exp *Expose) XAALDeviceInte
func
(
dev
*
DebugDevice
)
update
(
payload
map
[
string
]
interface
{})
{
slog
.
Info
(
"Debug Device update"
,
"payload"
,
payload
)
jsonDump
(
payload
)
jsonDump
(
"Debug Device update"
,
payload
)
}
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