Skip to content

Commit

Permalink
Cleanup Geolocation Server integration.
Browse files Browse the repository at this point in the history
Geolocation is now provided through a LoRa Cloud integration in
ChirpStack Application Server. Alternatively, all the meta-data
(fine-timestamp, SNR, RSSI) needed for geolocation is already exposed
by ChirpStack Application Server so that geolocation through an external
service is still a possibility.

The advantage of performing geolocation in the Application Server is
that it can use a combination of TDOA, RSSI, Wifi, GNSS and potentially
other sources for geolocation. For geolocation using Wifi, GNSS, ... the
payload must be decrypted first, which can only be done by the
Application Server.
  • Loading branch information
brocaar committed May 21, 2020
1 parent 8b02116 commit 3eec483
Show file tree
Hide file tree
Showing 19 changed files with 139 additions and 1,416 deletions.
20 changes: 0 additions & 20 deletions cmd/chirpstack-network-server/cmd/configfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,26 +625,6 @@ get_downlink_data_delay="{{ .NetworkServer.GetDownlinkDataDelay }}"
commands_connection_string="{{ .NetworkServer.Gateway.Backend.AzureIoTHub.CommandsConnectionString }}"
# Geolocation settings.
#
# When set, ChirpStack Network Server will use the configured geolocation server to
# resolve the location of the devices.
[geolocation_server]
# Server.
#
# The hostname:ip of the geolocation service (optional).
server="{{ .GeolocationServer.Server }}"
# CA certificate used by the API client (optional).
ca_cert="{{ .GeolocationServer.CACert}}"
# TLS certificate used by the API client (optional).
tls_cert="{{ .GeolocationServer.TLSCert }}"
# TLS key used by the API client (optional).
tls_key="{{ .GeolocationServer.TLSKey }}"
# Monitoring settings.
#
# Note that this replaces the metrics configuration. If a metrics section is
Expand Down
38 changes: 0 additions & 38 deletions cmd/chirpstack-network-server/cmd/root_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"google.golang.org/grpc/balancer/roundrobin"
"google.golang.org/grpc/credentials"

"github.com/brocaar/chirpstack-api/go/v3/geo"
"github.com/brocaar/chirpstack-api/go/v3/nc"
"github.com/brocaar/chirpstack-network-server/internal/adr"
"github.com/brocaar/chirpstack-network-server/internal/api"
Expand All @@ -28,7 +27,6 @@ import (
"github.com/brocaar/chirpstack-network-server/internal/backend/gateway/azureiothub"
"github.com/brocaar/chirpstack-network-server/internal/backend/gateway/gcppubsub"
"github.com/brocaar/chirpstack-network-server/internal/backend/gateway/mqtt"
"github.com/brocaar/chirpstack-network-server/internal/backend/geolocationserver"
"github.com/brocaar/chirpstack-network-server/internal/backend/joinserver"
"github.com/brocaar/chirpstack-network-server/internal/band"
"github.com/brocaar/chirpstack-network-server/internal/config"
Expand Down Expand Up @@ -56,7 +54,6 @@ func run(cmd *cobra.Command, args []string) error {
setGatewayBackend,
setupApplicationServer,
setupADR,
setupGeolocationServer,
setupJoinServer,
setupNetworkController,
setupUplink,
Expand Down Expand Up @@ -226,41 +223,6 @@ func setupApplicationServer() error {
return nil
}

func setupGeolocationServer() error {
// TODO: move setup to gelolocation.Setup
if config.C.GeolocationServer.Server == "" {
log.Info("no geolocation-server configured")
return nil
}

log.WithFields(log.Fields{
"server": config.C.GeolocationServer.Server,
"ca_cert": config.C.GeolocationServer.CACert,
"tls_cert": config.C.GeolocationServer.TLSCert,
"tls_key": config.C.GeolocationServer.TLSKey,
}).Info("connecting to geolocation-server")

dialOptions := []grpc.DialOption{
grpc.WithBalancerName(roundrobin.Name),
}
if config.C.GeolocationServer.TLSCert != "" && config.C.GeolocationServer.TLSKey != "" {
dialOptions = append(dialOptions, grpc.WithTransportCredentials(
mustGetTransportCredentials(config.C.GeolocationServer.TLSCert, config.C.GeolocationServer.TLSKey, config.C.GeolocationServer.CACert, false),
))
} else {
dialOptions = append(dialOptions, grpc.WithInsecure())
}

geoConn, err := grpc.Dial(config.C.GeolocationServer.Server, dialOptions...)
if err != nil {
return errors.Wrap(err, "geolocation-server dial error")
}

geolocationserver.SetClient(geo.NewGeolocationServerServiceClient(geoConn))

return nil
}

func setupJoinServer() error {
if err := joinserver.Setup(config.C); err != nil {
return errors.Wrap(err, "setup join-server backend error")
Expand Down
20 changes: 0 additions & 20 deletions docs/content/install/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -675,26 +675,6 @@ get_downlink_data_delay="100ms"
commands_connection_string=""


# Geolocation settings.
#
# When set, ChirpStack Network Server will use the configured geolocation server to
# resolve the location of the devices.
[geolocation_server]
# Server.
#
# The hostname:ip of the geolocation service (optional).
server=""

# CA certificate used by the API client (optional).
ca_cert=""

# TLS certificate used by the API client (optional).
tls_cert=""

# TLS key used by the API client (optional).
tls_key=""


# Monitoring settings.
#
# Note that this replaces the metrics configuration. If a metrics section is
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/Azure/azure-amqp-common-go v1.1.4
github.com/Azure/azure-service-bus-go v0.9.1
github.com/NickBall/go-aes-key-wrap v0.0.0-20170929221519-1c3aa3e4dfc5
github.com/brocaar/chirpstack-api/go/v3 v3.5.1
github.com/brocaar/chirpstack-api/go/v3 v3.6.1
github.com/brocaar/lorawan v0.0.0-20191115102621-6095d473cf60
github.com/eclipse/paho.mqtt.golang v1.2.0
github.com/elazarl/go-bindata-assetfs v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/blakesmith/ar v0.0.0-20150311145944-8bd4349a67f2 h1:oMCHnXa6CCCafdPDbMh/lWRhRByN0VFLvv+g+ayx1SI=
github.com/blakesmith/ar v0.0.0-20150311145944-8bd4349a67f2/go.mod h1:PkYb9DJNAwrSvRx5DYA+gUcOIgTGVMNkfSCbZM8cWpI=
github.com/brocaar/chirpstack-api/go/v3 v3.5.1 h1:/XIDgKS3hzrqJrPqFU+KXtwcZneccCcCU4N4kN/2jAQ=
github.com/brocaar/chirpstack-api/go/v3 v3.5.1/go.mod h1:ex/wqXQaClwDMa2zDN6crp9ZiMGc1GMVQhjxiB+OJcg=
github.com/brocaar/chirpstack-api/go/v3 v3.6.1 h1:piHy2E2om9ah/auNc4Dn3U84CX4t0suUr2ykXrqgxbo=
github.com/brocaar/chirpstack-api/go/v3 v3.6.1/go.mod h1:ex/wqXQaClwDMa2zDN6crp9ZiMGc1GMVQhjxiB+OJcg=
github.com/brocaar/lorawan v0.0.0-20191115102621-6095d473cf60 h1:jecx8QFcsUAWZojNIqOZaoAWFwkBbd3VOHZ3kv6FQxE=
github.com/brocaar/lorawan v0.0.0-20191115102621-6095d473cf60/go.mod h1:VgyRGAJ/wl1JfqZZmNlCTM8fyaIKF11YvYAGIVtedL8=
github.com/caarlos0/ctrlc v1.0.0 h1:2DtF8GSIcajgffDFJzyG15vO+1PuBWOMUdFut7NnXhw=
Expand Down
86 changes: 40 additions & 46 deletions internal/api/network_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,28 +346,26 @@ func (n *NetworkServerAPI) CreateDeviceProfile(ctx context.Context, req *ns.Crea
}

dp := storage.DeviceProfile{
ID: dpID,
SupportsClassB: req.DeviceProfile.SupportsClassB,
ClassBTimeout: int(req.DeviceProfile.ClassBTimeout),
PingSlotPeriod: int(req.DeviceProfile.PingSlotPeriod),
PingSlotDR: int(req.DeviceProfile.PingSlotDr),
PingSlotFreq: int(req.DeviceProfile.PingSlotFreq),
SupportsClassC: req.DeviceProfile.SupportsClassC,
ClassCTimeout: int(req.DeviceProfile.ClassCTimeout),
MACVersion: req.DeviceProfile.MacVersion,
RegParamsRevision: req.DeviceProfile.RegParamsRevision,
RXDelay1: int(req.DeviceProfile.RxDelay_1),
RXDROffset1: int(req.DeviceProfile.RxDrOffset_1),
RXDataRate2: int(req.DeviceProfile.RxDatarate_2),
RXFreq2: int(req.DeviceProfile.RxFreq_2),
FactoryPresetFreqs: factoryPresetFreqs,
MaxEIRP: int(req.DeviceProfile.MaxEirp),
MaxDutyCycle: int(req.DeviceProfile.MaxDutyCycle),
SupportsJoin: req.DeviceProfile.SupportsJoin,
Supports32bitFCnt: req.DeviceProfile.Supports_32BitFCnt,
RFRegion: band.Band().Name(),
GeolocBufferTTL: int(req.DeviceProfile.GeolocBufferTtl),
GeolocMinBufferSize: int(req.DeviceProfile.GeolocMinBufferSize),
ID: dpID,
SupportsClassB: req.DeviceProfile.SupportsClassB,
ClassBTimeout: int(req.DeviceProfile.ClassBTimeout),
PingSlotPeriod: int(req.DeviceProfile.PingSlotPeriod),
PingSlotDR: int(req.DeviceProfile.PingSlotDr),
PingSlotFreq: int(req.DeviceProfile.PingSlotFreq),
SupportsClassC: req.DeviceProfile.SupportsClassC,
ClassCTimeout: int(req.DeviceProfile.ClassCTimeout),
MACVersion: req.DeviceProfile.MacVersion,
RegParamsRevision: req.DeviceProfile.RegParamsRevision,
RXDelay1: int(req.DeviceProfile.RxDelay_1),
RXDROffset1: int(req.DeviceProfile.RxDrOffset_1),
RXDataRate2: int(req.DeviceProfile.RxDatarate_2),
RXFreq2: int(req.DeviceProfile.RxFreq_2),
FactoryPresetFreqs: factoryPresetFreqs,
MaxEIRP: int(req.DeviceProfile.MaxEirp),
MaxDutyCycle: int(req.DeviceProfile.MaxDutyCycle),
SupportsJoin: req.DeviceProfile.SupportsJoin,
Supports32bitFCnt: req.DeviceProfile.Supports_32BitFCnt,
RFRegion: band.Band().Name(),
}

if err := storage.CreateDeviceProfile(ctx, storage.DB(), &dp); err != nil {
Expand Down Expand Up @@ -396,28 +394,26 @@ func (n *NetworkServerAPI) GetDeviceProfile(ctx context.Context, req *ns.GetDevi

resp := ns.GetDeviceProfileResponse{
DeviceProfile: &ns.DeviceProfile{
Id: dp.ID.Bytes(),
SupportsClassB: dp.SupportsClassB,
ClassBTimeout: uint32(dp.ClassBTimeout),
PingSlotPeriod: uint32(dp.PingSlotPeriod),
PingSlotDr: uint32(dp.PingSlotDR),
PingSlotFreq: uint32(dp.PingSlotFreq),
SupportsClassC: dp.SupportsClassC,
ClassCTimeout: uint32(dp.ClassCTimeout),
MacVersion: dp.MACVersion,
RegParamsRevision: dp.RegParamsRevision,
RxDelay_1: uint32(dp.RXDelay1),
RxDrOffset_1: uint32(dp.RXDROffset1),
RxDatarate_2: uint32(dp.RXDataRate2),
RxFreq_2: uint32(dp.RXFreq2),
FactoryPresetFreqs: factoryPresetFreqs,
MaxEirp: uint32(dp.MaxEIRP),
MaxDutyCycle: uint32(dp.MaxDutyCycle),
SupportsJoin: dp.SupportsJoin,
RfRegion: string(dp.RFRegion),
Supports_32BitFCnt: dp.Supports32bitFCnt,
GeolocBufferTtl: uint32(dp.GeolocBufferTTL),
GeolocMinBufferSize: uint32(dp.GeolocMinBufferSize),
Id: dp.ID.Bytes(),
SupportsClassB: dp.SupportsClassB,
ClassBTimeout: uint32(dp.ClassBTimeout),
PingSlotPeriod: uint32(dp.PingSlotPeriod),
PingSlotDr: uint32(dp.PingSlotDR),
PingSlotFreq: uint32(dp.PingSlotFreq),
SupportsClassC: dp.SupportsClassC,
ClassCTimeout: uint32(dp.ClassCTimeout),
MacVersion: dp.MACVersion,
RegParamsRevision: dp.RegParamsRevision,
RxDelay_1: uint32(dp.RXDelay1),
RxDrOffset_1: uint32(dp.RXDROffset1),
RxDatarate_2: uint32(dp.RXDataRate2),
RxFreq_2: uint32(dp.RXFreq2),
FactoryPresetFreqs: factoryPresetFreqs,
MaxEirp: uint32(dp.MaxEIRP),
MaxDutyCycle: uint32(dp.MaxDutyCycle),
SupportsJoin: dp.SupportsJoin,
RfRegion: string(dp.RFRegion),
Supports_32BitFCnt: dp.Supports32bitFCnt,
},
}

Expand Down Expand Up @@ -473,8 +469,6 @@ func (n *NetworkServerAPI) UpdateDeviceProfile(ctx context.Context, req *ns.Upda
dp.SupportsJoin = req.DeviceProfile.SupportsJoin
dp.Supports32bitFCnt = req.DeviceProfile.Supports_32BitFCnt
dp.RFRegion = band.Band().Name()
dp.GeolocBufferTTL = int(req.DeviceProfile.GeolocBufferTtl)
dp.GeolocMinBufferSize = int(req.DeviceProfile.GeolocMinBufferSize)

if err := storage.FlushDeviceProfileCache(ctx, dp.ID); err != nil {
return nil, errToRPCError(err)
Expand Down
80 changes: 38 additions & 42 deletions internal/api/network_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,26 +348,24 @@ func TestNetworkServerAPI(t *testing.T) {
Convey("When calling CreateDeviceProfile", func() {
resp, err := api.CreateDeviceProfile(ctx, &ns.CreateDeviceProfileRequest{
DeviceProfile: &ns.DeviceProfile{
SupportsClassB: true,
ClassBTimeout: 1,
PingSlotPeriod: 2,
PingSlotDr: 3,
PingSlotFreq: 868100000,
SupportsClassC: true,
ClassCTimeout: 4,
MacVersion: "1.0.2",
RegParamsRevision: "B",
RxDelay_1: 5,
RxDrOffset_1: 6,
RxDatarate_2: 7,
RxFreq_2: 868200000,
FactoryPresetFreqs: []uint32{868100000, 868300000, 868500000},
MaxEirp: 14,
MaxDutyCycle: 1,
SupportsJoin: true,
Supports_32BitFCnt: true,
GeolocBufferTtl: 60,
GeolocMinBufferSize: 3,
SupportsClassB: true,
ClassBTimeout: 1,
PingSlotPeriod: 2,
PingSlotDr: 3,
PingSlotFreq: 868100000,
SupportsClassC: true,
ClassCTimeout: 4,
MacVersion: "1.0.2",
RegParamsRevision: "B",
RxDelay_1: 5,
RxDrOffset_1: 6,
RxDatarate_2: 7,
RxFreq_2: 868200000,
FactoryPresetFreqs: []uint32{868100000, 868300000, 868500000},
MaxEirp: 14,
MaxDutyCycle: 1,
SupportsJoin: true,
Supports_32BitFCnt: true,
},
})
So(err, ShouldBeNil)
Expand All @@ -380,28 +378,26 @@ func TestNetworkServerAPI(t *testing.T) {
})
So(err, ShouldBeNil)
So(getResp.DeviceProfile, ShouldResemble, &ns.DeviceProfile{
Id: resp.Id,
SupportsClassB: true,
ClassBTimeout: 1,
PingSlotPeriod: 2,
PingSlotDr: 3,
PingSlotFreq: 868100000,
SupportsClassC: true,
ClassCTimeout: 4,
MacVersion: "1.0.2",
RegParamsRevision: "B",
RxDelay_1: 5,
RxDrOffset_1: 6,
RxDatarate_2: 7,
RxFreq_2: 868200000,
FactoryPresetFreqs: []uint32{868100000, 868300000, 868500000},
MaxEirp: 14,
MaxDutyCycle: 1,
SupportsJoin: true,
RfRegion: "EU868", // set by the api
Supports_32BitFCnt: true,
GeolocBufferTtl: 60,
GeolocMinBufferSize: 3,
Id: resp.Id,
SupportsClassB: true,
ClassBTimeout: 1,
PingSlotPeriod: 2,
PingSlotDr: 3,
PingSlotFreq: 868100000,
SupportsClassC: true,
ClassCTimeout: 4,
MacVersion: "1.0.2",
RegParamsRevision: "B",
RxDelay_1: 5,
RxDrOffset_1: 6,
RxDatarate_2: 7,
RxFreq_2: 868200000,
FactoryPresetFreqs: []uint32{868100000, 868300000, 868500000},
MaxEirp: 14,
MaxDutyCycle: 1,
SupportsJoin: true,
RfRegion: "EU868", // set by the api
Supports_32BitFCnt: true,
})
})
})
Expand Down
15 changes: 0 additions & 15 deletions internal/backend/geolocationserver/geolocation.go

This file was deleted.

7 changes: 0 additions & 7 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,6 @@ type Config struct {
} `mapstructure:"gateway"`
} `mapstructure:"network_server"`

GeolocationServer struct {
Server string `mapstructure:"server"`
CACert string `mapstructure:"ca_cert"`
TLSCert string `mapstructure:"tls_cert"`
TLSKey string `mapstructure:"tls_key"`
} `mapstructure:"geolocation_server"`

JoinServer struct {
ResolveJoinEUI bool `mapstructure:"resolve_join_eui"`
ResolveDomainSuffix string `mapstructure:"resolve_domain_suffix"`
Expand Down
Loading

0 comments on commit 3eec483

Please sign in to comment.