Chirpstack:一個開源的Lora服務項目,該項目包含Gateway Bridge,Network Server,Application Server,Gateway os等子項目,官網地址:https://www.chirpstack.io/
服務器環境:CentOS Linux release 7.8.2003 (Core)。
一,安裝mosquitto。mosauitto是一個開源的MQTT消息代理軟件。這個項目中,MQTT承擔了各個組件之間互相通信的重任,貫穿了從網橋到AS的整個流程。
1,添加EPEL軟件包安裝源:yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
2,安裝mosquitto:yum install mosquitto
3, 配置mosquitto
#創建密碼文件 touch /etc/mosquitto/pwfile #創建策略文件 touch /etc/mosquitto/aclfile #創建日志目錄 mkdir /var/log/mosquitto #創建日志文件 touch /var/log/mosquitto/mosquitto.log #創建本地持久化文件目錄 mkdir /var/lib/mosquitto #創建chrip用戶 mosquitto_passwd /etc/mosquitto/pwfile chrip #輸入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
二,安裝gateway-bridge
1,新建一個目錄,下載redhat安裝包到該目錄 wget https://artifacts.chirpstack.io/downloads/chirpstack-gateway-bridge/chirpstack-gateway-bridge_3.9.2_linux_386.rpm
2,安裝rpm:rpm -ivh chirpstack-gateway-bridge_3.9.2_linux_386.rpm
3,為getway-bridge創建一個mqtt用戶及密碼:mosquitto_passwd chirp_gateway,並為該用戶配置主題為“gateway/#”的讀寫策略.配置后重啟Mosquitto
4,配置MQTT認證信息: vi /etc/chirpstack-gateway-bridge/chirpstack-gateway-bridge.toml
#配置MQTT payloads采用的協議,默認為protobuf marshaler="json" #配置MQTT 用戶名
username="chirp_gateway"
password="123456"
#如果需要更改udp的監聽端口可以改寫udp_bind值,默認1700
5, 啟動網橋: sudo systemctl start chirpstack-gateway-bridge。查看日志:journalctl -f -n 100 -u chirpstack-gateway-bridge
三,安裝配置redis
1,yum install redis
2, vi /etc/redis.conf。找到requirepass,去掉注釋並設置新的密碼:requirepass redis123456
3,啟動redis:systemctl start redis
4,驗證密碼:redis-cli -h 127.0.0.1 -p 6379 -a redis123456
四,安裝配置postgresql
1,rpm源: yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm。安裝源見:https://yum.postgresql.org/repopackages/
2,安裝:yum install postgresql95-server postgresql95-contrib
3,初始化數據庫:/usr/pgsql-9.5/bin/postgresql95-setup initdb
4,修改postgres用戶密碼: passwd postgres
5,修改postgresql監聽地址:vi /var/lib/pgsql/9.5/data/postgresql.conf。修改listen_addresses值為“*”
6,修改postgresql認證方式:vi /var/lib/pgsql/9.5/data/pg_hba.conf。
# TYPE DATABASE USER ADDRESS METHOD # "local" is for Unix domain socket connections only local all all peer # IPv4 local connections: host all all 127.0.0.1/32 ident # IPv6 local connections: host all all ::1/128 md5 # Allow replication connections from localhost, by a user with the # replication privilege. local replication postgres peer host replication postgres 127.0.0.1/32 ident host replication postgres ::1/128 ident
5,啟動:systemctl enable postgresql-9.5.service systemctl start postgresql-9.5.service
五,安裝network-server
1,添加mqtt賬戶:mosquitto_passwd /etc/mosquitto/pwfile chirp_network。並配置主題:“gateway/#” 的讀寫權限。配置后重啟Mosquitto
2,添加postgresql賬戶及數據庫
1),進入postgres用戶:su postgres,輸入psql指令
2),創建角色及密碼:create role chirpstack_ns with login password 'dbpassword';
3),創建數據庫:create database chirpstack_ns with owner chirpstack_ns;
4),測試:psql -h localhost -U chirpstack_ns -W chirpstack_ns。輸入密碼。
3,下載chirpstack-network-server:wget https://artifacts.chirpstack.io/downloads/chirpstack-network-server/chirpstack-network-server_3.10.0_linux_386.rpm
4,安裝rpm:rpm -ivh chirpstack-network-server_3.10.0_linux_386.rpm
5,配置:vi /etc/chirpstack-network-server/chirpstack-network-server.toml
#postgresql連接字符串 [postgresql] dsn="postgres://chirpstack_ns:dbpassword@localhost/chirpstack_ns?sslmode=disable" #redis連接字符串 [redis] url="redis://requirepass:redis123456@localhost:6379" #中國lora頻點設置 [network_server] name="CN470" #注釋掉[[network_server.network_settings.extra_channels]]節點 # [[network_server.network_settings.extra_channels]] # frequency=867100000 # min_dr=0 # max_dr=5 #mqtt設置 [network_server.gateway.backend] username="chirp_network" password="123456"
6,啟動network-server:systemctl start chirpstack-network-server。查看日志:journalctl -u chirpstack-network-server -f -n 50
六,安裝Chirpstack-Application-server
1,新建Mosquitto用戶和策略:mosquitto_passwd /etc/mosquitto/pwfile chrip_application。並配置主題"gateway/#"的讀寫權限。配置后重啟Mosquitto
2,添加postgresql賬戶及數據庫
1),進入postgres用戶:su postgres,輸入psql指令
2),創建角色及密碼:create role chirpstack_as with login password 'dbpassword';
3),創建數據庫:create database chirpstack_as with owner chirpstack_as;
4)開啟 trigram 和 hstore
\c chirpstack_as
create extension pg_trgm;
create extension hstore;
4),測試:psql -h localhost -U chirpstack_as -W chirpstack_as。輸入密碼。
3,下載application-server:wget https://artifacts.chirpstack.io/downloads/chirpstack-application-server/chirpstack-application-server_3.12.2_linux_386.rpm
4,安裝:rpm -ivh chirpstack-application-server_3.12.2_linux_386.rpm
5,利用openssl生成一個密鑰:openssl rand -base64 32
6,配置:
#postgresql連接字符串 [postgresql] dsn="postgres:/chirpstack_as:dbpassword@localhost/chirpstack_as?sslmode=disable" #redis連接字符串
[redis]
url="redis://requirepass:redis123456@localhost:6379"
#mqtt設置
[application_server]
enabled=["mqtt"]
username="chirp_network"
password="123456"
#jwt密鑰,由openssl rand -base64 32生成
jwt_secret="w7X8LWXqee6HM3ach02as3fVB2xslTRXk/UCiTWC/8k="
7,啟動:systemctl start chirpstack-application-server。 查看日志:journalctl -f -n 100 -u chirpstack-application-server
七,開放端口
開放 UDP 1700 ,TCP 8080,1883
firewall-cmd --zone=public --add-port=1700/udp --permanent firewall-cmd --zone=public --add-port=8080/tcp --permanent firewall-cmd --zone=public --add-port=1883/tcp --permanent firewall-cmd --reload
打開applicationServer管理頁面,默認用戶和密碼為admin
八 配置application server
打開管理界面,登錄
1,添加services:
2,添加網關配置
3,配置網關,我手里有一個躬遠的Lorawan網關。配置Lora服務器
在application server添加該網關。
查看gateway-bridge日志。可以看到已經可以收到網關的udp包,並發布到Mqtt:journalctl -u chirpstack-gateway-bridge -f -n 50
application server上該網關已經是active了。
九:添加設備。我手中有安志博的lora傾斜傳感器終端,采用abp入網方式。按說明書激活后在application平台添加該設備
1,添加設備配置文件
2,添加應用域
3,在該應用域下添加設備
4,配置設備的入網參數。該入網參數可以由設備終端提供,也可以自己定好后發給廠家由廠家出廠時設置好。
ABP入網主要有三個參數:1,Device address 2,Network session key,3,Application session key
5,觸發該lora終端,applcation平台設備上線
十,從mqtt獲取設備的上行數據
利用Mosquitto_sub工具訂閱application/#主題:mosquitto_sub -t application/# -u chirp_application -P 123456 。可以新建一個Mosquitto用戶和策略,也可以直接用之前部署Application-server時的用戶
紅框中的數據即為設備所上傳的數據,需要用base64解密后轉為16進制。
十一,下發數據到設備
可以通過http接口或者mqtt發布二種方式,由於篇幅關系就不一一介紹。參考管網教程:
mqtt方式:https://www.chirpstack.io/application-server/integrations/mqtt/
http方式:https://www.chirpstack.io/application-server/api/http-examples/