当前位置:   article > 正文

LoRaWAN 服务器 ChirpStack 部署教程

chirpstack

ChirpStack 简介

ChirpStack 是一款开源的 LoRaWAN 网络服务器,可用于建立私人或公共 LoRaWAN 网。ChirpStack 为网关、设备和租户的管理提供了一个 web 界面,并与主要的云提供商、数据库和通常用于处理设备数据的服务进行了数据集成,主要的集成服务包括: MQTT 前向转发代理、HTTP 转发代理、influxDB入库服务等。ChirpStack 还提供了基于 gRPC 的 API,可用于集成或扩展 ChirpStacck 的各种功能。

ChirpStack 架构

ChirpStack 项目的架构图如下所示:
在这里插入图片描述

在架构图中,可以看到 LoRa Gateway 与服务端连接的方式有 2 种。一种是由 Packet Forwarder 直接与 ChirpStack Gateway Bridge 连接,另一种在 LoRa 网关内直接集成了 Packet Forwarder 和 ChirpStack Gateway Bridge 这两个组件,然后与 MQTT Broker 进行连接。

Chirpstack 部署

Chirpstack 部署方式

Chirpstack 可以以 Docker 方式部署,同时,也可以在 Debian/Ubuntu 服务器上单独部署。在 Debian/Ubuntu 服务器上单独部署,需要先安装依赖包,再进行 Chirpstack 的部署,实际操作中,我觉得比较麻烦,下面就一在 Docker 运行的方式进行部署说明。

运行环境

在本教程中,使用友善之臂的 nanopi NEO3 作为核心板作为运行机器。硬件参数如下所示:
在这里插入图片描述

  • Soc: RockChip RK3328, Quad-core 64-bit high-performance Cortex A53
  • RAM: 1GB/2GB DDR4
  • LAN: 10/100/1000M 以太网,带全球唯一MAC地址
  • USB Host: 1x USB3.0 Type A and 2x USB2.0 on 2.54mm pin header
  • MicroSD Slot: MicroSD x 1 for system boot and storage
  • LED: Power LED x 1, System LED x 1
  • Key: User Key x 1
  • Fan: 2Pin JST ZH 1.5mm Connector for 5V Fan
  • GPIO: 2.54mm pitch 26 pin-header, include I2C, UART, SPI, I2S, GPIO
  • Serial Debug Port: 2.54mm pitch 3 pin-header, 1500000bps
  • Power: 5V/1A, via Type-C or GPIO
  • PCB Dimension: 48 x 48mm
  • Working Temperature: -20℃ to 70℃
  • Weight: 22g

友善之臂官方提供的系统镜像有基于 openwrt 和 ubuntu core 定制过的系统。不过,根据我的个人爱好,Nanopi NEO3 我运行的是 Armbian 系统。

克隆 Github 仓库

Chirpstack 官方提供了一个快速部署 Chirpstack 的 Github 仓库,利用 dockper compose 工具,对 Chirpstack 服务进行快速部署。

git clone https://github.com/chirpstack/chirpstack-docker.git
  • 1

启动服务

cd chirpstack-docker
docker-compose up -d
  • 1
  • 2

查看 docker 运行状态

等待 docker 启动完成后,不改变系统路径,直接在命令行输入:

docker compose ls
  • 1

命令行返回 compose 启动的情况:

NAME                STATUS              CONFIG FILES
chirpstack-docker   running(6)          /home/sage/chirpstack-docker/docker-compose.yml
  • 1
  • 2

然后,再查看 docker compose 启动的容器运行情况:

docker compose ps
  • 1

运行结果如下所示:

在这里插入图片描述

访问 Chirpstack 服务

使用 Web 浏览器访问本地的 Nanopi NEO3 的 8080 端口,就可以看见 Chirpstack 的服务登陆页。我的 Nanopi NEO3 地址是 192.168.10.125 所以,我用浏览器直接访问“192.168.10.125:8080”端口后,自动跳转到 Chirpstack 的登陆页。

在这里插入图片描述

登陆的用户名和密码默认是: admin/admin,登陆成功后,就可以看到 Chirpstack 的 dashboard 页面了。

在这里插入图片描述

访问 Chirpstack 的 Swagger 接口

在浏览器中访问 8090 端口,就可以进入 Chirpstack 的 Swagger 后端接口 API 文档。我这里访问的是 Nanopi NEO3 的局域网地址“192.168.10.125:8090”。

在这里插入图片描述

到此,Chirpstack 使用 Docker 的快速部署就完成了。

