Handle new default topic scheme 'ATB/#'

This commit is contained in:
Siegfried Siegert 2020-11-22 14:41:04 +01:00
parent 78241d8e5a
commit 30c66efffd

View File

@ -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