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 #714 from TheThingsNetwork/develop
Browse files Browse the repository at this point in the history
v2.9.3
  • Loading branch information
htdvisser authored May 23, 2018
2 parents 4a193dc + 55b53bd commit 47b47fb
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 11 deletions.
2 changes: 1 addition & 1 deletion core/band/band.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func Get(region string) (frequencyPlan FrequencyPlan, err error) {
frequencyPlan.DisableUplinkChannel(channel)
}
}
frequencyPlan.ADR = &ADRConfig{MinDataRate: 0, MaxDataRate: 3, MinTXPower: 10, MaxTXPower: 20, StepTXPower: 2}
frequencyPlan.ADR = &ADRConfig{MinDataRate: 0, MaxDataRate: 5, MinTXPower: 10, MaxTXPower: 20, StepTXPower: 2}
case pb_lorawan.FrequencyPlan_CN_470_510.String():
frequencyPlan.Band, err = lora.GetConfig(lora.CN_470_510, false, lorawan.DwellTimeNoLimit)
case pb_lorawan.FrequencyPlan_AS_923.String():
Expand Down
35 changes: 35 additions & 0 deletions core/handler/application/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright © 2017 The Things Network
// Use of this source code is governed by the MIT license that can be found in the LICENSE file.

package application

import (
"github.com/prometheus/client_golang/prometheus"
)

var applicationCount = prometheus.NewGaugeFunc(prometheus.GaugeOpts{
Namespace: "ttn",
Subsystem: "handler",
Name: "registered_applications",
Help: "Registered applications.",
}, func() float64 {
var count uint64
for _, store := range stores {
applications, err := store.Count()
if err != nil {
continue
}
count += uint64(applications)
}
return float64(count)
})

func init() {
prometheus.Register(applicationCount)
}

var stores []*RedisApplicationStore

func countStore(store *RedisApplicationStore) {
stores = append(stores, store)
}
4 changes: 3 additions & 1 deletion core/handler/application/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ func NewRedisApplicationStore(client *redis.Client, prefix string) Store {
for v, f := range migrate.ApplicationMigrations(prefix) {
store.AddMigration(v, f)
}
return &RedisApplicationStore{
s := &RedisApplicationStore{
store: store,
}
countStore(s)
return s
}

// RedisApplicationStore stores Applications in Redis.
Expand Down
35 changes: 35 additions & 0 deletions core/handler/device/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright © 2017 The Things Network
// Use of this source code is governed by the MIT license that can be found in the LICENSE file.

package device

import (
"github.com/prometheus/client_golang/prometheus"
)

var deviceCount = prometheus.NewGaugeFunc(prometheus.GaugeOpts{
Namespace: "ttn",
Subsystem: "handler",
Name: "registered_devices",
Help: "Registered devices.",
}, func() float64 {
var count uint64
for _, store := range stores {
devices, err := store.Count()
if err != nil {
continue
}
count += uint64(devices)
}
return float64(count)
})

func init() {
prometheus.Register(deviceCount)
}

var stores []*RedisDeviceStore

func countStore(store *RedisDeviceStore) {
stores = append(stores, store)
}
1 change: 1 addition & 0 deletions core/handler/device/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func NewRedisDeviceStore(client *redis.Client, prefix string) *RedisDeviceStore
queues: queues,
}
s.AddBuiltinAttribute(defaultDeviceAttributes...)
countStore(s)
return s
}

Expand Down
14 changes: 12 additions & 2 deletions core/networkserver/adr.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,21 @@ func getAdrReqPayloads(dev *device.Device, frequencyPlan *band.FrequencyPlan, dr
}
}
case pb_lorawan.FrequencyPlan_US_902_928.String(), pb_lorawan.FrequencyPlan_AU_915_928.String():
var dr500 uint8
switch dev.ADR.Band {
case pb_lorawan.FrequencyPlan_US_902_928.String():
dr500 = 4
case pb_lorawan.FrequencyPlan_AU_915_928.String():
dr500 = 6
default:
panic("could not determine 500kHz channel data rate index")
}