Chirpstack 配置

chirpstack-docker 目录

从 Github 获取 chirpstack-docker 工程后,可以查看工程的目录结构如下所示:

.
├── configuration
│   ├── chirpstack
│   │   ├── chirpstack.toml
│   │   ├── region_cn470_0.toml
│   │   ├── region_cn470_10.toml
│   │   ├── region_cn470_11.toml
|   │   ├── ...
│   │   ├── region_cn779.toml
│   │   ├── region_eu433.toml
│   │   ├── region_eu868.toml
│   ├── chirpstack-gateway-bridge
│   │   └── chirpstack-gateway-bridge.toml
│   ├── mosquitto
│   │   └── mosquitto.conf
│   └── postgresql
│       └── initdb
│           ├── 001-init-chirpstack.sh
│           └── 002-chirpstack_extensions.sh
├── docker-compose.yml
├── LICENSE
├── lorawan-devices
├── Makefile
└── README.md
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • configuration: chirpstack 服务配置总目录,目录下分为 chirpstack 、 chirpstack-gateway-bridge 、 mosquitto 和 postgresql 的配置。
    • chirpstack: chirpstack.toml是 chirpstack 的整体配置,region_xxxxx.toml 文件时针对不同地区的 LoRaWAN 参数的网络设置。
    • chirpstack-gateway-bridge: chirpstack-gateway-bridge 网关桥的配置文件。
    • mosquitto: mqtt 服务中间件的配置目录,具体配置在 mosquitto.conf中进行配置即可。
    • postgresql: chirpstack 数据库配置文件目录,默认部署时,可以先不更改配置。
  • docker-compose.yml: chirpstack 进行 docker 部署时的 docker compose 文件,规定了镜像依赖,docker 网络以及数据持久化的相关信息。
  • lorawan-devices: LoRaWAN 设备的存储库。可以通过 make import-lorawan-devices指令将 LoRaWAN 的终端设备导入到 chirpstack 数据库中。

配置示例

chirpstack 在部署时,只需要将 configuration/chirpstack目录下的 chirpstack.tomlregion_xxxxx.toml文件配置好,就可以了。其他的配置,在刚上手的时候,可以先不用管。

先看 chirpstack.toml文件的配置示例:

# Logging.
[logging]

  # Log level.
  #
  # Options are: trace, debug, info, warn error.
  level="info"


# PostgreSQL configuration.
[postgresql]

  # PostgreSQL DSN.
  #
  # Format example: postgres://<USERNAME>:<PASSWORD>@<HOSTNAME>/<DATABASE>?sslmode=<SSLMODE>.
  #
  # SSL mode options:
  #  * disable - no SSL
  #  * require - Always SSL (skip verification)
  #  * verify-ca - Always SSL (verify that the certificate presented by the server was signed by a trusted CA)
  #  * verify-full - Always SSL (verify that the certification presented by the server was signed by a trusted CA and the server host name matches the one in the certificate)
  dsn="postgres://chirpstack:chirpstack@$POSTGRESQL_HOST/chirpstack?sslmode=disable"

  # Max open connections.
  #
  # This sets the max. number of open connections that are allowed in the
  # PostgreSQL connection pool.
  max_open_connections=10

  # Min idle connections.
  #
  # This sets the min. number of idle connections in the PostgreSQL connection
  # pool (0 = equal to max_open_connections).
  min_idle_connections=0


# Redis configuration.
[redis]

  # Server address or addresses.
  #
  # Set multiple addresses when connecting to a cluster.
  servers=[
    "redis://$REDIS_HOST/",
  ]

  # TLS enabled.
  tls_enabled=false

  # Redis Cluster.
  #
  # Set this to true when the provided URLs are pointing to a Redis Cluster
  # instance.
  cluster=false


# Network related configuration.
[network]

  # Network identifier (NetID, 3 bytes) encoded as HEX (e.g. 010203).
  net_id="000000"

  # Enabled regions.
  #
  # Multiple regions can be enabled simultaneously. Each region must match
  # the 'name' parameter of the region configuration in '[[regions]]'.
  enabled_regions=[
    "as923",
    "as923_2",
    "as923_3",
    "as923_4",
    "au915_0",
    "cn470_10",
    "cn779",
    "eu433",
    "eu868",
    "in865",
    "ism2400",
    "kr920",
    "ru864",
    "us915_0",
    "us915_1",
  ]


# API interface configuration.
[api]

  # interface:port to bind the API interface to.
  bind="0.0.0.0:8080"

  # Secret.
  #
  # This secret is used for generating login and API tokens, make sure this
  # is never exposed. Changing this secret will invalidate all login and API
  # tokens. The following command can be used to generate a random secret:
  #   openssl rand -base64 32
  secret="you-must-replace-this"


[integration]
  enabled=["mqtt"]

  [integration.mqtt]
    server="tcp://$MQTT_BROKER_HOST:1883/"
    json=true
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106

配置说明

chirpstack.toml文件中的配置主要有以下几项:

  • logging: 配置日志等级,可配置为 trace, debug, info, warn, error 其中某一项的值。
  • postgresql: chirpstack 连接 postgresql 的参数,包括用户名、密码、最大连接数等。
  • redis: chirpstack 的 redis 缓存地址等配置。
  • network: 网络服务器总体配置,配置内容包括网络编号,可用的 regions 参数等。(regions 参数是根据各地区的无线电组织划分的专用频段来设定的,在使用时应该遵循所在地区的无线电使用规范)。
  • api: chirpstack 接口和秘钥的配置。
  • integration: chirpstack 的插件配置,使用时根据需要进行启用,学习是使用默认配置。

地区参数配置示例

# This file contains an example CN470 example (channels 0-7).
[[regions]]

  # Name is an use-defined identifier for this region.
  name="cn470_0"

  # Common-name refers to the common-name of this region as defined by
  # the LoRa Alliance.
  common_name="CN470"


  # Gateway configuration.
  [regions.gateway]

    # Force gateways as private.
    #
    # If enabled, gateways can only be used by devices under the same tenant.
    force_gws_private=false

    
    # Gateway backend configuration.
    [regions.gateway.backend]

      # The enabled backend type.
      enabled="mqtt"

      # MQTT configuration.
      [regions.gateway.backend.mqtt]

        # Event topic template.
        event_topic="cn470_0/gateway/+/event/+"

        # Command topic template.
        command_topic="cn470_0/gateway/{{ gateway_id }}/command/{{ command }}"

        # MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws)
        server="tcp://$MQTT_BROKER_HOST:1883"

        # Connect with the given username (optional)
        username=""

        # Connect with the given password (optional)
        password=""

        # Quality of service level
        #
        # 0: at most once
        # 1: at least once
        # 2: exactly once
        #
        # Note: an increase of this value will decrease the performance.
        # For more information: https://www.hivemq.com/blog/mqtt-essentials-part-6-mqtt-quality-of-service-levels
        qos=0

        # Clean session
        #
        # Set the "clean session" flag in the connect message when this client
        # connects to an MQTT broker. By setting this flag you are indicating
        # that no messages saved by the broker for this client should be delivered.
        clean_session=false

        # Client ID
        #
        # Set the client id to be used by this client when connecting to the MQTT
        # broker. A client id must be no longer than 23 characters. If left blank,
        # a random id will be generated by ChirpStack.
        client_id=""

        # CA certificate file (optional)
        #
        # Use this when setting up a secure connection (when server uses ssl://...)
        # but the certificate used by the server is not trusted by any CA certificate
        # on the server (e.g. when self generated).
        ca_cert=""

        # TLS certificate file (optional)
        tls_cert=""

        # TLS key file (optional)
        tls_key=""


    # Gateway channel configuration.
    #
    # Note: this configuration is only used in case the gateway is using the
    # ChirpStack Concentratord daemon. In any other case, this configuration 
    # is ignored.
    [[regions.gateway.channels]]
      frequency=470300000
      bandwidth=125000
      modulation="LORA"
      spreading_factors=[7, 8, 9, 10, 11, 12]

    [[regions.gateway.channels]]
      frequency=470500000
      bandwidth=125000
      modulation="LORA"
      spreading_factors=[7, 8, 9, 10, 11, 12]

    [[regions.gateway.channels]]
      frequency=470700000
      bandwidth=125000
      modulation="LORA"
      spreading_factors=[7, 8, 9, 10, 11, 12]

    [[regions.gateway.channels]]
      frequency=470900000
      bandwidth=125000
      modulation="LORA"
      spreading_factors=[7, 8, 9, 10, 11, 12]

    [[regions.gateway.channels]]
      frequency=471100000
      bandwidth=125000
      modulation="LORA"
      spreading_factors=[7, 8, 9, 10, 11, 12]

    [[regions.gateway.channels]]
      frequency=471300000
      bandwidth=125000
      modulation="LORA"
      spreading_factors=[7, 8, 9, 10, 11, 12]

    [[regions.gateway.channels]]
      frequency=471500000
      bandwidth=125000
      modulation="LORA"
      spreading_factors=[7, 8, 9, 10, 11, 12]

    [[regions.gateway.channels]]
      frequency=471700000
      bandwidth=125000
      modulation="LORA"
      spreading_factors=[7, 8, 9, 10, 11, 12]


  # Region specific network configuration.
  [regions.network]
    
    # Installation margin (dB) used by the ADR engine.
    #
    # A higher number means that the network-server will keep more margin,
    # resulting in a lower data-rate but decreasing the chance that the
    # device gets disconnected because it is unable to reach one of the
    # surrounded gateways.
    installation_margin=10

    # RX window (Class-A).
    #
    # Set this to:
    # 0: RX1 / RX2
    # 1: RX1 only
    # 2: RX2 only
    rx_window=0

    # RX1 delay (1 - 15 seconds).
    rx1_delay=1

    # RX1 data-rate offset
    rx1_dr_offset=0

    # RX2 data-rate
    rx2_dr=0

    # RX2 frequency (Hz)
    rx2_frequency=505300000

    # Prefer RX2 on RX1 data-rate less than.
    #
    # Prefer RX2 over RX1 based on the RX1 data-rate. When the RX1 data-rate
    # is smaller than the configured value, then the Network Server will
    # first try to schedule the downlink for RX2, failing that (e.g. the gateway
    # has already a payload scheduled at the RX2 timing) it will try RX1.
    rx2_prefer_on_rx1_dr_lt=0

    # Prefer RX2 on link budget.
    #
    # When the link-budget is better for RX2 than for RX1, the Network Server will first
    # try to schedule the downlink in RX2, failing that it will try RX1.
    rx2_prefer_on_link_budget=false

    # Downlink TX Power (dBm)
    #
    # When set to -1, the downlink TX Power from the configured band will
    # be used.
    #
    # Please consult the LoRaWAN Regional Parameters and local regulations
    # for valid and legal options. Note that the configured TX Power must be
    # supported by your gateway(s).
    downlink_tx_power=-1

    # ADR is disabled.
    adr_disabled=false

    # Minimum data-rate.
    min_dr=0

    # Maximum data-rate.
    max_dr=5

    # Enabled uplink channels.
    #
    # Use this when ony a sub-set of the by default enabled channels are being
    # used. For example when only using the first 8 channels of the US band.
    # Note: when left blank / empty array, all channels will be enabled.
    enabled_uplink_channels=[0, 1, 2, 3, 4, 5, 6, 7]


    # Rejoin-request configuration (LoRaWAN 1.1)
    [regions.network.rejoin_request]

      # Request devices to periodically send rejoin-requests.
      enabled=false

      # The device must send a rejoin-request type 0 at least every 2^(max_count_n + 4)
      # uplink messages. Valid values are 0 to 15.
      max_count_n=0

      # The device must send a rejoin-request type 0 at least every 2^(max_time_n + 10)
      # seconds. Valid values are 0 to 15.
      #
      # 0  = roughly 17 minutes
      # 15 = about 1 year
      max_time_n=0
    

    # Class-B configuration.
    [regions.network.class_b]

      # Ping-slot data-rate. 
      ping_slot_dr=0

      # Ping-slot frequency (Hz)
      #
      # set this to 0 to use the default frequency plan for the configured region
      # (which could be frequency hopping).
      ping_slot_frequency=0
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223
  • 224
  • 225
  • 226
  • 227
  • 228
  • 229
  • 230
  • 231
  • 232
  • 233
  • 234
  • 235
  • 236
  • 237

地区参数配置说明

region_cn470_0.toml文件中的配置主要有以下几项:

  • regions.gateway: 网关参数配置
    • regions.gateway.backend: 网关接入后台的配置(后续会对网关后台接入再详细说明)。
    • regions.gateway.channels: 网关用到的无线电频率详细配置(具体参数参考 LoRaWAN 的地区规范)。
  • regions.network: 地区网络配置
    • regions.network.rejoin_request: LoRaWAN 入网请求。
      y.channels: 网关用到的无线电频率详细配置(具体参数参考 LoRaWAN 的地区规范)。
  • regions.network: 地区网络配置
    • regions.network.rejoin_request: LoRaWAN 入网请求。
    • regions.network.class_b: LoRaWAN B 类终端参数配置。
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/171183
推荐阅读
相关标签
  

闽ICP备14008679号