-
Notifications
You must be signed in to change notification settings - Fork 0
/
send_cmd.go
42 lines (36 loc) · 868 Bytes
/
send_cmd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"encoding/base64"
"fmt"
"github.com/lab5e/lospan/pkg/pb/lospan"
)
type sendCmd struct {
DeviceEUI string `kong:"help='Device EUI',required"`
Payload string `kong:"help='Payload, base64 encoded',required"`
Port uint8 `kong:"help='Port for message',default=1"`
Ack bool `kong:"help='Request message ack',default=false"`
}
func (*sendCmd) Run(args *params) error {
p := args.Send
client, ctx, done, err := createClient(args.Address)
if err != nil {
return err
}
defer done()
buf, err := base64.StdEncoding.DecodeString(p.Payload)
if err != nil {
return err
}
req := &lospan.DownstreamMessage{
Eui: p.DeviceEUI,
Payload: buf,
Port: int32(p.Port),
Ack: p.Ack,
}
_, err = client.SendMessage(ctx, req)
if err != nil {
return err
}
fmt.Println("Message queued in outbox")
return nil
}