ChirpStack介绍
ChirpStack开源LoRaWAN网络服务器堆栈为LoRaWAN网络提供了开源组件。它们共同构成了一个即用型解决方案,包括用于设备管理的用户友好型Web界面和用于集成的API。模块化体系结构使得可以在现有基础架构中进行集成。所有组件均已获得MIT许可,并可以用于商业目的。
下面是chirpstack的官网。
https://www.chirpstack.io/
ChirpStack服务端组件:
- ChirpStack Gateway Bridge:网关网桥,处理与LoRaWAN网关的通信
- ChirpStack Network Server:网络服务器,LoRaWAN网络服务器的实现
- ChirpStack Application Server:应用服务器,LoRaWAN应用服务器的实现
- ChirpStack Gateway OS:基于嵌入式Linux的操作系统,用于在LoRa网关上运行(完整)ChirpStack堆栈
ChirpStack部署方式
- 使用 Docker-Compose 快速部署
https://blog.csdn.net/iotisan/article/details/90412945 - 手动部署
本文为手动部署搭建流程
部署流程
服务器环境:CentOS Linux release 7.8.2003 (Core)
ChirpStack依赖Postgresql,mosquitto,redis软件,所以需要先安装这些软件。
1、Postgresql安装
PostgreSQL是一种特性非常齐全的自由软件的对象-关系型数据库管理系统(ORDBMS),是以加州大学计算机系开发的POSTGRES,4.2版本为基础的对象关系型数据库管理系统。POSTGRES的许多领先概念只是在比较迟的时候才出现在商业网站数据库中。PostgreSQL支持大部分的SQL标准并且提供了很多其他现代特性,如复杂查询、外键、触发器、视图、事务完整性、多版本并发控制等。同样,PostgreSQL也可以用许多方法扩展,例如通过增加新的数据类型、函数、操作符、聚集函数、索引方法、过程语言等。另外,因为许可证的灵活,任何人都可以以任何目的免费使用、修改和分发PostgreSQL。
- 选择系统对应的版本
https://www.postgresql.org/download/linux/redhat/
image.png - 添加RPM
yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
- 安装PostgreSQL 9.5
yum install postgresql96-server postgresql96-contrib
- 初始化数据库
/usr/pgsql-9.6/bin/postgresql96-setup initdb
- 开机自启动
systemctl enable postgresql-9.6
- 启动数据库
systemctl start postgresql-9.6
postgresql安装后会自动创建一个postgres用户 - 创建数据库用户和数据库以供后续安装ChirpStack使用
#添加用户
sudo -u postgres psql
#-- set up the users and the passwords
#-- (note that it is important to use single quotes and a semicolon at the end!)
create role chirpstack_as with login password 'dbpassword';
create role chirpstack_ns with login password 'dbpassword';
#-- create the database for the servers
create database chirpstack_as with owner chirpstack_as;
create database chirpstack_ns with owner chirpstack_ns;
#-- change to the ChirpStack Application Server database
\c chirpstack_as
#-- enable the pq_trgm and hstore extensions
#-- (this is needed to facilitate the search feature)
create extension pg_trgm;
#-- (this is needed to store additional k/v meta-data)
create extension hstore;
#-- exit psql
\q
2、mosquitto安装
mosquitto一款实现了消息推送协议 MQTT v3.1 的开源消息代理软件,提供轻量级的,支持可发布/可订阅的的消息推送模式,使设备对设备之间的短消息通信变得简单,比如现在应用广泛的低功耗传感器,手机、嵌入式计算机、微型控制器等移动设备。
- 添加RPM:
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
- 安装mosquitto:
yum install mosquitto
- 配置mosquitto:
#创建密码文件
touch /etc/mosquitto/pwfile
#创建策略文件
touch /etc/mosquitto/aclfile
#创建日志目录
mkdir /var/log/mosquitto
#创建日志文件
touch /var/log/mosquitto/mosquitto.log
#创建本地持久化文件目录
mkdir /var/lib/mosquitto
#创建chirp用户
mosquitto_passwd /etc/mosquitto/pwfile chirp
#输入chrip用户的密码
配置参数:vi /etc/mosquitto/mosquitto.conf
#持久化配置
persistence true
persistence_location /var/lib/mosquitto/
#日志文件配置
log_dest file /var/log/mosquitto/mosquitto.log
#用户名密码认证配置
allow_anonymous false
password_file /etc/mosquitto/pwfile
acl_file /etc/mosquitto/aclfile
配置用户策略:vi /etc/mosquitto/aclfile
user chirp //用户chirp
topic chirpstack/# //可对主题chirpstack读写
测试: mosquitto_sub -t chirpstack/# -u chirp -P 123456
日志查看:tail -f /var/log/mosquitto/mosquitto.log
-添加ChirpStack mqtt用户,设置密码。
mosquitto_passwd /etc/mosquitto/pwfile chirp_gateway
输入密码:
mosquitto_passwd /etc/mosquitto/pwfile chirp_network
输入密码:
mosquitto_passwd /etc/mosquitto/pwfile chrip_application
输入密码:
配置用户策略
[root@VM-0-15-centos ~]# cat /etc/mosquitto/aclfile
user chrip
topic chirpstack/#
user chirp_gateway
topic gateway/#
user chirp_network
topic gateway/#
user chrip_application
topic gateway/#
启动重启命令:
1、查看mosquitto的进程
ps -aux | grep mosquitto
2、杀掉进程
kill -9 18248
3.启动mosquitto
mosquitto -c /etc/mosquitto/mosquitto.conf -d
-参考
https://blog.csdn.net/qq_34301871/article/details/93617204
3、redis安装
redis内网不能访问的问题:
1、检查端口是否通
2、取消redis bind 127.0.0.1
3、关闭保护模式 protected-mode no
4、chirpstack-gateway-bridge安装
yum install https://artifacts.chirpstack.io/downloads/chirpstack-gateway-bridge/chirpstack-gateway-bridge_3.10.0_linux_amd64.rpm
安装成功后出现以下提示:
---------------------------------------------------------------------------------
The configuration file is located at:
/etc/chirpstack-gateway-bridge/chirpstack-gateway-bridge.toml
Some helpful commands for chirpstack-gateway-bridge:
Start:
$ sudo systemctl start chirpstack-gateway-bridge
Restart:
$ sudo systemctl restart chirpstack-gateway-bridge
Stop:
$ sudo systemctl stop chirpstack-gateway-bridge
Display logs:
$ sudo journalctl -f -n 100 -u chirpstack-gateway-bridge
---------------------------------------------------------------------------------
gateway-bridge配置:
marshaler="json"
# Generic MQTT authentication.
[integration.mqtt.auth.generic]
# MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws)
server="tcp://127.0.0.1:1883"
# Connect with the given username (optional)
username="chirp_gateway"
# Connect with the given password (optional)
password="123456"
配置后启动服务
5、chirpstack-network-server安装
yum install https://artifacts.chirpstack.io/downloads/chirpstack-network-server/chirpstack-network-server_3.10.0_linux_amd64.rpm
安装成功后出现以下提示:
---------------------------------------------------------------------------------
The configuration file is located at:
/etc/chirpstack-network-server/chirpstack-network-server.toml
Some helpful commands for chirpstack-network-server:
Start:
$ sudo systemctl start chirpstack-network-server
Restart:
$ sudo systemctl restart chirpstack-network-server
Stop:
$ sudo systemctl stop chirpstack-network-server
Display logs:
$ sudo journalctl -f -n 100 -u chirpstack-network-server
---------------------------------------------------------------------------------
network-server配置:
# This configuration configures ChirpStack Network Server for the EU868 band using a MQTT
# broker to communicate with the gateways. Many options and defaults have been
# omitted for simplicity.
#
# For other bands, see the ./examples/ sub-directory.
#
# See https://www.chirpstack.io/network-server/install/config/ for a full
# configuration example and documentation.
# PostgreSQL settings.
#
# Please note that PostgreSQL 9.5+ is required.
[postgresql]
# PostgreSQL dsn (e.g.: postgres://user:password@hostname/database?sslmode=disable).
# Besides using an URL (e.g. 'postgres://user:password@hostname/database?sslmode=disable')
# it is also possible to use the following format:
# 'user=chirpstack_ns dbname=chirpstack_ns sslmode=disable'.
#
# The following connection parameters are supported:
#
# * dbname - The name of the database to connect to
# * user - The user to sign in as
# * password - The user's password
# * host - The host to connect to. Values that start with / are for unix domain sockets. (default is localhost)
# * port - The port to bind to. (default is 5432)
# * sslmode - Whether or not to use SSL (default is require, this is not the default for libpq)
# * fallback_application_name - An application_name to fall back to if one isn't provided.
# * connect_timeout - Maximum wait for connection, in seconds. Zero or not specified means wait indefinitely.
# * sslcert - Cert file location. The file must contain PEM encoded data.
# * sslkey - Key file location. The file must contain PEM encoded data.
# * sslrootcert - The location of the root certificate file. The file must contain PEM encoded data.
#
# Valid values for sslmode are:
#
# * 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_ns:dbpassword@localhost/chirpstack_ns?sslmode=disable"
dsn="postgres://chirpstack_ns:dbpassword@localhost/chirpstack_ns?sslmode=disable"
# Redis settings
#
# Please note that Redis 2.6.0+ is required.
[redis]
# Redis url (e.g. redis://user:password@hostname/0)
#
# For more information about the Redis URL format, see:
# https://www.iana.org/assignments/uri-schemes/prov/redis
url="redis://localhost:6379"
# Network-server settings.
[network_server]
# Network identifier (NetID, 3 bytes) encoded as HEX (e.g. 010203)
net_id="000000"
# LoRaWAN regional band configuration.
#
# Note that you might want to consult the LoRaWAN Regional Parameters
# specification for valid values that apply to your region.
# See: https://www.lora-alliance.org/lorawan-for-developers
[network_server.band]
name="CN470"
# LoRaWAN network related settings.
[network_server.network_settings]
# Extra channel configuration.
#
# Use this for LoRaWAN regions where it is possible to extend the by default
# available channels with additional channels (e.g. the EU band).
# The first 5 channels will be configured as part of the OTAA join-response
# (using the CFList field).
# The other channels (or channel / data-rate changes) will be (re)configured
# using the NewChannelReq mac-command.
#
#[[network_server.network_settings.extra_channels]]
#frequency=867100000
#min_dr=0
#max_dr=5
#[[network_server.network_settings.extra_channels]]
#frequency=867300000
#min_dr=0
#max_dr=5
#[[network_server.network_settings.extra_channels]]
#frequency=867500000
#min_dr=0
#max_dr=5
#[[network_server.network_settings.extra_channels]]
#frequency=867700000
#min_dr=0
#max_dr=5
#[[network_server.network_settings.extra_channels]]
#frequency=867900000
#min_dr=0
#max_dr=5
# Class B settings
[network_server.network_settings.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
# Network-server API
#
# This is the network-server API that is used by ChirpStack Application Server or other
# custom components interacting with ChirpStack Network Server.
[network_server.api]
# ip:port to bind the api server
bind="0.0.0.0:8000"
# Backend defines the gateway backend settings.
#
# The gateway backend handles the communication with the gateway(s) part of
# the LoRaWAN network.
[network_server.gateway.backend]
# Backend
type="mqtt"
# MQTT gateway backend settings.
#
# This is the backend communicating with the LoRa gateways over a MQTT broker.
[network_server.gateway.backend.mqtt]
# MQTT topic templates for the different MQTT topics.
#
# The meaning of these topics are documented at:
# https://www.chirpstack.io/gateway-bridge/
#
# The default values match the default expected configuration of the
# ChirpStack Gateway Bridge MQTT backend. Therefore only change these values when
# absolutely needed.
# Event topic template.
event_topic="gateway/+/event/+"
# Command topic template.
#
# Use:
# * "{{ .GatewayID }}" as an substitution for the LoRa gateway ID
# * "{{ .CommandType }}" as an substitution for the command type
command_topic_template="gateway/{{ .GatewayID }}/command/{{ .CommandType }}"
# MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws)
server="tcp://localhost:1883"
# Connect with the given username (optional)
username="chirp_network"
# Connect with the given password (optional)
password="123456"
# Metrics collection settings.
[metrics]
# Timezone
#
# The timezone is used for correctly aggregating the metrics (e.g. per hour,
# day or month).
# Example: "Europe/Amsterdam" or "Local" for the the system's local time zone.
timezone="Local"
# Join-server settings.
[join_server]
# Default join-server settings.
#
# This join-server will be used when resolving the JoinEUI is set to false
# or as a fallback when resolving the JoinEUI fails.
[join_server.default]
# hostname:port of the default join-server
#
# This API is provided by ChirpStack Application Server.
server="http://localhost:8003"
6、chirpstack-application-server安装
https://artifacts.chirpstack.io/downloads/chirpstack-application-server/chirpstack-application-server_3.10.0_linux_amd64.rpm
安装成功后出现以下提示:
---------------------------------------------------------------------------------
The configuration file is located at:
/etc/chirpstack-application-server/chirpstack-application-server.toml
Some helpful commands for chirpstack-application-server:
Start:
$ sudo systemctl start chirpstack-application-server
Restart:
$ sudo systemctl restart chirpstack-application-server
Stop:
$ sudo systemctl stop chirpstack-application-server
Display logs:
$ sudo journalctl -f -n 100 -u chirpstack-application-server
---------------------------------------------------------------------------------
application-server配置:
# This configuration sets the required settings and configures an integration
# with a MQTT broker. Many options and defaults have been omitted for
# simplicity.
#
# See https://www.chirpstack.io/application-server/install/config/ for a full
# configuration example and documentation.
# PostgreSQL settings.
#
# Please note that PostgreSQL 9.5+ is required.
[postgresql]
# PostgreSQL dsn (e.g.: postgres://user:password@hostname/database?sslmode=disable).
#
# Besides using an URL (e.g. 'postgres://user:password@hostname/database?sslmode=disable')
# it is also possible to use the following format:
# 'user=chirpstack_as dbname=chirpstack_as sslmode=disable'.
#
# The following connection parameters are supported:
#
# * dbname - The name of the database to connect to
# * user - The user to sign in as
# * password - The user's password
# * host - The host to connect to. Values that start with / are for unix domain sockets. (default is localhost)
# * port - The port to bind to. (default is 5432)
# * sslmode - Whether or not to use SSL (default is require, this is not the default for libpq)
# * fallback_application_name - An application_name to fall back to if one isn't provided.
# * connect_timeout - Maximum wait for connection, in seconds. Zero or not specified means wait indefinitely.
# * sslcert - Cert file location. The file must contain PEM encoded data.
# * sslkey - Key file location. The file must contain PEM encoded data.
# * sslrootcert - The location of the root certificate file. The file must contain PEM encoded data.
#
# Valid values for sslmode are:
#
# * 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_as:dbpassword@localhost/chirpstack_as?sslmode=disable"
# Redis settings
#
# Please note that Redis 2.6.0+ is required.
[redis]
# Redis url (e.g. redis://user:password@hostname/0)
#
# For more information about the Redis URL format, see:
# https://www.iana.org/assignments/uri-schemes/prov/redis
url="redis://localhost:6379"
# Application-server settings.
[application_server]
# Integration configures the data integration.
#
# This is the data integration which is available for all applications,
# besides the extra integrations that can be added on a per-application
# basis.
[application_server.integration]
# Enabled integrations.
enabled=["mqtt"]
# MQTT integration backend.
[application_server.integration.mqtt]
# MQTT topic templates for the different MQTT topics.
#
# The meaning of these topics are documented at:
# https://www.chirpstack.io/application-server/integrate/data/
#
# The following substitutions can be used:
# * "{{ .ApplicationID }}" for the application id.
# * "{{ .DevEUI }}" for the DevEUI of the device.
#
# Note: the downlink_topic_template must contain both the application id and
# DevEUI substitution!
uplink_topic_template="application/{{ .ApplicationID }}/device/{{ .DevEUI }}/rx"
downlink_topic_template="application/{{ .ApplicationID }}/device/{{ .DevEUI }}/tx"
join_topic_template="application/{{ .ApplicationID }}/device/{{ .DevEUI }}/join"
ack_topic_template="application/{{ .ApplicationID }}/device/{{ .DevEUI }}/ack"
error_topic_template="application/{{ .ApplicationID }}/device/{{ .DevEUI }}/error"
status_topic_template="application/{{ .ApplicationID }}/device/{{ .DevEUI }}/status"
location_topic_template="application/{{ .ApplicationID }}/device/{{ .DevEUI }}/location"
# MQTT server (e.g. scheme://host:port where scheme is tcp, ssl or ws)
server="tcp://localhost:1883"
# Connect with the given username (optional)
username="chrip_application"
# Connect with the given password (optional)
password="123456"
# Settings for the "internal api"
#
# This is the API used by ChirpStack Network Server to communicate with ChirpStack Application Server
# and should not be exposed to the end-user.
[application_server.api]
# ip:port to bind the api server
bind="0.0.0.0:8001"
# Public ip:port of the application-server API.
#
# This is used by ChirpStack Network Server to connect to ChirpStack Application Server. When running
# ChirpStack Application Server on a different host than ChirpStack Network Server, make sure to set
# this to the host:ip on which ChirpStack Network Server can reach ChirpStack Application Server.
# The port must be equal to the port configured by the 'bind' flag
# above.
public_host="localhost:8001"
# Settings for the "external api"
#
# The API and web-interface exposed to the end-user.
[application_server.external_api]
# ip:port to bind the (user facing) http server to (web-interface and REST / gRPC api)
bind="0.0.0.0:8080"
# http server TLS certificate (optional)
tls_cert=""
# http server TLS key (optional)
tls_key=""
# JWT secret used for api authentication / authorization
# You could generate this by executing 'openssl rand -base64 32' for example
jwt_secret="vTF5M9E2Ymz7sg+rl78OeFz7UymnhWVdh36YiVvnowo="
# Join-server configuration.
#
# ChirpStack Application Server implements a (subset) of the join-api specified by the
# LoRaWAN Backend Interfaces specification. This API is used by ChirpStack Network Server
# to handle join-requests.
[join_server]
# ip:port to bind the join-server api interface to
bind="0.0.0.0:8003"
7、登陆
8、参考文档
https://www.cnblogs.com/liujiabing/p/13692308.html
https://www.it610.com/article/1295693840237273088.htm
https://blog.csdn.net/weixin_46027505/article/details/107270912