@@ -34,7 +34,7 @@ func NewBackend(server, username, password string) (*Backend, error) {
34
34
opts .SetOnConnectHandler (b .onConnected )
35
35
opts .SetConnectionLostHandler (b .onConnectionLost )
36
36
37
- log .WithField ("server" , server ).Info ("backend/mqttpubsub : connecting to mqtt broker" )
37
+ log .WithField ("server" , server ).Info ("backend: connecting to mqtt broker" )
38
38
b .conn = mqtt .NewClient (opts )
39
39
if token := b .conn .Connect (); token .Wait () && token .Error () != nil {
40
40
return nil , token .Error ()
@@ -60,7 +60,7 @@ func (b *Backend) SubscribeGatewayTX(mac lorawan.EUI64) error {
60
60
b .mutex .Lock ()
61
61
62
62
topic := fmt .Sprintf ("gateway/%s/tx" , mac .String ())
63
- log .WithField ("topic" , topic ).Info ("backend/mqttpubsub : subscribing to topic" )
63
+ log .WithField ("topic" , topic ).Info ("backend: subscribing to topic" )
64
64
if token := b .conn .Subscribe (topic , 0 , b .txPacketHandler ); token .Wait () && token .Error () != nil {
65
65
return token .Error ()
66
66
}
@@ -75,7 +75,7 @@ func (b *Backend) UnSubscribeGatewayTX(mac lorawan.EUI64) error {
75
75
b .mutex .Lock ()
76
76
77
77
topic := fmt .Sprintf ("gateway/%s/tx" , mac .String ())
78
- log .WithField ("topic" , topic ).Info ("backend/mqttpubsub : unsubscribing from topic" )
78
+ log .WithField ("topic" , topic ).Info ("backend: unsubscribing from topic" )
79
79
if token := b .conn .Unsubscribe (topic ); token .Wait () && token .Error () != nil {
80
80
return token .Error ()
81
81
}
@@ -100,18 +100,18 @@ func (b *Backend) publish(topic string, v interface{}) error {
100
100
if err != nil {
101
101
return err
102
102
}
103
- log .WithField ("topic" , topic ).Info ("backend/mqttpubsub : publishing packet" )
103
+ log .WithField ("topic" , topic ).Info ("backend: publishing packet" )
104
104
if token := b .conn .Publish (topic , 0 , false , bytes ); token .Wait () && token .Error () != nil {
105
105
return token .Error ()
106
106
}
107
107
return nil
108
108
}
109
109
110
110
func (b * Backend ) txPacketHandler (c mqtt.Client , msg mqtt.Message ) {
111
- log .WithField ("topic" , msg .Topic ()).Info ("backend/mqttpubsub : packet received" )
111
+ log .WithField ("topic" , msg .Topic ()).Info ("backend: packet received" )
112
112
var txPacket models.TXPacket
113
113
if err := json .Unmarshal (msg .Payload (), & txPacket ); err != nil {
114
- log .Errorf ("backend/mqttpubsub : decode tx packet error: %s" , err )
114
+ log .Errorf ("backend: decode tx packet error: %s" , err )
115
115
return
116
116
}
117
117
b .txPacketChan <- txPacket
@@ -121,16 +121,16 @@ func (b *Backend) onConnected(c mqtt.Client) {
121
121
defer b .mutex .RUnlock ()
122
122
b .mutex .RLock ()
123
123
124
- log .Info ("backend/mqttpubsub : connected to mqtt broker" )
124
+ log .Info ("backend: connected to mqtt broker" )
125
125
if len (b .gateways ) > 0 {
126
126
for {
127
- log .WithField ("topic_count" , len (b .gateways )).Info ("backend/mqttpubsub : re-registering to gateway topics" )
127
+ log .WithField ("topic_count" , len (b .gateways )).Info ("backend: re-registering to gateway topics" )
128
128
topics := make (map [string ]byte )
129
129
for k := range b .gateways {
130
130
topics [fmt .Sprintf ("gateway/%s/tx" , k )] = 0
131
131
}
132
132
if token := b .conn .SubscribeMultiple (topics , b .txPacketHandler ); token .Wait () && token .Error () != nil {
133
- log .WithField ("topic_count" , len (topics )).Errorf ("backend/mqttpubsub : subscribe multiple failed: %s" , token .Error ())
133
+ log .WithField ("topic_count" , len (topics )).Errorf ("backend: subscribe multiple failed: %s" , token .Error ())
134
134
time .Sleep (time .Second )
135
135
continue
136
136
}
@@ -140,5 +140,5 @@ func (b *Backend) onConnected(c mqtt.Client) {
140
140
}
141
141
142
142
func (b * Backend ) onConnectionLost (c mqtt.Client , reason error ) {
143
- log .Errorf ("backend/mqttpubsub : mqtt connection error: %s" , reason )
143
+ log .Errorf ("backend: mqtt connection error: %s" , reason )
144
144
}
0 commit comments