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

Commit 47b47fb

Browse files
authored
Merge pull request #714 from TheThingsNetwork/develop
v2.9.3
2 parents 4a193dc + 55b53bd commit 47b47fb

File tree

11 files changed

+131
-11
lines changed

11 files changed

+131
-11
lines changed

core/band/band.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func Get(region string) (frequencyPlan FrequencyPlan, err error) {
113113
frequencyPlan.DisableUplinkChannel(channel)
114114
}
115115
}
116-
frequencyPlan.ADR = &ADRConfig{MinDataRate: 0, MaxDataRate: 3, MinTXPower: 10, MaxTXPower: 20, StepTXPower: 2}
116+
frequencyPlan.ADR = &ADRConfig{MinDataRate: 0, MaxDataRate: 5, MinTXPower: 10, MaxTXPower: 20, StepTXPower: 2}
117117
case pb_lorawan.FrequencyPlan_CN_470_510.String():
118118
frequencyPlan.Band, err = lora.GetConfig(lora.CN_470_510, false, lorawan.DwellTimeNoLimit)
119119
case pb_lorawan.FrequencyPlan_AS_923.String():

core/handler/application/metrics.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright © 2017 The Things Network
2+
// Use of this source code is governed by the MIT license that can be found in the LICENSE file.
3+
4+
package application
5+
6+
import (
7+
"github.com/prometheus/client_golang/prometheus"
8+
)
9+
10+
var applicationCount = prometheus.NewGaugeFunc(prometheus.GaugeOpts{
11+
Namespace: "ttn",
12+
Subsystem: "handler",
13+
Name: "registered_applications",
14+
Help: "Registered applications.",
15+
}, func() float64 {
16+
var count uint64
17+
for _, store := range stores {
18+
applications, err := store.Count()
19+
if err != nil {
20+
continue
21+
}
22+
count += uint64(applications)
23+
}
24+
return float64(count)
25+
})
26+
27+
func init() {
28+
prometheus.Register(applicationCount)
29+
}
30+
31+
var stores []*RedisApplicationStore
32+
33+
func countStore(store *RedisApplicationStore) {
34+
stores = append(stores, store)
35+
}

core/handler/application/store.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ func NewRedisApplicationStore(client *redis.Client, prefix string) Store {
3535
for v, f := range migrate.ApplicationMigrations(prefix) {
3636
store.AddMigration(v, f)
3737
}
38-
return &RedisApplicationStore{
38+
s := &RedisApplicationStore{
3939
store: store,
4040
}
41+
countStore(s)
42+
return s
4143
}
4244

4345
// RedisApplicationStore stores Applications in Redis.

core/handler/device/metrics.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright © 2017 The Things Network
2+
// Use of this source code is governed by the MIT license that can be found in the LICENSE file.
3+
4+
package device
5+
6+
import (
7+
"github.com/prometheus/client_golang/prometheus"
8+
)
9+
10+
var deviceCount = prometheus.NewGaugeFunc(prometheus.GaugeOpts{
11+
Namespace: "ttn",
12+
Subsystem: "handler",
13+
Name: "registered_devices",
14+
Help: "Registered devices.",
15+
}, func() float64 {
16+
var count uint64
17+
for _, store := range stores {
18+
devices, err := store.Count()
19+
if err != nil {
20+
continue
21+
}
22+
count += uint64(devices)
23+
}
24+
return float64(count)
25+
})
26+
27+
func init() {
28+
prometheus.Register(deviceCount)
29+
}
30+
31+
var stores []*RedisDeviceStore
32+
33+
func countStore(store *RedisDeviceStore) {
34+
stores = append(stores, store)
35+
}

core/handler/device/store.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ func NewRedisDeviceStore(client *redis.Client, prefix string) *RedisDeviceStore
6161
queues: queues,
6262
}
6363
s.AddBuiltinAttribute(defaultDeviceAttributes...)
64+
countStore(s)
6465
return s
6566
}
6667

