NOISSUE - Fix lora-adapter Object decode (#610)
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
This commit is contained in:
parent
fa7d638453
commit
a60a5c1ba1
|
@ -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"`
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue