I’ve copied/built the example here: Go examples - ChirpStack open-source LoRaWAN® Network Server documentation
I’ve added a few print lines for debugging, but when running I get this error message: Unauthenticated desc =
Full output here:
ChirpStack Example
Connecting to server...
Creating client...
Enqueueing downlink...
panic: rpc error: code = Unauthenticated desc =
goroutine 1 [running]:
main.main()
/home/myuser/repositories/chirp-example/chirpstackexample.go:67 +0x433
Here is the source I’m running exactly
package main
import (
"context"
"fmt"
"github.com/chirpstack/chirpstack/api/go/v4/api"
"google.golang.org/grpc"
)
// configuration
var (
// This must point to the API interface
server = "localhost:8080"
// The DevEUI for which we want to enqueue the downlink
devEUI = "0101010101010101"
// The API token (retrieved using the web-interface)
apiToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJjaGlycHN0YWNrIiwiaXNzIjoiY2hpcnBzdGFjayIsInN1YiI6ImNlNjNiYmFjLTRlYjAtNGQzYy1hNTA1LTk3NmUz......."
)
type APIToken string
func (a APIToken) GetRequestMetadata(ctx context.Context, url ...string) (map[string]string, error) {
return map[string]string{
"authorization": fmt.Sprintf("Bearer %s", a),
}, nil
}
func (a APIToken) RequireTransportSecurity() bool {
return false
}
func main() {
fmt.Println("ChirpStack Example7")
// define gRPC dial options
dialOpts := []grpc.DialOption{
grpc.WithBlock(),
grpc.WithPerRPCCredentials(APIToken(apiToken)),
grpc.WithInsecure(), // remove this when using TLS
}
// connect to the gRPC server
fmt.Println("Connecting to server...")
conn, err := grpc.Dial(server, dialOpts...)
if err != nil {
panic(err)
}
// define the DeviceService client
fmt.Println("Creating client...")
deviceClient := api.NewDeviceServiceClient(conn)
// make an Enqueue api call
fmt.Println("Enqueueing downlink...")
resp, err := deviceClient.Enqueue(context.Background(), &api.EnqueueDeviceQueueItemRequest{
QueueItem: &api.DeviceQueueItem{
DevEui: devEUI,
FPort: 10,
Confirmed: false,
Data: []byte{0x01, 0x02, 0x03},
},
})
if err != nil {
panic(err)
}
fmt.Printf("The downlink has been enqueued with id: %s\n", resp.Id)
}
It doesn’t seem to like that byte array, but it’s not clear to me what this actually represents and/or what should go there.