diff --git a/lora/message.go b/lora/message.go index aa9e7c6c..57ed107f 100644 --- a/lora/message.go +++ b/lora/message.go @@ -40,4 +40,5 @@ type Message struct { FCnt int `json:"fCnt"` FPort int `json:"fPort"` Data string `json:"data"` + Object string `json:"object"` } diff --git a/lora/service.go b/lora/service.go index aa12ea45..2801f36d 100644 --- a/lora/service.go +++ b/lora/service.go @@ -84,9 +84,17 @@ func (as *adapterService) Publish(m Message) error { return ErrNotFoundApp } - payload, err := base64.StdEncoding.DecodeString(m.Data) - if err != nil { - return ErrMalformedMessage + // Use the SenML message decoded on LoRa server application if + // field Object isn't empty. Otherwise, decode standard field Data. + var payload []byte + switch m.Object { + case "": + payload, err = base64.StdEncoding.DecodeString(m.Data) + if err != nil { + return ErrMalformedMessage + } + default: + payload = []byte(m.Object) } // Publish on Mainflux NATS broker