阡陌 发表于 2023-12-26 00:18:29

将 chirpstack-gateway-bridge 部署到网关



## 下载

根据网关选择,这里下载 ARMv7 指令集的二进制程序

https://artifacts.chirpstack.io/downloads/chirpstack-gateway-bridge/chirpstack-gateway-bridge_3.14.3_linux_armv7.tar.gz



## 配置

从 Ubuntu 服务器中找到 apt 安装时自动创建的配置文件。

<!--more-->

### 基本配置

```
# Gateway backend configuration.

# Backend type.
type="semtech_udp"

# Semtech UDP packet-forwarder backend.


# ip:port to bind the UDP listener to
#
# Example: 0.0.0.0:1700 to listen on port 1700 for all network interfaces.
# This is the listener to which the packet-forwarder forwards its data
# so make sure the 'serv_port_up' and 'serv_port_down' from your
# packet-forwarder matches this port.
udp_bind = "0.0.0.0:1700"


# Integration configuration.

# Payload marshaler.
#
# This defines how the MQTT payloads are encoded. Valid options are:
# * protobuf:Protobuf encoding
# * json:      JSON encoding (easier for debugging, but less compact than 'protobuf')
marshaler="protobuf"

# MQTT integration configuration.

# Event topic template.
event_topic_template="gateway/{{ .GatewayID }}/event/{{ .EventType }}"

# Command topic template.
command_topic_template="gateway/{{ .GatewayID }}/command/#"

# MQTT authentication.

# Type defines the MQTT authentication type to use.
#
# Set this to the name of one of the sections below.
type="generic"

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

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

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


### 日志配置

```

# debug=5, info=4, warning=3, error=2, fatal=1, panic=0
log_level=4

# Log to syslog.
#
# When set to true, log messages are being written to syslog.
log_to_syslog=true
```

查看日志方法:

```
logread -f -e chirpstack
```



## 安装

### 安装脚本

```sh
#!/bin/sh

if [ -f /etc/init.d/lora-bridge ]
then
/etc/init.d/lora-bridge stop
/etc/init.d/lora-bridge disable
fi

cp chirpstack-gateway-bridge /usr/sbin/
chmod +rx /usr/sbin/chirpstack-gateway-bridge
cp lora-bridge /etc/init.d/
chmod +rx /etc/init.d/lora-bridge
mkdir -p /etc/chirpstack-gateway-bridge
cp chirpstack-gateway-bridge.toml /etc/chirpstack-gateway-bridge/
chmod +r /etc/chirpstack-gateway-bridge/chirpstack-gateway-bridge.toml

/etc/init.d/lora-bridge enable
/etc/init.d/lora-bridge start
```


### 服务脚本

**注意,以下代码无效(仅做记录):**

```sh
#!/bin/sh /etc/rc.common

START=98
STOP=1

start()
{
    echo service chirpstack-gateway-bridge start
    /usr/sbin/chirpstack-gateway-bridge &
}

stop()
{
    echo service chirpstack-gateway-bridge stop
    bridge_pid=$( ps -w | grep chirpstack-gateway-bridge | grep -v grep | awk '{print $1}' 2>/dev/null )
    if [ -n "$bridge_pid" ];then
      kill $bridge_pid > /dev/null 2>&1
    fi
}

```

使用前边的 start()、stop() 的形式创建的服务只能手动启动运行,不能启动时自动运行,查了很久没弄明白。而网关中的其他一些服务比如 lora 就可以正常自启动,不知是否与目标程序有关。

以下代码可用:

```
#!/bin/sh /etc/rc.common

START=98
STOP=1
USE_PROCD=1
PROG=/usr/sbin/chirpstack-gateway-bridge

start_service () {
    echo service chirpstack-gateway-bridge start
    procd_open_instance
    procd_set_param command "$PROG"
    procd_close_instance
}

stop_service() {
    echo service chirpstack-gateway-bridge stop
}
```



## 配置网关

通常在网关的 WebUI 上将 lora 的 server address 改为 localhost 即可。


页: [1]
查看完整版本: 将 chirpstack-gateway-bridge 部署到网关