add Dad's freq band notes and outlines for packet forwarder and chirpstack

This commit is contained in:
Jon Roeber 2023-10-07 10:21:14 -04:00
parent ee469b945e
commit 8e5867dc61
5 changed files with 429 additions and 0 deletions

View File

@ -0,0 +1,8 @@
# Raspberry Pi Setup
Download the [Raspberry Pi Imager](https://flathub.org/apps/org.raspberrypi.rpi-imager) from Flathub (or elsewhere)
Download Raspberry Pi OS Lite 64-bit from the [Raspberry Pi download page](https://www.raspberrypi.com/software/operating-systems/)
Settings in the imager

39
doc/2-packet-forwarder.md Normal file
View File

@ -0,0 +1,39 @@
# Packet Forwarder
Download `lora_pkt_fwd` from <https://github.com/Lora-net/sx1302_hal>
Run `make`
Setup config
Make pf user + give permissions
Copy files to pf user's home:
- `global_conf.json.sx1250.US915`
- `lora_pkt_fwd`
- `reset_lgw.sh`
(Make sure execute permission is set on `lora_pkt_fwd` and `reset_lgw.sh`.)
Create SystemD unit file at `/etc/systemd/system/packet-forwarder.service`:
```systemd
[Unit]
Description=SX1302 Packet Forwarder
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
User=pf
WorkingDirectory=/home/pf
ExecStart=/home/pf/lora_pkt_fwd -c global_conf.json.sx1250.US915
[Install]
WantedBy=multi-user.target
```
Start and enable `sudo systemctl enable --now packet-forwarder.service`.

179
doc/3-chirpstack.md Normal file
View File

@ -0,0 +1,179 @@
# ChirpStack Setup
Follow install instructions: <https://www.chirpstack.io/docs/getting-started/debian-ubuntu.html>
Set configurations
For `/etc/chirpstack-gateway-bridge/chirpstack-gateway-bridge.toml`:
```toml
root@chirpstack:/etc/chirpstack-gateway-bridge# cat chirpstack-gateway-bridge.toml
# This configuration provides a Semtech UDP packet-forwarder backend and
# integrates with a MQTT broker. Many options and defaults have been omitted
# for simplicity.
#
# See https://www.chirpstack.io/gateway-bridge/install/config/ for a full
# configuration example and documentation.
# Gateway backend configuration.
[backend]
# Backend type.
type="semtech_udp"
# Semtech UDP packet-forwarder backend.
[backend.semtech_udp]
# 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.
[integration]
# 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.
[integration.mqtt]
# Event topic template.
event_topic_template="us915_0/gateway/{{ .GatewayID }}/event/{{ .EventType }}"
# Command topic template.
command_topic_template="us915_0/gateway/{{ .GatewayID }}/command/#"
# MQTT authentication.
[integration.mqtt.auth]
# Type defines the MQTT authentication type to use.
#
# Set this to the name of one of the sections below.
type="generic"
# 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=""
# Connect with the given password (optional)
password=""
```
For `/etc/chirpstack/chirpstack.toml`:
```toml
root@chirpstack:/etc/chirpstack# cat 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@localhost/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://localhost/",
]
# 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="theChirpthing!."
[integration]
enabled=["mqtt"]
[integration.mqtt]
server="tcp://localhost:1883/"
json=true
```

203
doc/global_conf.md Normal file
View File

@ -0,0 +1,203 @@
# References
- LoRaWAN US915 frequencies:
https://www.baranidesign.com/faq-articles/2019/4/23/lorawan-usa-frequencies-channels-and-sub-bands-for-iot-devices
- Also see FCC Part 15.247
https://www.govinfo.gov/content/pkg/CFR-2013-title47-vol1/pdf/CFR-2013-title47-vol1-sec15-247.pdf
# Naming Convention
This document uses 0-indexing to identify the US915 subbands. There are eight subbands and they are named in this document as subband_0, subband_1, ..., subband_7.
Chirpstack uses zero indexing in the configuration file name for each subband. For example, the configuration file for subband_0 is /etc/chirpstack/region_us915_0.toml.
Other sources use 1-indexing to identify subbands. The baranidesign reference, above, as well as Helium and The Things Network identify the US bands as subband_1, subband_2, ..., subband_8.
# Set the Subband
Restart the computer after making changes to Chirpstack and the packet forwarder. If changes are made to the packet forwarder, the computer may need to be powered off in order to reset the packet forwarder.
## Packet Forwarder
The RAK Wireless packet forwarder files are in /opt/ttn-gateway/packet_forwarder/lora_pkt_fwd. By default, the frequency subband is set in global_conf.json. An example global configuration file follows.
``` json
{
"SX130x_conf": {
"com_type": "SPI",
"com_path": "/dev/spidev0.0",
"lorawan_public": true,
"clksrc": 0,
"antenna_gain": 0, /* antenna gain, in dBi */
"full_duplex": false,
"fine_timestamp": {
"enable": false,
"mode": "all_sf" /* high_capacity or all_sf */
},
"radio_0": {
"enable": true,
"type": "SX1250",
"freq": 909100000,
"rssi_offset": -215.4,
"rssi_tcomp": {"coeff_a": 0, "coeff_b": 0, "coeff_c": 20.41, "coeff_d": 2162.56, "coeff_e": 0},
"tx_enable": true,
"tx_freq_min": 923000000,
"tx_freq_max": 928000000,
"tx_gain_lut":[
{"rf_power": 12, "pa_gain": 1, "pwr_idx": 6},
{"rf_power": 13, "pa_gain": 1, "pwr_idx": 7},
{"rf_power": 14, "pa_gain": 1, "pwr_idx": 8},
{"rf_power": 15, "pa_gain": 1, "pwr_idx": 9},
{"rf_power": 16, "pa_gain": 1, "pwr_idx": 10},
{"rf_power": 17, "pa_gain": 1, "pwr_idx": 11},
{"rf_power": 18, "pa_gain": 1, "pwr_idx": 12},
{"rf_power": 19, "pa_gain": 1, "pwr_idx": 13},
{"rf_power": 20, "pa_gain": 1, "pwr_idx": 14},
{"rf_power": 21, "pa_gain": 1, "pwr_idx": 15},
{"rf_power": 22, "pa_gain": 1, "pwr_idx": 16},
{"rf_power": 23, "pa_gain": 1, "pwr_idx": 17},
{"rf_power": 24, "pa_gain": 1, "pwr_idx": 18},
{"rf_power": 25, "pa_gain": 1, "pwr_idx": 19},
{"rf_power": 26, "pa_gain": 1, "pwr_idx": 21},
{"rf_power": 27, "pa_gain": 1, "pwr_idx": 22}
]
},
"radio_1": {
"enable": true,
"type": "SX1250",
"freq": 909800000,
"rssi_offset": -215.4,
"rssi_tcomp": {"coeff_a": 0, "coeff_b": 0, "coeff_c": 20.41, "coeff_d": 2162.56, "coeff_e": 0},
"tx_enable": false
},
"chan_multiSF_All": {"spreading_factor_enable": [ 5, 6, 7, 8, 9, 10, 11, 12 ]},
"chan_multiSF_0": {"enable": true, "radio": 0, "if": -400000}, /* Freq : 908.7 MHz*/
"chan_multiSF_1": {"enable": true, "radio": 0, "if": -200000}, /* Freq : 908.9 MHz*/
"chan_multiSF_2": {"enable": true, "radio": 0, "if": 0}, /* Freq : 909.1 MHz*/
"chan_multiSF_3": {"enable": true, "radio": 0, "if": 200000}, /* Freq : 909.3 MHz*/
"chan_multiSF_4": {"enable": true, "radio": 1, "if": -300000}, /* Freq : 909.5 MHz*/
"chan_multiSF_5": {"enable": true, "radio": 1, "if": -100000}, /* Freq : 909.7 MHz*/
"chan_multiSF_6": {"enable": true, "radio": 1, "if": 100000}, /* Freq : 909.9 MHz*/
"chan_multiSF_7": {"enable": true, "radio": 1, "if": 300000}, /* Freq : 910.1 MHz*/
"chan_Lora_std": {"enable": true, "radio": 0, "if": 300000, "bandwidth": 500000, "spread_factor": 8, /* Freq : 909.4 MHz*/
"implicit_hdr": false, "implicit_payload_length": 17, "implicit_crc_en": false, "implicit_coderate": 1},
"chan_FSK": {"enable": false, "radio": 1, "if": 300000, "bandwidth": 125000, "datarate": 50000} /* Freq : 910.1 MHz*/
},
"gateway_conf": {
"gateway_ID": "AA555A0000000000",
/* change with default server address/ports */
"server_address": "localhost",
"serv_port_up": 1700,
"serv_port_down": 1700,
/* adjust the following parameters for your network */
"keepalive_interval": 10,
"stat_interval": 30,
"push_timeout_ms": 100,
/* forward only valid packets */
"forward_crc_valid": true,
"forward_crc_error": false,
"forward_crc_disabled": false,
/* GPS configuration */
"gps_tty_path": "/dev/ttyAMA0",
/* GPS reference coordinates */
"ref_latitude": 0.0,
"ref_longitude": 0.0,
"ref_altitude": 0,
/* Beaconing parameters */
"beacon_period": 0, /* disable class B beacon, set to 128 enable beacon */
"beacon_freq_hz": 923300000,
"beacon_freq_nb": 8,
"beacon_freq_step": 600000,
"beacon_datarate": 12,
"beacon_bw_hz": 500000,
"beacon_power": 27
},
"debug_conf": {
"ref_payload":[
{"id": "0xCAFE1234"},
{"id": "0xCAFE2345"}
],
"log_file": "loragw_hal.log"
}
}
```
Note that the settings for 125 kHz channels, chan_multiSF_0 - chan_multiSF_7, show frequency offsets from the radio_0 and radio_1 freq values. Specifically, chan_multiSF_0 through chan_multiSF_3 use offsets from the radio_0 freq and chan_multiSF_4 through multiSF_7 use offsets from the radio_1 freq. The 500 kHz channel, chan_Lora_std, uses an offset from the radio_0 freq. One method for setting the subband is to keep the offsets as shown and change the radio_0 and radio_1 freq values to match the desired subband.
### Example 1. Set the frequencies for US915 subband_1.
The eight required frequencies are 903.1, 903.3, 903.5, ..., 905.3 kHz. This is the subband used by Helium and The Things Network.
- Set the radio_0 freq to 904300000. The frequency for chan_multiSF_0 is:
$$904300000 - 400000 = 903900000 \ \ (903.9 kHz)$$
Likewise, the frequency for chan_multiSF_3 is
$$904300000 + 200000 = 904500000 \ \ (904.5 kHz)$$
The 500 kHz bandwidth frequency is
$$904300000 + 300000 = 904600000 \ \ (904.6 kHz)$$
- Set the radio_1 freq to 905000000. The frequency for chan_multiSF_4 is
$$905000000 - 300000 = 904700000 \ \ (904.7 kHz)$$
The frequency for chan_multiSF_6 is
$$905000000 + 1000000 = 905100000 \ \ (905.1 kHz)$$
### Example 2. Set the frequencies for US915 subband_4.
The eight required frequencies for subband_4 are 908.7, 908.9, 909.1, ..., 910.1 kHz.
- Set the radio_0 freq to 909100000. The frequency for chan_multiSF_1 is
$$909100000 - 200000 = 908900000 \ \ (908.8 kHz)$$
The frequency for chan_multiSF_2 is
$$909100000 + 0 = 909100000 \ \ (909.1 kHz)$$
The 500 kHz bandwidth frequency is
$$909100000 + 300000 = 909400000 \ \ (909.4 kHz)$$
- Set the radio_1 freq to 909800000. The frequency for chan_multiSF_5 is
$$909800000 - 100000 = 909700000 \ \ (909.7 kHz)$$
and the frequency for chan_multiSF_7 is
$$909800000 + 300000 = 910100000 \ \ (910.1 kHz)$$
## Chirpstack
### Gateway Bridge Configuration
The Chirpstack gateway bridge configuration file is /etc/chirpstack-gateway-bridge/chirpstack-gateway-bridge.toml. In the [integration.mqtt] section of this file, change the event_topic_template and the command_topic_template names to match the desired subband. For example, if subband_4 is used, the mqtt integration section should be:
```
# MQTT integration configuration.
[integration.mqtt]
# Event topic template.
event_topic_template="us915_4/gateway/{{ .GatewayID }}/event/{{ .EventType }}"
# Command topic template.
command_topic_template="us915_4/gateway/{{ .GatewayID }}/command/#"
```
### Device Profile
Use the Chirpstack web interface to configure the Device Profile region.
![Device Profile](./chirpstack_deviceprofile.png "Chirpstack Device Profile Settings")
Use the Region configuration dropdown box to select the subband_4 channels. The channels can be cross referenced to frequencies using the link shown in the references, above. After making the selection, click on "Submit" button to save the entry.