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