NOISSUE - Fix lora-adapter Object decode (#610)

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
This commit is contained in:
Manuel Imperiale 2019-02-22 15:30:37 +01:00 committed by GitHub
parent fa7d638453
commit a60a5c1ba1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 14 deletions

View File

@ -29,16 +29,16 @@ type TxInfo struct {
// Message lora msg (www.loraserver.io/lora-app-server/integrate/data/)
type Message struct {
ApplicationID string `json:"applicationID"`
ApplicationName string `json:"applicationName"`
DeviceName string `json:"deviceName"`
DevEUI string `json:"devEUI"`
DeviceStatusBattery string `json:"deviceStatusBattery"`
DeviceStatusMrgin string `json:"deviceStatusMargin"`
RxInfo RxInfo `json:"rxInfo"`
TxInfo TxInfo `json:"txInfo"`
FCnt int `json:"fCnt"`
FPort int `json:"fPort"`
Data string `json:"data"`
Object string `json:"object"`
ApplicationID string `json:"applicationID"`
ApplicationName string `json:"applicationName"`
DeviceName string `json:"deviceName"`
DevEUI string `json:"devEUI"`
DeviceStatusBattery string `json:"deviceStatusBattery"`
DeviceStatusMrgin string `json:"deviceStatusMargin"`
RxInfo RxInfo `json:"rxInfo"`
TxInfo TxInfo `json:"txInfo"`
FCnt int `json:"fCnt"`
FPort int `json:"fPort"`
Data string `json:"data"`
Object interface{} `json:"object"`
}

View File

@ -2,6 +2,7 @@ package lora
import (
"encoding/base64"
"encoding/json"
"errors"
"github.com/mainflux/mainflux"
@ -88,13 +89,17 @@ func (as *adapterService) Publish(m Message) error {
// field Object isn't empty. Otherwise, decode standard field Data.
var payload []byte
switch m.Object {
case "":
case nil:
payload, err = base64.StdEncoding.DecodeString(m.Data)
if err != nil {
return ErrMalformedMessage
}
default:
payload = []byte(m.Object)
jo, err := json.Marshal(m.Object)
if err != nil {
return err
}
payload = []byte(jo)
}
// Publish on Mainflux NATS broker