Skip to content
Snippets Groups Projects
Commit 7c43f932 authored by KERDREUX Jerome's avatar KERDREUX Jerome
Browse files

Removing mqttTopic gobal in progress

parent 15f29f20
No related branches found
No related tags found
No related merge requests found
...@@ -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)
......
...@@ -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(mqttTopic+"/#", 0, nil); token.Wait() && token.Error() != nil { if token := client.Subscribe(topic+"/#", 0, nil); token.Wait() && token.Error() != nil {
panic(token.Error()) panic(token.Error())
} }
return client return client
......
...@@ -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.GetButtons) dev.SetMethod("get_buttons", dev.getButtons)
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) GetButtons(xaal.MessageBody) *xaal.MessageBody { func (dev *ButtonRemote) getButtons(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 {
......
...@@ -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) GetTopic() string { func (zDev *Z2MDevice) getTopic() 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.GetTopic() + "/" + topic topic = zDev.getTopic() + "/" + 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 {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment