MF-600 - Handle custom LoRa Server application decoder (#608)

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
This commit is contained in:
Manuel Imperiale 2019-02-22 09:31:44 +01:00 committed by Dušan Borovčanin
parent 06921fbee6
commit 1c09632671
2 changed files with 12 additions and 3 deletions

View File

@ -40,4 +40,5 @@ type Message struct {
FCnt int `json:"fCnt"`
FPort int `json:"fPort"`
Data string `json:"data"`
Object string `json:"object"`
}

View File

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