// Adapted from https://github.com/brocaar/lorawan/blob/master/band/band_us902_928.go
payloads = []lorawan.LinkADRReqPayload{
{
DataRate: 4, // fixed settings for 500kHz channel
TXPower: 0, // fixed settings for 500kHz channel
DataRate: dr500, // fixed settings for 500kHz channel
TXPower: 0, // fixed settings for 500kHz channel
Redundancy: lorawan.Redundancy{
ChMaskCntl: 7,
NbRep: uint8(dev.ADR.NbTrans),
Expand Down
2 changes: 1 addition & 1 deletion core/networkserver/adr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ func TestHandleDownlinkADR(t *testing.T) {
a.So(fOpts[1].CID, ShouldEqual, lorawan.LinkADRReq)
payload := new(lorawan.LinkADRReqPayload)
payload.UnmarshalBinary(fOpts[1].Payload) // First LinkAdrReq
a.So(payload.DataRate, ShouldEqual, 4) // 500kHz channel, so DR4
a.So(payload.DataRate, ShouldEqual, 6) // 500kHz channel, so DR6
a.So(payload.TXPower, ShouldEqual, 0) // Max tx power
a.So(payload.Redundancy.ChMaskCntl, ShouldEqual, 7)
// Ch 64-71, All 125 kHz channels off
Expand Down
35 changes: 35 additions & 0 deletions core/networkserver/device/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright © 2017 The Things Network
// Use of this source code is governed by the MIT license that can be found in the LICENSE file.

package device

import (
"github.com/prometheus/client_golang/prometheus"
)

var deviceCount = prometheus.NewGaugeFunc(prometheus.GaugeOpts{
Namespace: "ttn",
Subsystem: "networkserver",
Name: "registered_devices",
Help: "Registered devices.",
}, func() float64 {
var count uint64
for _, store := range stores {
devices, err := store.Count()
if err != nil {
continue
}
count += uint64(devices)
}
return float64(count)
})

func init() {
prometheus.Register(deviceCount)
}

var stores []*RedisDeviceStore

func countStore(store *RedisDeviceStore) {
stores = append(stores, store)
}
4 changes: 3 additions & 1 deletion core/networkserver/device/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ func NewRedisDeviceStore(client *redis.Client, prefix string) Store {
store.AddMigration(v, f)
}
frameStore := storage.NewRedisQueueStore(client, prefix+":"+redisFramesPrefix)
return &RedisDeviceStore{
s := &RedisDeviceStore{
client: client,
prefix: prefix,
store: store,
frameStore: frameStore,
devAddrIndex: storage.NewRedisSetStore(client, prefix+":"+redisDevAddrPrefix),
}
countStore(s)
return s
}

// RedisDeviceStore stores Devices in Redis.
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ services:
volumes:
- "./.env/:/root/.env/"
bridge:
image: thethingsnetwork/lora-gateway-bridge
image: thethingsnetwork/gateway-connector-bridge
hostname: bridge
ports:
- "1700:1700/udp"
Expand Down
8 changes: 4 additions & 4 deletions mqtt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

Note: Some values may be omitted if they are `null`, `false`, `""` or `0`.

**Usage (Mosquitto):** `mosquitto_sub -h <Region>.thethings.network:1883 -d -t 'my-app-id/devices/my-dev-id/up'`
**Usage (Mosquitto):** `mosquitto_sub -h <Region>.thethings.network -d -t 'my-app-id/devices/my-dev-id/up'`

**Usage (Go client):**

Expand Down Expand Up @@ -126,7 +126,7 @@ you will see this on MQTT:
}
```

**Usage (Mosquitto):** `mosquitto_pub -h <Region>.thethings.network:1883 -d -t 'my-app-id/devices/my-dev-id/down' -m '{"port":1,"payload_raw":"AQIDBA=="}'`
**Usage (Mosquitto):** `mosquitto_pub -h <Region>.thethings.network -d -t 'my-app-id/devices/my-dev-id/down' -m '{"port":1,"payload_raw":"AQIDBA=="}'`

**Usage (Go client):**

Expand Down Expand Up @@ -161,7 +161,7 @@ Instead of `payload_raw` you can also use `payload_fields` with an object of fie
}
```

**Usage (Mosquitto):** `mosquitto_pub -h <Region>.thethings.network:1883 -d -t 'my-app-id/devices/my-dev-id/down' -m '{"port":1,"payload_fields":{"led":true}}'`
**Usage (Mosquitto):** `mosquitto_pub -h <Region>.thethings.network -d -t 'my-app-id/devices/my-dev-id/down' -m '{"port":1,"payload_fields":{"led":true}}'`

**Usage (Go client):**

Expand Down Expand Up @@ -213,7 +213,7 @@ downlink as the _first_ or _last_ item in a the downlink queue.
}
```

**Usage (Mosquitto):** `mosquitto_sub -h <Region>.thethings.network:1883 -d -t 'my-app-id/devices/my-dev-id/events/activations'`
**Usage (Mosquitto):** `mosquitto_sub -h <Region>.thethings.network -d -t 'my-app-id/devices/my-dev-id/events/activations'`

**Usage (Go client):**

Expand Down

0 comments on commit 47b47fb

Please sign in to comment.