I’ve been successfully using the HTTP-API to manage my application and now I want to switch to using grpc, since its more recommendable.
I am using Go as a language. I wrote the proto based on the API-Doc. I even double checked with the server side proto on their github. I tried creating a testdevice on the identity server as a first test, but all I
end up getting all the time is a non-descript error. Maybe someone who has already used the grpc api can see a mistake in my attempt.
My testfunctioncall:
func connect() {
var conn *grpc.ClientConn
var err error
var auth string
var header, trailer metadata.MD
auth = "Bearer " + ApiKey
md := metadata.New(map[string]string{
“authorization”: auth,
})
ctx := metadata.NewOutgoingContext(context.Background(), md)conn, err = grpc.Dial(“eu1.cloud.thethings.network:1884”, grpc.WithInsecure())
if err != nil {
log.Fatalf(“Error: %s”, err)
}
log.Println(“Successfully connected”)
defer conn.Close()
ttsclient := thingsstackapi.NewEndDeviceRegistryClient(conn)
appidentifiers := thingsstackapi.ApplicationIdentifiers{
ApplicationId: “lora-sensortest”,
}
ids := thingsstackapi.EndDeviceIdentifiers{
DeviceId: “sd2”,
ApplicationIds: &appidentifiers,
DevEui: byte(“1234567890123456”),
JoinEui: byte(“1234567890123456”),
}
message := thingsstackapi.EndDevice{
Ids: &ids,
NetworkServerAddress: “eu1.cloud.thethings.network”,
JoinServerAddress: “eu1.cloud.thethings.network”,
ApplicationServerAddress: “eu1.cloud.thethings.network”,
}
request := thingsstackapi.CreateEndDeviceRequest{
EndDevice: &message,
}
resp, err := ttsclient.Create(ctx, &request, grpc.Header(&header), grpc.Trailer(&trailer))
log.Println(header)
log.Println(trailer)
if err != nil {
log.Println(resp)
conn.Close()
log.Fatalf(err.Error())
}
}
Here is my definition of the relevant structs in the protofile
service EndDeviceRegistry {
rpc Create(CreateEndDeviceRequest) returns (EndDevice);
rpc Get(GetEndDeviceRequest) returns (EndDevice);
rpc List(ListEndDevicesRequest) returns (EndDevices);
rpc Delete(EndDeviceIdentifiers) returns (google.protobuf.Empty);
}
message CreateEndDeviceRequest {
EndDevice end_device = 1;
}
message EndDevice {
EndDeviceIdentifiers ids = 1;
string network_server_address = 9;
string application_server_address = 10;
string join_server_address = 11;
MACVersion lorawan_version = 15;
PHYVersion lorawan_phy_version = 16;
string frequency_plan_id = 17;
bool supports_join = 20;
RootKeys root_keys = 22;
}
message EndDeviceIdentifiers {
string device_id = 1;
ApplicationIdentifiers application_ids = 2;
bytes dev_eui = 4;
bytes join_eui = 5;
bytes dev_addr = 6;
}
message ApplicationIdentifiers {
string application_id = 1;
}
And here is the output:
2021/05/25 12:15:44 Successfully connected
2021/05/25 12:15:44 map
2021/05/25 12:15:44 map[content-type:[application/grpc] date:[Tue, 25 May 2021 10:15:45 GMT] server:[envoy]]
2021/05/25 12:15:44
2021/05/25 12:15:44 rpc error: code = Unimplemented desc =
Process exiting with code: 1 signal: false
The empty desc field is really upsetting. I confirmed with WireShark that a connection with the dialed address is successfully established and it does so. I’ve been changing multiple small things all over but the output is always the same. I tried deleting devices, listing them, nothing changes.
I’ve been trying for quite some time now and I am simply out of ideas. Any help would be greatly appreciated. Thanks in advance.