core/networkserver/adr.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,11 +307,21 @@ func getAdrReqPayloads(dev *device.Device, frequencyPlan *band.FrequencyPlan, dr
307307
}
308308
}
309309
case pb_lorawan.FrequencyPlan_US_902_928.String(), pb_lorawan.FrequencyPlan_AU_915_928.String():
310+
var dr500 uint8
311+
switch dev.ADR.Band {
312+
case pb_lorawan.FrequencyPlan_US_902_928.String():
313+
dr500 = 4
314+
case pb_lorawan.FrequencyPlan_AU_915_928.String():
315+
dr500 = 6
316+
default:
317+
panic("could not determine 500kHz channel data rate index")
318+
}
319+
310320
// Adapted from https://github.com/brocaar/lorawan/blob/master/band/band_us902_928.go
311321
payloads = []lorawan.LinkADRReqPayload{
312322
{
313-
DataRate: 4, // fixed settings for 500kHz channel
314-
TXPower: 0, // fixed settings for 500kHz channel
323+
DataRate: dr500, // fixed settings for 500kHz channel
324+
TXPower: 0, // fixed settings for 500kHz channel
315325
Redundancy: lorawan.Redundancy{
316326
ChMaskCntl: 7,
317327
NbRep: uint8(dev.ADR.NbTrans),

core/networkserver/adr_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ func TestHandleDownlinkADR(t *testing.T) {
255255
a.So(fOpts[1].CID, ShouldEqual, lorawan.LinkADRReq)
256256
payload := new(lorawan.LinkADRReqPayload)
257257
payload.UnmarshalBinary(fOpts[1].Payload) // First LinkAdrReq
258-
a.So(payload.DataRate, ShouldEqual, 4) // 500kHz channel, so DR4
258+
a.So(payload.DataRate, ShouldEqual, 6) // 500kHz channel, so DR6
259259
a.So(payload.TXPower, ShouldEqual, 0) // Max tx power
260260
a.So(payload.Redundancy.ChMaskCntl, ShouldEqual, 7)
261261
// Ch 64-71, All 125 kHz channels off

core/networkserver/device/metrics.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright © 2017 The Things Network
2+
// Use of this source code is governed by the MIT license that can be found in the LICENSE file.
3+
4+
package device
5+
6+
import (
7+
"github.com/prometheus/client_golang/prometheus"
8+
)
9+
10+
var deviceCount = prometheus.NewGaugeFunc(prometheus.GaugeOpts{
11+
Namespace: "ttn",
12+
Subsystem: "networkserver",
13+
Name: "registered_devices",
14+
Help: "Registered devices.",
15+
}, func() float64 {
16+
var count uint64
17+
for _, store := range stores {
18+
devices, err := store.Count()
19+
if err != nil {
20+
continue
21+
}
22+
count += uint64(devices)
23+
}
24+
return float64(count)
25+
})
26+
27+
func init() {
28+
prometheus.Register(deviceCount)
29+
}
30+
31+
var stores []*RedisDeviceStore
32+
33+
func countStore(store *RedisDeviceStore) {
34+
stores = append(stores, store)
35+
}

core/networkserver/device/store.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,15 @@ func NewRedisDeviceStore(client *redis.Client, prefix string) Store {
4343
store.AddMigration(v, f)
4444
}
4545
frameStore := storage.NewRedisQueueStore(client, prefix+":"+redisFramesPrefix)
46-
return &RedisDeviceStore{
46+
s := &RedisDeviceStore{
4747
client: client,
4848
prefix: prefix,
4949
store: store,
5050
frameStore: frameStore,
5151
devAddrIndex: storage.NewRedisSetStore(client, prefix+":"+redisDevAddrPrefix),
5252
}
53+
countStore(s)
54+
return s
5355
}
5456

5557
// RedisDeviceStore stores Devices in Redis.

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ services:
107107
volumes:
108108
- "./.env/:/root/.env/"
109109
bridge:
110-
image: thethingsnetwork/lora-gateway-bridge
110+
image: thethingsnetwork/gateway-connector-bridge
111111
hostname: bridge
112112
ports:
113113
- "1700:1700/udp"

mqtt/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555

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

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

6060
**Usage (Go client):**
6161

@@ -126,7 +126,7 @@ you will see this on MQTT:
126126
}
127127
```
128128

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

131131
**Usage (Go client):**
132132

@@ -161,7 +161,7 @@ Instead of `payload_raw` you can also use `payload_fields` with an object of fie
161161
}
162162
```
163163

164-
**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}}'`
164+
**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}}'`
165165

166166
**Usage (Go client):**
167167

@@ -213,7 +213,7 @@ downlink as the _first_ or _last_ item in a the downlink queue.
213213
}
214214
```
215215

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

218218
**Usage (Go client):**
219219

0 commit comments

Comments
 (0)