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
7c43f932
Commit
7c43f932
authored
5 months ago
by
KERDREUX Jerome
Browse files
Options
Downloads
Patches
Plain Diff
Removing mqttTopic gobal in progress
parent
15f29f20
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
main.go
+1
-1
1 addition, 1 deletion
main.go
mqtt.go
+2
-2
2 additions, 2 deletions
mqtt.go
xaal.go
+2
-2
2 additions, 2 deletions
xaal.go
z2m.go
+2
-2
2 additions, 2 deletions
z2m.go
with
7 additions
and
7 deletions
main.go
+
1
−
1
View file @
7c43f932
...
@@ -15,7 +15,7 @@ func main() {
...
@@ -15,7 +15,7 @@ func main() {
// spew.Dump(cfg)
// spew.Dump(cfg)
xaal
.
SetupLogger
()
xaal
.
SetupLogger
()
client
:=
mqttSetup
(
cfg
.
brokerHost
,
cfg
.
brokerPort
)
client
:=
mqttSetup
(
cfg
.
brokerHost
,
cfg
.
brokerPort
,
cfg
.
topic
)
eng
:=
xaal
.
NewEngine
()
eng
:=
xaal
.
NewEngine
()
gw
:=
NewGW
(
client
,
cfg
)
gw
:=
NewGW
(
client
,
cfg
)
...
...
This diff is collapsed.
Click to expand it.
mqtt.go
+
2
−
2
View file @
7c43f932
...
@@ -11,7 +11,7 @@ import (
...
@@ -11,7 +11,7 @@ import (
)
)
// mqttSetup creates a new MQTT client
// mqttSetup creates a new MQTT client
func
mqttSetup
(
mqttBroker
string
,
port
int
)
MQTT
.
Client
{
func
mqttSetup
(
mqttBroker
string
,
port
int
,
topic
string
)
MQTT
.
Client
{
// This JS style of creating a client is awfully verbose
// This JS style of creating a client is awfully verbose
opts
:=
MQTT
.
NewClientOptions
()
.
opts
:=
MQTT
.
NewClientOptions
()
.
AddBroker
(
fmt
.
Sprintf
(
"tcp://%s:%d"
,
mqttBroker
,
port
))
.
AddBroker
(
fmt
.
Sprintf
(
"tcp://%s:%d"
,
mqttBroker
,
port
))
.
...
@@ -23,7 +23,7 @@ func mqttSetup(mqttBroker string, port int) MQTT.Client {
...
@@ -23,7 +23,7 @@ func mqttSetup(mqttBroker string, port int) MQTT.Client {
panic
(
token
.
Error
())
panic
(
token
.
Error
())
}
}
slog
.
Debug
(
"Connected to"
,
"Broker"
,
mqttBroker
,
"Port"
,
port
,
"Client"
,
mqttClientID
)
slog
.
Debug
(
"Connected to"
,
"Broker"
,
mqttBroker
,
"Port"
,
port
,
"Client"
,
mqttClientID
)
if
token
:=
client
.
Subscribe
(
mqttT
opic
+
"/#"
,
0
,
nil
);
token
.
Wait
()
&&
token
.
Error
()
!=
nil
{
if
token
:=
client
.
Subscribe
(
t
opic
+
"/#"
,
0
,
nil
);
token
.
Wait
()
&&
token
.
Error
()
!=
nil
{
panic
(
token
.
Error
())
panic
(
token
.
Error
())
}
}
return
client
return
client
...
...
This diff is collapsed.
Click to expand it.
xaal.go
+
2
−
2
View file @
7c43f932
...
@@ -420,7 +420,7 @@ func (dev *Lamp) setMode(body xaal.MessageBody) *xaal.MessageBody {
...
@@ -420,7 +420,7 @@ func (dev *Lamp) setMode(body xaal.MessageBody) *xaal.MessageBody {
func
NewButtonRemote
(
addr
uuid
.
UUID
,
zDev
*
Z2MDevice
,
exp
*
Expose
)
XAALDeviceInterface
{
func
NewButtonRemote
(
addr
uuid
.
UUID
,
zDev
*
Z2MDevice
,
exp
*
Expose
)
XAALDeviceInterface
{
dev
:=
&
ButtonRemote
{
XAALDevice
{
schemas
.
NewButtonRemote
(
addr
),
zDev
,
exp
}}
dev
:=
&
ButtonRemote
{
XAALDevice
{
schemas
.
NewButtonRemote
(
addr
),
zDev
,
exp
}}
dev
.
setup
()
dev
.
setup
()
dev
.
SetMethod
(
"get_buttons"
,
dev
.
G
etButtons
)
dev
.
SetMethod
(
"get_buttons"
,
dev
.
g
etButtons
)
return
dev
return
dev
}
}
...
@@ -434,7 +434,7 @@ func (dev *ButtonRemote) update(payload map[string]interface{}) {
...
@@ -434,7 +434,7 @@ func (dev *ButtonRemote) update(payload map[string]interface{}) {
}
}
}
}
func
(
dev
*
ButtonRemote
)
G
etButtons
(
xaal
.
MessageBody
)
*
xaal
.
MessageBody
{
func
(
dev
*
ButtonRemote
)
g
etButtons
(
xaal
.
MessageBody
)
*
xaal
.
MessageBody
{
body
:=
make
(
xaal
.
MessageBody
)
body
:=
make
(
xaal
.
MessageBody
)
action
:=
dev
.
Z2MDevice
.
GetExpose
(
dev
.
Expose
.
Name
)
action
:=
dev
.
Z2MDevice
.
GetExpose
(
dev
.
Expose
.
Name
)
if
action
!=
nil
{
if
action
!=
nil
{
...
...
This diff is collapsed.
Click to expand it.
z2m.go
+
2
−
2
View file @
7c43f932
...
@@ -70,7 +70,7 @@ type Feature struct {
...
@@ -70,7 +70,7 @@ type Feature struct {
// =============================================================================
// =============================================================================
// returns the topic for the device
// returns the topic for the device
func
(
zDev
*
Z2MDevice
)
G
etTopic
()
string
{
func
(
zDev
*
Z2MDevice
)
g
etTopic
()
string
{
return
mqttTopic
+
"/"
+
zDev
.
FriendlyName
return
mqttTopic
+
"/"
+
zDev
.
FriendlyName
}
}
...
@@ -146,7 +146,7 @@ func (zDev *Z2MDevice) setupXAALDevices(gw *Gateway) {
...
@@ -146,7 +146,7 @@ func (zDev *Z2MDevice) setupXAALDevices(gw *Gateway) {
// Publish the payload to the right topic
// Publish the payload to the right topic
func
(
zDev
*
Z2MDevice
)
Publish
(
topic
string
,
payload
interface
{})
{
func
(
zDev
*
Z2MDevice
)
Publish
(
topic
string
,
payload
interface
{})
{
topic
=
zDev
.
G
etTopic
()
+
"/"
+
topic
topic
=
zDev
.
g
etTopic
()
+
"/"
+
topic
slog
.
Debug
(
"Sending"
,
"topic"
,
topic
,
"payload"
,
payload
)
slog
.
Debug
(
"Sending"
,
"topic"
,
topic
,
"payload"
,
payload
)
client
:=
GetGW
()
.
client
client
:=
GetGW
()
.
client
if
token
:=
client
.
Publish
(
topic
,
0
,
false
,
payload
);
token
.
Wait
()
&&
token
.
Error
()
!=
nil
{
if
token
:=
client
.
Publish
(
topic
,
0
,
false
,
payload
);
token
.
Wait
()
&&
token
.
Error
()
!=
nil
{
...
...
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