Handle new default topic scheme 'ATB/#'
This commit is contained in:
parent
78241d8e5a
commit
30c66efffd
13
mqtt/mqtt.go
13
mqtt/mqtt.go
|
@ -127,6 +127,11 @@ var subscriptionHandler = func(client MQTT.Client, msg MQTT.Message) {
|
||||||
|
|
||||||
topicSlice := strings.Split(msg.Topic(), "/")
|
topicSlice := strings.Split(msg.Topic(), "/")
|
||||||
|
|
||||||
|
// remove a possible empty element (-> handle '/ATB/#' and 'ATB/#'
|
||||||
|
if (len(topicSlice[0]) == 0) {
|
||||||
|
topicSlice = topicSlice[1:]
|
||||||
|
}
|
||||||
|
|
||||||
matchedWithType, err := regexp.MatchString(regexpWithType, msg.Topic())
|
matchedWithType, err := regexp.MatchString(regexpWithType, msg.Topic())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("ERROR: matchedWithType: %s", err.Error())
|
log.Printf("ERROR: matchedWithType: %s", err.Error())
|
||||||
|
@ -140,12 +145,12 @@ var subscriptionHandler = func(client MQTT.Client, msg MQTT.Message) {
|
||||||
var deviceID string
|
var deviceID string
|
||||||
if matchedWithType {
|
if matchedWithType {
|
||||||
fmt.Printf("Topic matched regexpWithType\n")
|
fmt.Printf("Topic matched regexpWithType\n")
|
||||||
customerID = topicSlice[3]
|
customerID = topicSlice[2]
|
||||||
deviceID = topicSlice[4]
|
deviceID = topicSlice[3]
|
||||||
} else if matchedDefault {
|
} else if matchedDefault {
|
||||||
fmt.Printf("Topic matched regexpDefault\n")
|
fmt.Printf("Topic matched regexpDefault\n")
|
||||||
customerID = topicSlice[2]
|
customerID = topicSlice[1]
|
||||||
deviceID = topicSlice[5]
|
deviceID = topicSlice[4]
|
||||||
} else {
|
} else {
|
||||||
log.Printf("ERROR: no matching topic: %s", msg.Topic())
|
log.Printf("ERROR: no matching topic: %s", msg.Topic())
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue
Block a user