Skip to content

Commit 497a1ac

Browse files
committed
Update the ChirpStack Simulator for ChirpStack v4.
1 parent 37a7e02 commit 497a1ac

File tree

13 files changed

+268
-242
lines changed

13 files changed

+268
-242
lines changed

Dockerfile-devel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.13-alpine
1+
FROM golang:1.18-alpine
22

33
ENV PROJECT_PATH=/chirpstack-simulator
44
ENV PATH=$PATH:$PROJECT_PATH/build

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2020 Orne Brocaar
3+
Copyright (c) 2022 Orne Brocaar
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# ChirpStack Simulator
22

33
ChirpStack Simulator is an open-source simulator for the [ChirpStack](https://www.chirpstack.io)
4-
open-source LoRaWAN<sup>&reg;</sup> Network-Server stack. It simulates
4+
open-source LoRaWAN<sup>&reg;</sup> Network-Server (v4). It simulates
55
a configurable number of devices and gateways, which will be automatically
66
created on starting the simulation.
77

@@ -36,8 +36,8 @@ For generating a configuration template, use the following command:
3636
log_level=4
3737

3838

39-
# Application Server configuration.
40-
[application_server]
39+
# ChirpStack configuration.
40+
[chirpstack]
4141

4242
# API configuration.
4343
#
@@ -46,20 +46,18 @@ log_level=4
4646
# * Gateways
4747
# * Application
4848
# * Devices
49-
[application_server.api]
49+
[chirpstack.api]
5050

5151
# JWT token.
5252
#
53-
# The JWT token to connect to the ChirpStack Application Server API. This
54-
# token can be generated using the login API endpoint. In the near-future
55-
# it will be possible to generate these tokens within the web-interface:
56-
# https://github.com/brocaar/chirpstack-application-server/pull/421
57-
jwt_token="PUT_YOUR_JWT_TOKEN_HERE"
53+
# API key to connect to the ChirpStack API. This API key can created within
54+
# the ChirpStack web-interface.
55+
api_key="PUT_YOUR_API_KEY_HERE"
5856

5957
# Server.
6058
#
61-
# This must point to the external API server of the ChirpStack Application
62-
# Server. When the server is running on the same machine, keep this to the
59+
# This must point to the API interface of ChirpStack.
60+
# If the server is running on the same machine, keep this to the
6361
# default value.
6462
server="127.0.0.1:8080"
6563

@@ -72,8 +70,8 @@ log_level=4
7270
# MQTT integration configuration.
7371
#
7472
# This integration is used for counting the number of uplinks that are
75-
# published by the ChirpStack Application Server integration.
76-
[application_server.integration.mqtt]
73+
# published by the ChirpStack MQTT integration.
74+
[chirpstack.integration.mqtt]
7775

7876
# MQTT server.
7977
server="tcp://127.0.0.1:1883"
@@ -85,14 +83,8 @@ log_level=4
8583
password=""
8684

8785

88-
# Network Server configuration.
89-
#
90-
# This configuration is used to simulate LoRa gateways using the MQTT gateway
91-
# backend.
92-
[network_server]
93-
9486
# MQTT gateway backend.
95-
[network_server.gateway.backend.mqtt]
87+
[chirpstack.gateway.backend.mqtt]
9688

9789
# MQTT server.
9890
server="tcp://127.0.0.1:1883"
@@ -107,11 +99,10 @@ log_level=4
10799
# Simulator configuration.
108100
[[simulator]]
109101

110-
# Service-profile ID.
102+
# Tenant ID.
111103
#
112-
# It is recommended to create a new organization with a new service-profile
113-
# in the ChirpStack Application Server.
114-
service_profile_id="PUT_YOUR_SERVICE_PROFILE_ID_HERE"
104+
# It is recommended to create a new tenant for simulations.
105+
tenant_id="PUT_YOUR_TENANT_ID_HERE"
115106

116107
# Duration.
117108
#
@@ -159,10 +150,10 @@ activation_time="1m"
159150
max_count=5
160151

161152
# Event topic template.
162-
event_topic_template="gateway/{{ .GatewayID }}/event/{{ .Event }}"
153+
event_topic_template="eu868/gateway/{{ .GatewayID }}/event/{{ .Event }}"
163154

164155
# Command topic template.
165-
command_topic_template="gateway/{{ .GatewayID }}/command/{{ .Command }}"
156+
command_topic_template="eu868/gateway/{{ .GatewayID }}/command/{{ .Command }}"
166157

167158

168159
# Prometheus metrics configuration.
@@ -173,7 +164,7 @@ activation_time="1m"
173164
# * Join-Accepts received
174165
# * Uplinks sent (by the devices)
175166
# * Uplinks sent (by the gateways)
176-
# * Uplinks sent (by the ChirpStack Application Server MQTT integration)
167+
# * Uplinks sent (by the ChirpStack MQTT integration)
177168
[prometheus]
178169

179170
# IP:port to bind the Prometheus endpoint to.

cmd/chirpstack-simulator/cmd/configfile.go

Lines changed: 42 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ import (
1111
)
1212

1313
const configTemplate = `[general]
14-
# Log level
15-
#
16-
# debug=5, info=4, warning=3, error=2, fatal=1, panic=0
17-
log_level={{ .General.LogLevel }}
14+
# Log level
15+
#
16+
# debug=5, info=4, warning=3, error=2, fatal=1, panic=0
17+
log_level={{ .General.LogLevel }}
1818
1919
20-
# Application Server configuration.
21-
[application_server]
20+
# ChirpStack configuration.
21+
[chirpstack]
2222
2323
# API configuration.
2424
#
@@ -27,74 +27,62 @@ log_level={{ .General.LogLevel }}
2727
# * Gateways
2828
# * Application
2929
# * Devices
30-
[application_server.api]
31-
32-
# JWT token.
33-
#
34-
# The JWT token to connect to the ChirpStack Application Server API. This
35-
# token can be generated using the login API endpoint. In the near-future
36-
# it will be possible to generate these tokens within the web-interface:
37-
# https://github.com/brocaar/chirpstack-application-server/pull/421
38-
jwt_token="{{ .ApplicationServer.API.JWTToken }}"
30+
[chirpstack.api]
3931
40-
# Server.
41-
#
42-
# This must point to the external API server of the ChirpStack Application
43-
# Server. When the server is running on the same machine, keep this to the
44-
# default value.
45-
server="{{ .ApplicationServer.API.Server }}"
32+
# API key.
33+
#
34+
# The API key can be obtained through the ChirpStack web-interface.
35+
api_key="{{ .ChirpStack.API.APIKey }}"
4636
47-
# Insecure.
48-
#
49-
# Set this to true when the endpoint is not using TLS.
50-
insecure={{ .ApplicationServer.API.Insecure }}
37+
# Server.
38+
#
39+
# This must point to the ChirpStack API interface.
40+
server="{{ .ChirpStack.API.Server }}"
5141
42+
# Insecure.
43+
#
44+
# Set this to true when the endpoint is not using TLS.
45+
insecure={{ .ChirpStack.API.Insecure }}
5246
53-
# MQTT integration configuration.
54-
#
55-
# This integration is used for counting the number of uplinks that are
56-
# published by the ChirpStack Application Server integration.
57-
[application_server.integration.mqtt]
5847
59-
# MQTT server.
60-
server="{{ .ApplicationServer.Integration.MQTT.Server }}"
48+
# MQTT integration configuration.
49+
#
50+
# This integration is used for counting the number of uplinks that are
51+
# published by the ChirpStack MQTT integration.
52+
[chirpstack.integration.mqtt]
6153
62-
# Username.
63-
username="{{ .ApplicationServer.Integration.MQTT.Username }}"
54+
# MQTT server.
55+
server="{{ .ChirpStack.Integration.MQTT.Server }}"
6456
65-
# Password.
66-
password="{{ .ApplicationServer.Integration.MQTT.Password }}"
57+
# Username.
58+
username="{{ .ChirpStack.Integration.MQTT.Username }}"
6759
60+
# Password.
61+
password="{{ .ChirpStack.Integration.MQTT.Password }}"
6862
69-
# Network Server configuration.
70-
#
71-
# This configuration is used to simulate LoRa gateways using the MQTT gateway
72-
# backend.
73-
[network_server]
7463
7564
# MQTT gateway backend.
76-
[network_server.gateway.backend.mqtt]
65+
[chirpstack.gateway.backend.mqtt]
7766
78-
# MQTT server.
79-
server="{{ .NetworkServer.Gateway.Backend.MQTT.Server }}"
67+
# MQTT server.
68+
server="{{ .NetworkServer.Gateway.Backend.MQTT.Server }}"
8069
81-
# Username.
82-
username="{{ .NetworkServer.Gateway.Backend.MQTT.Username }}"
70+
# Username.
71+
username="{{ .NetworkServer.Gateway.Backend.MQTT.Username }}"
8372
84-
# Password.
85-
password="{{ .NetworkServer.Gateway.Backend.MQTT.Password }}"
73+
# Password.
74+
password="{{ .NetworkServer.Gateway.Backend.MQTT.Password }}"
8675
8776
8877
# Simulator configuration.
8978
#
9079
# Example:
9180
# [[simulator]]
9281
#
93-
# # Service-profile ID.
82+
# # Tenant ID.
9483
# #
95-
# # It is recommended to create a new organization with a new service-profile
96-
# # in the ChirpStack Application Server.
97-
# service_profile_id="1f32476e-a112-4f00-bcc7-4aab4bfefa1d"
84+
# # It is recommended to create a new tenant in ChirpStack.
85+
# tenant_id="1f32476e-a112-4f00-bcc7-4aab4bfefa1d"
9886
#
9987
# # Duration.
10088
# #
@@ -136,10 +124,10 @@ log_level={{ .General.LogLevel }}
136124
# [simulator.gateway]
137125
#
138126
# # Event topic template.
139-
# event_topic_template="{{ "gateway/{{ .GatewayID }}/event/{{ .Event }}" }}"
127+
# event_topic_template="eu868/{{ "gateway/{{ .GatewayID }}/event/{{ .Event }}" }}"
140128
#
141129
# # Command topic template.
142-
# command_topic_template="{{ "gateway/{{ .GatewayID }}/command/{{ .Command }}" }}"
130+
# command_topic_template="eu868/{{ "gateway/{{ .GatewayID }}/command/{{ .Command }}" }}"
143131
#
144132
# # Min number of receiving gateways.
145133
# min_count=3

examples/single_uplink/main.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ import (
66
"sync"
77
"time"
88

9-
"github.com/brocaar/chirpstack-api/go/v3/common"
10-
"github.com/brocaar/chirpstack-api/go/v3/gw"
119
"github.com/brocaar/chirpstack-simulator/simulator"
1210
"github.com/brocaar/lorawan"
11+
"github.com/chirpstack/chirpstack/api/go/v4/gw"
1312
log "github.com/sirupsen/logrus"
1413
)
1514

@@ -26,8 +25,8 @@ func main() {
2625
sgw, err := simulator.NewGateway(
2726
simulator.WithMQTTCredentials("localhost:1883", "", ""),
2827
simulator.WithGatewayID(gatewayID),
29-
simulator.WithEventTopicTemplate("gateway/{{ .GatewayID }}/event/{{ .Event }}"),
30-
simulator.WithCommandTopicTemplate("gateway/{{ .GatewayID }}/command/{{ .Command }}"),
28+
simulator.WithEventTopicTemplate("eu868/gateway/{{ .GatewayID }}/event/{{ .Event }}"),
29+
simulator.WithCommandTopicTemplate("eu868/gateway/{{ .GatewayID }}/command/{{ .Command }}"),
3130
)
3231
if err != nil {
3332
panic(err)
@@ -40,14 +39,15 @@ func main() {
4039
simulator.WithUplinkInterval(time.Second),
4140
simulator.WithUplinkCount(1),
4241
simulator.WithUplinkPayload(true, 10, []byte{1, 2, 3}),
43-
simulator.WithUplinkTXInfo(gw.UplinkTXInfo{
44-
Frequency: 868100000,
45-
Modulation: common.Modulation_LORA,
46-
ModulationInfo: &gw.UplinkTXInfo_LoraModulationInfo{
47-
LoraModulationInfo: &gw.LoRaModulationInfo{
48-
Bandwidth: 125,
49-
SpreadingFactor: 7,
50-
CodeRate: "3/4",
42+
simulator.WithUplinkTXInfo(gw.UplinkTxInfo{
43+
Frequency: 868100000,
44+
Modulation: &gw.Modulation{
45+
Parameters: &gw.Modulation_Lora{
46+
Lora: &gw.LoraModulationInfo{
47+
Bandwidth: 125000,
48+
SpreadingFactor: 7,
49+
CodeRate: gw.CodeRate_CR_4_6,
50+
},
5151
},
5252
},
5353
}),

go.mod

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,17 @@ module github.com/brocaar/chirpstack-simulator
33
go 1.13
44

55
require (
6-
github.com/brocaar/chirpstack-api/go/v3 v3.1.3
76
github.com/brocaar/lorawan v0.0.0-20191105091820-9ed596703a6c
7+
github.com/chirpstack/chirpstack/api/go/v4 v4.0.0-rc.2
88
github.com/eclipse/paho.mqtt.golang v1.2.0
99
github.com/gofrs/uuid v3.2.0+incompatible
10-
github.com/golang/protobuf v1.3.2
10+
github.com/golang/protobuf v1.5.2
1111
github.com/pkg/errors v0.8.1
1212
github.com/prometheus/client_golang v0.9.3
1313
github.com/sirupsen/logrus v1.4.2
1414
github.com/smartystreets/assertions v1.0.0 // indirect
1515
github.com/spf13/cobra v0.0.5
1616
github.com/spf13/viper v1.5.0
17-
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 // indirect
18-
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b // indirect
1917
golang.org/x/text v0.3.2 // indirect
20-
google.golang.org/grpc v1.26.0
18+
google.golang.org/grpc v1.45.0
2119
)

0 commit comments

Comments
 (0)