MF-600 - Handle custom LoRa Server application decoder (#608)
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
This commit is contained in:
parent
06921fbee6
commit
1c09632671
|
@ -40,4 +40,5 @@ type Message struct {
|
|||
FCnt int `json:"fCnt"`
|
||||
FPort int `json:"fPort"`
|
||||
Data string `json:"data"`
|
||||
Object string `json:"object"`
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue