Technology Sharing

Deploy chirpstack using Docker in Linux

2024-07-12

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

Table of contents

I. Introduction

2. Chirpstack

1. What is chirpstack?

2. Chirpstack Component

3. Why choose Docker deployment?

3. Deployment process under Linux

4. Web interface deployment process


I. Introduction

In this article, I use LinuxDockerDeploy chirpstack, chirpstack usesv4 version, v4 version and v3 Compared with Docker, gRPC API has made some changes, and compatibility needs to be considered. However, we only use Docker to deploy chirpstack. In fact, there are some changes in the directory and web interface. The configuration logic is the same, and there is not much change. If you are using the v3 version, you can ask me directly if you don’t understand anything.

2. Chirpstack

1. What is chirpstack?

ChirpStack is an open source LoRaWAN network server that can be used to set up private or public LoRaWAN networks. ChirpStack provides a web interface Used to manage gateways, devices, and applications.ChirpStack provides a gRPC-based API that can be used to integrate or extend ChirpStack.

2. Chirpstack Component

(1)ChirpStack Network Server: NS for short, its function isEnsure the normal operation of the LoRaWAN network and manage device communications.ThatResponsible for the core logic of the LoRaWAN network. It handles the device joining process, downlink scheduling, device activity status tracking, etc. It is also responsible for processing the uplink data received from the LoRa gateway and sending the downlink data to the gateway.

(2)ChirpStack Application Server: referred to as AS, its function isManage and process application layer data, and provide user interface and API interface.ThatResponsible for processing and managing LoRaWAN application layer data. It allows users to define applications, device configurations, and data decoders. It also provides APIs and web interfaces for managing devices, monitoring network traffic, handling data decoding, and sending application layer data to external applications.

(3)ChirpStack Gateway Bridge:itActs as middleware between the gateway and the web serverThis component can convert the LoRa packet forwarder protocol transmitted from the LoRa gateway into the common data format (JSON and Protobuf) of the ChirpStack network server.

(4)PostgreSQL: This is an open source relational database management system forPersistent Storage ChirpStack configuration data, device information, gateway information, application data, etc.

(5)Redis: This is an open source in-memory data structure storage system, usuallyUsed as a database, cache, and message brokerChirpStack uses Redis to cache and process some real-time data to improve system performance and response speed.

(6)Mosquitto:Mosquitto is a MQTT protocol proxy server forHandles communication between devices and ChirpStack components.It allows messaging between LoRaWAN gateways and ChirpStack services.

Note the difference between Postgre SQL and Redis. Postgre SQL stores data on disk and supports persistent storage. Even if the system is restarted, the data will not be lost. The performance is relatively slow. Redis stores data on memory and supports efficient read and write operations, with extremely high performance.

3. Why choose Docker deployment?

(1) Simplify the deployment process:As mentioned above, ChirpStack is composed of multiple service components. Docker Compose allows us to use a configuration file (docker-compose.yml) Define and run multiple containers with just one command (docker-compose up) to start all services.

(2) Environmental isolation:Each chirpstack service can run in an independent container, avoiding dependency conflicts and environmental pollution.

(3) Portability:Using Docker, we can ensure that the same code and configuration are running in development, test, and production environments. This helps avoid "environment problems" that arise in different environments.

(4) Centralized configuration:All service configurations are centralized in one docker-compose.yml file for easy management and version control. We can easily modify and update the configuration.

3. Deployment process under Linux

1. Pull the source code from github

v4 version: (The following will explain the v4 version)

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

v3 version:

git clone https://github.com/chirpstack/chirpstack-docker/tree/v3

2. Modificationdocker-compose.yml Configuration Files

The file is aA multi-container application configured using Docker Compose for deploying the ChirpStack IoT platform.Covers all the major components required by the ChirpStack system, ensuring they work together in a Docker container. (Note that this configuration file usually only needs to modify the frequency band and port you want, and nothing else needs to be changed)

(1)chirpstack

This is the ChirpStack application server (usually no modification is required).

  1. chirpstack:
  2. image: chirpstack/chirpstack:4
  3. command: -c /etc/chirpstack
  4. restart: unless-stopped
  5. volumes:
  6. - ./configuration/chirpstack:/etc/chirpstack
  7. - ./lorawan-devices:/opt/lorawan-devices
  8. depends_on:
  9. - postgres
  10. - mosquitto
  11. - redis
  12. environment:
  13. - MQTT_BROKER_HOST=mosquitto
  14. - REDIS_HOST=redis
  15. - POSTGRESQL_HOST=postgres
  16. ports:
  17. - 8080:8080
  • image: Use chirpstack/chirpstack:4 Mirror image.
  • command: Specify the configuration file path as /etc/chirpstack
  • restart: Set to unless-stopped, that is, the container will automatically restart unless it is stopped manually.
  • volumes: mount local directories ./configuration/chirpstack to the container/etc/chirpstack,as well as ./lorawan-devices to the container/opt/lorawan-devices
  • depends_on: Dependency postgres, mosquitto, redis Three services.
  • environment: Set environment variables, including MQTT_BROKER_HOST, REDIS_HOST, POSTGRESQL_HOST
  • ports: exposed ports 8080, the container 8080 Port mapping to the host8080 port.

(2)chirpstack-gateway-bridge

This is the ChirpStack gateway bridge service (I use the cn470_10 band here).

  1. chirpstack-gateway-bridge:
  2. image: chirpstack/chirpstack-gateway-bridge:4
  3. restart: unless-stopped
  4. ports:
  5. - 1700:1700/udp
  6. volumes:
  7. - ./configuration/chirpstack-gateway-bridge:/etc/chirpstack-gateway-bridge
  8. environment:
  9. - INTEGRATION__MQTT__EVENT_TOPIC_TEMPLATE=cn470_10/gateway/{{ .GatewayID }}/event/{{ .EventType }}
  10. - INTEGRATION__MQTT__STATE_TOPIC_TEMPLATE=cn470_10/gateway/{{ .GatewayID }}/state/{{ .StateType }}
  11. - INTEGRATION__MQTT__COMMAND_TOPIC_TEMPLATE=cn470_10/gateway/{{ .GatewayID }}/command/#
  12. depends_on:
  13. - mosquitto
  • estart: Set to unless-stopped
  • ports: exposed UDP ports 1700
  • volumes: mount local directories ./configuration/chirpstack-gateway-bridge to the container/etc/chirpstack-gateway-bridge
  • environment: Set environment variables and specify the MQTT topic template.
  • depends_on: Dependency mosquitto Serve.

(3)chirpstack-gateway-bridge-basicstation

This is the basic station service of the ChirpStack gateway bridge (note the modification of the command part).

  1. chirpstack-gateway-bridge-basicstation:
  2. image: chirpstack/chirpstack-gateway-bridge:4
  3. restart: unless-stopped
  4. command: -c /etc/chirpstack-gateway-bridge/chirpstack-gateway-bridge-basicstation-cn470_10.toml
  5. ports:
  6. - 3001:3001
  7. volumes:
  8. - ./configuration/chirpstack-gateway-bridge:/etc/chirpstack-gateway-bridge
  9. depends_on:
  10. - mosquitto
  • image: Use chirpstack/chirpstack-gateway-bridge:4 Mirror image.
  • restart: Set to unless-stopped
  • command: Use configuration file chirpstack-gateway-bridge-basicstation-cn470_10.toml
  • ports: exposed ports 3001
  • volumes: mount local directories ./configuration/chirpstack-gateway-bridge to the container/etc/chirpstack-gateway-bridge
  • depends_on: Dependency mosquitto Serve.

(4)chirpstack-rest-api

This is ChirpStack's REST API service.

  1. chirpstack-rest-api:
  2. image: chirpstack/chirpstack-rest-api:4
  3. restart: unless-stopped
  4. command: --server chirpstack:8080 --bind 0.0.0.0:8090 --insecure
  5. ports:
  6. - 8090:8090
  7. depends_on:
  8. - chirpstack
  • image: Use chirpstack/chirpstack-rest-api:4 Mirror image.
  • restart: Set to unless-stopped
  • command: Specify ChirpStack server as chirpstack:8080, the binding address is 0.0.0.0:8090, and enable unsafe mode.
  • ports: exposed ports 8090
  • depends_on: Dependency chirpstack Serve.

(5)postgres

This is the PostgreSQL database service.

  1. postgres:
  2. image: postgres:14-alpine
  3. restart: unless-stopped
  4. volumes:
  5. - ./configuration/postgresql/initdb:/docker-entrypoint-initdb.d
  6. - postgresqldata:/var/lib/postgresql/data
  7. environment:
  8. - POSTGRES_PASSWORD=root
  • image: Use postgres:14-alpine Mirror image.
  • restart: Set to unless-stopped
  • volumes: mount local directories ./configuration/postgresql/initdb to the container/docker-entrypoint-initdb.d, and mount Docker volumes postgresqldata to the container/var/lib/postgresql/data
  • environment: Set environment variables POSTGRES_PASSWORD forroot

(6)redis

This is the Redis in-memory database service.

  1. redis:
  2. image: redis:7-alpine
  3. restart: unless-stopped
  4. command: redis-server --save 300 1 --save 60 100 --appendonly no
  5. volumes:
  6. - redisdata:/data
  • image: Use redis:7-alpine Mirror image.
  • restart: Set to unless-stopped
  • command: Run redis-server, and specify a save strategy.
  • volumes: Mount Docker volumes redisdata to the container/data

(7)mosquitto

This is the MQTT message broker service.

  1. mosquitto:
  2. image: eclipse-mosquitto:2
  3. restart: unless-stopped
  4. ports:
  5. - 1883:1883
  6. volumes:
  7. - ./configuration/mosquitto/config/:/mosquitto/config/

(8)Volumes

Define the data volume.

  1. volumes:
  2. postgresqldata:
  3. redisdata:
  • postgresqldata: used to store PostgreSQL data.
  • redisdata: used to store Redis data.

3. DocE-compose starts

sudo docker-compose up -d

4. Web interface deployment process

1. Access chirpstack (IP): 8080, the default account and password is admin

2. Create a gateway

Next, give the gateway a name as usual, but remember the gateway ID, and modify the corresponding ID in the gateway configuration.

3. Add device files

Fill in according to your requirements.

4. Configure AS

After adding the Play app, add devices and multicast settings in the app one by one.

 

Finally, run the gateway to see if it can connect to the cloud server and forward messages successfully.