Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

Commit

Permalink
Merge pull request #700 from TheThingsNetwork/develop
Browse files Browse the repository at this point in the history
v2.9.2
  • Loading branch information
htdvisser authored Mar 9, 2018
2 parents 8477a84 + 991017f commit 4a193dc
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 14 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ When you get started with The Things Network, you'll probably have some question
- Read the [official documentation](https://www.thethingsnetwork.org/docs/)
- Register on the [forum](https://www.thethingsnetwork.org/forum/) and search around
- Join [Slack](https://slack.thethingsnetwork.org) and ask us what you want to know
- Read background information on the [wiki](https://www.thethingsnetwork.org/wiki/)

## Installing and Running The Things Network Stack

Expand Down
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ func init() {
RootCmd.PersistentFlags().Bool("allow-insecure", false, "Allow insecure fallback if TLS unavailable")
RootCmd.PersistentFlags().String("key-dir", path.Clean(dir+"/.ttn/"), "The directory where public/private keys are stored")

RootCmd.PersistentFlags().Int("eu-rx2-dr", 3, "RX2 data rate for the EU band (SF12=0,SF9=3)")

viper.BindPFlags(RootCmd.PersistentFlags())
}

Expand Down
11 changes: 9 additions & 2 deletions core/band/band.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/TheThingsNetwork/ttn/utils/errors"
"github.com/brocaar/lorawan"
lora "github.com/brocaar/lorawan/band"
"github.com/spf13/viper"
)

// FrequencyPlan includes band configuration and CFList
Expand Down Expand Up @@ -65,14 +66,17 @@ func Guess(frequency uint64) string {

// Get the frequency plan for the given region
func Get(region string) (frequencyPlan FrequencyPlan, err error) {
defer func() {
if err == nil && region == pb_lorawan.FrequencyPlan_EU_863_870.String() {
frequencyPlan.RX2DataRate = viper.GetInt("eu-rx2-dr")
}
}()
if fp, ok := frequencyPlans[region]; ok {
return fp, nil
}
switch region {
case pb_lorawan.FrequencyPlan_EU_863_870.String():
frequencyPlan.Band, err = lora.GetConfig(lora.EU_863_870, false, lorawan.DwellTimeNoLimit)
// TTN uses SF9BW125 in RX2
frequencyPlan.RX2DataRate = 3
// TTN frequency plan includes extra channels next to the default channels:
frequencyPlan.UplinkChannels = []lora.Channel{
lora.Channel{Frequency: 868100000, DataRates: []int{0, 1, 2, 3, 4, 5}},
Expand Down Expand Up @@ -114,6 +118,7 @@ func Get(region string) (frequencyPlan FrequencyPlan, err error) {
frequencyPlan.Band, err = lora.GetConfig(lora.CN_470_510, false, lorawan.DwellTimeNoLimit)
case pb_lorawan.FrequencyPlan_AS_923.String():
frequencyPlan.Band, err = lora.GetConfig(lora.AS_923, false, lorawan.DwellTime400ms)
frequencyPlan.ADR = &ADRConfig{MinDataRate: 0, MaxDataRate: 5, MinTXPower: 2, MaxTXPower: 14, StepTXPower: 2}
case pb_lorawan.FrequencyPlan_AS_920_923.String():
frequencyPlan.Band, err = lora.GetConfig(lora.AS_923, false, lorawan.DwellTime400ms)
frequencyPlan.UplinkChannels = []lora.Channel{
Expand All @@ -130,6 +135,7 @@ func Get(region string) (frequencyPlan FrequencyPlan, err error) {
}
frequencyPlan.DownlinkChannels = frequencyPlan.UplinkChannels
frequencyPlan.CFList = &lorawan.CFList{922200000, 922400000, 922600000, 922800000, 923000000}
frequencyPlan.ADR = &ADRConfig{MinDataRate: 0, MaxDataRate: 5, MinTXPower: 2, MaxTXPower: 14, StepTXPower: 2}
case pb_lorawan.FrequencyPlan_AS_923_925.String():
frequencyPlan.Band, err = lora.GetConfig(lora.AS_923, false, lorawan.DwellTime400ms)
frequencyPlan.UplinkChannels = []lora.Channel{
Expand All @@ -146,6 +152,7 @@ func Get(region string) (frequencyPlan FrequencyPlan, err error) {
}
frequencyPlan.DownlinkChannels = frequencyPlan.UplinkChannels
frequencyPlan.CFList = &lorawan.CFList{923600000, 923800000, 924000000, 924200000, 924400000}
frequencyPlan.ADR = &ADRConfig{MinDataRate: 0, MaxDataRate: 5, MinTXPower: 2, MaxTXPower: 14, StepTXPower: 2}
case pb_lorawan.FrequencyPlan_KR_920_923.String():
frequencyPlan.Band, err = lora.GetConfig(lora.KR_920_923, false, lorawan.DwellTimeNoLimit)
// TTN frequency plan includes extra channels next to the default channels:
Expand Down
6 changes: 3 additions & 3 deletions core/band/band_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,21 @@ func TestGet(t *testing.T) {
fp, err := Get("AS_923")
a.So(err, ShouldBeNil)
a.So(fp.CFList, ShouldBeNil)
a.So(fp.ADR, ShouldBeNil)
a.So(fp.ADR, ShouldNotBeNil)
}

{
fp, err := Get("AS_920_923")
a.So(err, ShouldBeNil)
a.So(fp.CFList, ShouldNotBeNil)
a.So(fp.ADR, ShouldBeNil)
a.So(fp.ADR, ShouldNotBeNil)
}

{
fp, err := Get("AS_923_925")
a.So(err, ShouldBeNil)
a.So(fp.CFList, ShouldNotBeNil)
a.So(fp.ADR, ShouldBeNil)
a.So(fp.ADR, ShouldNotBeNil)
}

{
Expand Down
3 changes: 3 additions & 0 deletions core/discovery/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ func (d *discoveryServer) GetByAppID(ctx context.Context, req *pb.GetByAppIDRequ
if err != nil {
return nil, err
}
service.Metadata = nil
return service, nil
}

Expand All @@ -189,6 +190,7 @@ func (d *discoveryServer) GetByGatewayID(ctx context.Context, req *pb.GetByGatew
if err != nil {
return nil, err
}
service.Metadata = nil
return service, nil
}

Expand All @@ -200,6 +202,7 @@ func (d *discoveryServer) GetByAppEUI(ctx context.Context, req *pb.GetByAppEUIRe
if err != nil {
return nil, err
}
service.Metadata = nil
return service, nil
}

Expand Down
5 changes: 5 additions & 0 deletions core/router/downlink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ import (
. "github.com/TheThingsNetwork/ttn/utils/testing"
"github.com/golang/mock/gomock"
. "github.com/smartystreets/assertions"
"github.com/spf13/viper"
"golang.org/x/net/context"
)

func init() {
viper.Set("eu-rx2-dr", "3")
}

// newReferenceDownlink returns a default uplink message
func newReferenceDownlink() *pb.DownlinkMessage {
up := &pb.DownlinkMessage{
Expand Down
2 changes: 1 addition & 1 deletion core/storage/redis_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (s *RedisStore) Keys(selector string) ([]string, error) {
var allKeys []string
var cursor uint64
for {
keys, next, err := s.client.Scan(cursor, selector, 0).Result()
keys, next, err := s.client.Scan(cursor, selector, 10000).Result()
if err != nil {
return nil, err
}
Expand Down
5 changes: 2 additions & 3 deletions mqtt/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# API Reference

* Host: `<Region>.thethings.network`, where `<Region>` is last part of the handler you registered your application to, e.g. `eu`.
* Port: `1883` or `8883` for TLS
* PEM encoded CA certificate for TLS: [mqtt-ca.pem](https://console.thethingsnetwork.org/mqtt-ca.pem)
- Note: When this certificate expires, we will migrate to Let's Encrypt certificates. Therefore you might want to include the [Let's Encrypt Roots](https://letsencrypt.org/certificates/) in your certificate chain.
* Port: `1883`, or `8883` for TLS
* For TLS, the server uses a Let's Encrypt certificate. If your server does not trust that yet, you might want to include the [Let's Encrypt Roots](https://letsencrypt.org/certificates/) in your certificate chain. Alternatively you can use our PEM-encoded CA certificate, which includes those roots as well: [mqtt-ca.pem](https://console.thethingsnetwork.org/mqtt-ca.pem)
* Username: Application ID
* Password: Application Access Key

Expand Down
38 changes: 35 additions & 3 deletions ttnctl/cmd/clients_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package cmd

import (
"net/http"

accountlib "github.com/TheThingsNetwork/go-account-lib/account"
"github.com/TheThingsNetwork/ttn/ttnctl/util"
"github.com/spf13/cobra"
Expand All @@ -12,7 +14,20 @@ import (
var clientRequestCmd = &cobra.Command{
Use: "request [Name] [Description]",
Short: "Request a client",
Long: "ttnctl clients request can be used to request an OAuth client from the network staff.",
Long: `ttnctl clients request can be used to request an OAuth client from the network staff.
You need to supply the following information:
- An identifier for your OAuth client; can contain lowercase letters, numbers, dashes and underscores, just like Application and Gateway IDs.
- A description that will be shown to users that are signing in.
- A callback URI where users will be redirected after login.
- The scopes that your client needs access to:
- apps: Create and delete Applications
- gateways: Create and delete Gateways
- profile: Edit user profiles
- Note that you may not need an OAuth client to manage devices.
- The grants that your client uses for login:
- authorization_code: OAuth 2.0 authorization code (this is probably what you need)
- refresh_token: OAuth 2.0 refresh token grant
- password: OAuth 2.0 password grant (this will usually not be accepted)`,
Example: `$ ttnctl clients request my-gateway-editor "Client used to consult and edit gateway information" --uri "https://mygatewayclient.org/oauth/callback" --scope "profile,gateways" --grants "authorization_code,refresh_token"
INFO OAuth client requested OAuthClientName=my-gateway-editor
`,
Expand All @@ -22,13 +37,30 @@ var clientRequestCmd = &cobra.Command{
var name = args[0]
var description = args[1]

ctx = ctx.WithField("OAuthClientName", name)

uri, err := cmd.Flags().GetString("uri")
if err != nil {
ctx.WithError(err).Fatal("Error with URI")
}

var uriOK bool
ctx.Info("Testing Callback URI: " + uri + "?code=test&state=test")
res, err := http.Get(uri + "?code=test&state=test")
switch {
case err != nil:
ctx.WithError(err).Error("Callback URI test failed.")
case res.StatusCode == 404:
ctx.Error("Callback URI was not found (404)")
case res.StatusCode >= 500:
ctx.Errorf("Callback URI errored (%d)", res.StatusCode)
default:
ctx.Infof("Callback URI seems to be reachable (returned %d)", res.StatusCode)
uriOK = true
}
if !uriOK && !confirm("Are you sure the URI is correct? (y/N)") {
ctx.Info("Aborting")
return
}

scopes := make([]string, 0)
strScopes, err := cmd.Flags().GetStringSlice("scope")
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion ttnctl/cmd/gateways_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var gatewaysListCmd = &cobra.Command{
lng = gateway.AntennaLocation.Longitude
alt = gateway.AntennaLocation.Altitude
}
table.AddRow(i+1, gateway.ID, gateway.Activated, gateway.FrequencyPlan, fmt.Sprintf("(%f, %f, %f)", lat, lng, alt))
table.AddRow(i+1, gateway.ID, gateway.Activated, gateway.FrequencyPlan, fmt.Sprintf("(%f, %f, %d)", lat, lng, alt))
}

fmt.Println()
Expand Down

0 comments on commit 4a193dc

Please sign in to comment.