LoRa port for TARPN node: Difference between revisions

From TARPN Wiki
No edit summary
No edit summary
Line 205: Line 205:
PORT
PORT
PORTNUM=11                                ; Optional but sets port number if stated
PORTNUM=11                                ; Optional but sets port number if stated
ID=p2p link to KV4P-4     ; Displayed by PORTS command
ID=LoRa link to KV4P-3     ; Displayed by PORTS command
TYPE=ASYNC                                ; Port is RS232 Com
TYPE=ASYNC                                ; Port is RS232 Com
PROTOCOL=KISS                        ; TNC is used in KISS (or JKISS) mode
PROTOCOL=KISS                        ; TNC is used in KISS (or JKISS) mode
Line 215: Line 215:
PERSIST=180                    ; PERSIST=256/(# of transmitters-1)
PERSIST=180                    ; PERSIST=256/(# of transmitters-1)
SLOTTIME=50                    ; CMSA interval timer in milliseconds
SLOTTIME=50                    ; CMSA interval timer in milliseconds
TXDELAY=1000         ; Transmit keyup delay in milliseconds
TXDELAY=50         ; Transmit keyup delay in milliseconds
TXTAIL=1                      ; TX key down, in milliseconds, at packet end
TXTAIL=1                      ; TX key down, in milliseconds, at packet end
QUALITY=1                      ; Quality factor applied to node broadcasts heard on
QUALITY=1                      ; Quality factor applied to node broadcasts heard on
Line 224: Line 224:
;                              ; of 0 sends everything.
;                              ; of 0 sends everything.
MAXFRAME=1                    ; Max outstanding frames (1 thru 7)
MAXFRAME=1                    ; Max outstanding frames (1 thru 7)
FRACK=9000             ; Level 2 timout in milliseconds
FRACK=2000             ; Level 2 timout in milliseconds
RESPTIME=40                    ; Level 2 delayed ack timer in milliseconds
RESPTIME=40                    ; Level 2 delayed ack timer in milliseconds
RETRIES=20                    ; Level 2 maximum retry value
RETRIES=20                    ; Level 2 maximum retry value
Line 232: Line 232:
DIGIFLAG=0                    ; Digipeat: 0=OFF, 1=ALL, 255=UI Only
DIGIFLAG=0                    ; Digipeat: 0=OFF, 1=ALL, 255=UI Only
DIGIPORT=0                    ; Port on which to send digi'd frames (0 = same port)
DIGIPORT=0                    ; Port on which to send digi'd frames (0 = same port)
USERS=1                       ; Maximum number of L2 sessions, 0 = no limit
USERS=0                       ; Maximum number of L2 sessions, 0 = no limit
IGNOREUNLOCKEDROUTES=1 ; ignore node broadcasts from other than locked routes
IGNOREUNLOCKEDROUTES=0 ; ignore node broadcasts from other than locked routes
IPADDR=127.0.0.1      ; Address of PC runnning the TNC. Usually this is the same machine as BPQ, so use 127.0.0.1 but can be on anoth>
IPADDR=127.0.0.1      ; Address of PC runnning the TNC. Usually this is the same machine as BPQ, so use 127.0.0.1 but can be on anoth>
TCPPORT=10001          ; Port TNC listens on. Default for UZ7HO is 8100 and Direwolf 8001
TCPPORT=10001          ; Port TNC listens on. Default for UZ7HO is 8100 and Direwolf 8001

Revision as of 23:20, 14 August 2023

KV4P has been experimenting with adding LoRa ports to his TARPN node. LoRa is very desirable for TARPN because LoRa transceivers are very inexpensive yet have good range, are very small and low-power, and reduce the overall setup cost of a new link.

Materials:

  • Raspberry Pi Zero 2 W (~$15 when in stock), WITH gpio header. You can use any Rapsberry Pi model for this, but this is what I used.
  • Adafruit LoRa Radio Bonnet with OLED - RFM95W @ 915MHz - RadioFruit ($32.50)
  • 78mm of magnet wire (33cm band 1/4 wave), soldered to the radio bonnet antenna center conductor via (right next to the connector we won't use)

This assumes you already have a TARPN node. With this experimental guide, you'll be buiding a LoRa radio that shows up on your network as a TCP-based KISS TNC, which port 11 or port 12 of your TARPN node will connect to via the network.

I'm going to assume you already have the Raspberry Pi configured with Raspberry Pi OS, and connected to your local network (the same network as your TARPN node). You'll want to assign a static IP to it (rather than DHCP), so you can ensure your TARPN node will be able to find it on the network after restarts.

Get LoRa bonnet working

You can read more about these steps on this Adafruit page.

  1. sudo apt install python3-pip
  2. sudo pip3 install --upgrade setuptools
  3. sudo pip3 install --upgrade adafruit-python-shell
  4. wget https://github.com/adafruit/Adafruit_CircuitPython_framebuf/raw/main/examples/font5x8.bin
  5. wget https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/raspi-blinka.py
  6. sudo python3 raspi-blinka.py (this will require reboot at the end)
  7. sudo pip3 install adafruit-circuitpython-ssd1306
  8. sudo pip3 install adafruit-circuitpython-framebuf
  9. sudo pip3 install adafruit-circuitpython-rfm9x
  10. create this test script rfm9x_check.py, which you should run ("python3 rfm9x_check.py") to prove your bonnet is properly connected and working:
# SPDX-FileCopyrightText: 2018 Brent Rubell for Adafruit Industries
#
# SPDX-License-Identifier: MIT

"""
Wiring Check, Pi Radio w/RFM9x

Learn Guide: https://learn.adafruit.com/lora-and-lorawan-for-raspberry-pi
Author: Brent Rubell for Adafruit Industries
"""
import time
import busio
from digitalio import DigitalInOut, Direction, Pull
import board
# Import the SSD1306 module.
import adafruit_ssd1306
# Import the RFM9x radio module.
import adafruit_rfm9x

# Button A
btnA = DigitalInOut(board.D5)
btnA.direction = Direction.INPUT
btnA.pull = Pull.UP

# Button B
btnB = DigitalInOut(board.D6)
btnB.direction = Direction.INPUT
btnB.pull = Pull.UP

# Button C
btnC = DigitalInOut(board.D12)
btnC.direction = Direction.INPUT
btnC.pull = Pull.UP

# Create the I2C interface.
i2c = busio.I2C(board.SCL, board.SDA)

# 128x32 OLED Display
reset_pin = DigitalInOut(board.D4)
display = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c, reset=reset_pin)
# Clear the display.
display.fill(0)
display.show()
width = display.width
height = display.height

# Configure RFM9x LoRa Radio
CS = DigitalInOut(board.CE1)
RESET = DigitalInOut(board.D25)
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)

while True:
    # Clear the image
    display.fill(0)

    # Attempt to set up the RFM9x Module
    try:
        rfm9x = adafruit_rfm9x.RFM9x(spi, CS, RESET, 915.0)
        display.text('RFM9x: Detected', 0, 0, 1)
    except RuntimeError as error:
        # Thrown on version mismatch
        display.text('RFM9x: ERROR', 0, 0, 1)
        print('RFM9x Error: ', error)

    # Check buttons
    if not btnA.value:
        # Button A Pressed
        display.text('Ada', width-85, height-7, 1)
        display.show()
        time.sleep(0.1)
    if not btnB.value:
        # Button B Pressed
        display.text('Fruit', width-75, height-7, 1)
        display.show()
        time.sleep(0.1)
    if not btnC.value:
        # Button C Pressed
        display.text('Radio', width-65, height-7, 1)
        display.show()
        time.sleep(0.1)

    display.show()
    time.sleep(0.1)

Turn it into a TCP KISS TNC

See the github project for more info.

  1. sudo apt install git aprx python3-rpi.gpio python3-spidev python3-pil python3-smbus
  2. git clone https://github.com/IZ7BOJ/RPi-LoRa-KISS-TNC-2ndgen.git
  3. cd RPi-LoRa-KISS-TNC-2ndgen
  4. git clone https://github.com/mayeranalytics/pySX127x.git
  5. sudo mv board_config.py pySX127x/SX127x/board_config.py
  6. sudo mv LoRa.py pySX127x/SX127x//LoRa.py
  7. Replace config.py with these contents. You can/should customize the frequency to anything in the 33cm band (but at least 500kHz from the band edge) and if you have poor link conditions you can increase "spreadingfactor" above 7, which is the fastest this bonnet can handle:
## Config file for RPi-LoRa-KISS-TNC 2nd generation

## Lora Module selection
sx127x = True #if True, enables sx127x family, else sx126x

## Display enable and font
disp_en = False
font_size = 8

## Log enable and path
log_enable = True
logpath='/var/log/lora/lora.log' #log filename. Give r/w permission!

## KISS Settings
# Where to listen?
# TCP_HOST can be "localhost", "0.0.0.0" or a specific interface address
# TCP_PORT as configured in aprx.conf <interface> section
TCP_HOST = "0.0.0.0"
TCP_PORT = 10001

## Hardware Settings
# See datasheets for detailed pinout.
# The default pin assignment refers to PCB designed by I8FUC.
# The user can wire the module by his own and change pin assignment.
# assign "-1" if the pin is not used

# Settings valid for both SX126x and SX127x
busId = 0 #SPI Bus ID. Must be enabled on raspberry (sudo raspi-config). Default is 0
csId = 1 #SPI Chip Select pin. Valid values are 0 or 1
irqPin = 22 #DIO0 of sx127x and DIO1 of sx126x, used for IRQ in rx

# Settings valid only for SX126x. Default pin assignment refers to the PCB schematic /doc/LoRa_RPi_Companion_2022.pdf
resetPin = 6
busyPin = 4
# If txen and rxen are disabled (=-1), then DIO2 will be set as RF Switch control
txenPin = 0 #In Ebyte modules, it's used for switching on the tx pa.
rxenPin = 1 #In Ebyte modules, it's used for switching on the rx lna

# If Lora module has a TCXO, the following parameter must be True
# If True, the DIO3 line will be set as control voltage of the TCXO
tcxo=False

## LoRa Settings valid for both SX127x and SX126x modules
frequency = 910300000 #frequency in Hz
preamble = 32 #valid preable lenght is 8/16/24/32
spreadingFactor = 7 #valid spreading factor is between 5 and 12
bandwidth = 500000 #possible BW values: 7800, 10400,15600, 20800, 31250, 41700, 62500, 125000, 250000, 500000
codingrate = 5 #valid code rate denominator is between 5 and 8
appendSignalReport = False #append signal report when packets are forwarded to aprs server
outputPower = 17 #maximum TX power is 22(22dBm) for SX126x, and 17 (17dBm) for SX127x . Higher values will be forced to max allowed!
TX_OE_Style = False #if True, tx RF packets are in OE Style, otherwise in standard AX25
#sync_word = 0x1424 #sync word is x4y4. Es: 0x12 of 1st gen LoRa chip --> 0x1424 of 2nd gen LoRa chip
sync_word = 0x12
crc = True #defines if CRC is calculated and transmitted in the header. Note that modem works in explicit mode

#LoRa Settings valid only for SX126x
RX_GAIN_POWER_SAVING = False #If false, receiver is set in boosted gain mode (needs more power)

This github project needs more modification to work with TARPN, since it was originally written only for APRS packets and will break with any other kind. It also assumed ~400MHz, whereas the Adafruit bonnet is 33cm (902-928MHz). Here is how to update it (TODO these should be in a forked github project to remove these steps):

  1. nano pySX127x/SX127x/board_config.py (Change low_band = True, to False for 33cm support)
  2. nano pySX127x/SX127x/LoRa.py (Search for “43” and change multiple occurences to 915MHz)
  3. nano LoraAprsKissTnc_sx127x.py (Ditto, there's only 1 occurence in this one)
  4. sudo mkdir /var/log/lora
  5. sudo touch /var/log/lora/lora.log
  6. Replace KissHelper.py with this contents (this extends it to handle all KISS packets not just APRS, and makes it a little more tolerant of unexpected failures rather than just stopping the process at the first weird packet):
TODO get the contents of this file from one of my test devices (even better to put this on github instead)

Start/test your TCP-based KISS TNC with this command (you should see it print out the config values and say it's listening for connections, with no errors listed):

  • sudo python3 Start_lora-tnc.py

When you run the TNC for long-term use, you'll want to run it with "nohup sudo python3 Start_lora-tnc.py &" which will disassociate it with your linux account and run it in the background until manually terminated. In the future, we should wrap this in a systemd service.

TARPN configuration

On your TARPN node, you won't be able to run it with "tarpn service start" until TARPN is updated to allow TCP-based KISS TNCs on port 11 and 12. For now, you can force this by "tarpn service stop", then editing bpq/bpq32.cfg.

  1. nano bpq/bpq32.cfg
  2. Search for "PORTNUM=11" to find the right section
  3. Paste this in:
PORT
PORTNUM=11                                ; Optional but sets port number if stated
ID=LoRa link to KV4P-3     ; Displayed by PORTS command
TYPE=ASYNC                                ; Port is RS232 Com
PROTOCOL=KISS                         ; TNC is used in KISS (or JKISS) mode
;; See ..\RelatedFiles\KissRoms\KissRoms.zip.
FULLDUP=0                      ; Only meaningful for KISS (or JKISS) devices
;COMPORT=/dev/ttyUSB0
;SPEED=57600                    ; RS232 COM PORT SPEED
CHANNEL=A                      ; A for single channel TNC, A or B for multichannel
PERSIST=180                    ; PERSIST=256/(# of transmitters-1)
SLOTTIME=50                    ; CMSA interval timer in milliseconds
TXDELAY=50          ; Transmit keyup delay in milliseconds
TXTAIL=1                       ; TX key down, in milliseconds, at packet end
QUALITY=1                      ; Quality factor applied to node broadcasts heard on
;                               ; this port, unless overridden by a locked route
;                               ; entry. Setting to 0 stops node broadcasts
MINQUAL=81                     ; Entries in the nodes table with qualities greater or
;                               ; equal to MINQUAL will be sent on this port. A value
;                               ; of 0 sends everything.
MAXFRAME=1                     ; Max outstanding frames (1 thru 7)
FRACK=2000              ; Level 2 timout in milliseconds
RESPTIME=40                    ; Level 2 delayed ack timer in milliseconds
RETRIES=20                     ; Level 2 maximum retry value
PACLEN=136                      ; Default max packet length for this port
UNPROTO=ID                     ; BTEXT broadcast addrs format: DEST[,digi1[,digi2]]
L3ONLY=0                       ; 1=No user downlink connects on this port
DIGIFLAG=0                     ; Digipeat: 0=OFF, 1=ALL, 255=UI Only
DIGIPORT=0                     ; Port on which to send digi'd frames (0 = same port)
USERS=0                        ; Maximum number of L2 sessions, 0 = no limit
IGNOREUNLOCKEDROUTES=0  ; ignore node broadcasts from other than locked routes
IPADDR=127.0.0.1       ; Address of PC runnning the TNC. Usually this is the same machine as BPQ, so use 127.0.0.1 but can be on anoth>
TCPPORT=10001           ; Port TNC listens on. Default for UZ7HO is 8100 and Direwolf 8001
KISSOPTIONS=NOPARAMS
ENDPORT

You also need to add a fixed route for port 11 or 12 in bpq32.cfg. The appropriate section looks like this, and has commented-out port 11 and 12 routes already listed:

ROUTES: ; Locked routes (31 maximum)
KV4P-3,200,11

Of course, replace "KV4P-3" with whatever neighbor you plan to link to with that LoRa link.

Start TARPN with ./linbpq (instead of "tarpn service start"). You won't be able to use TARPN HOME until TARPN is updated to handle TCP-based KISS TNCs natively. But you can manually connect to your node (e.g. with QtTerm), and get into chat that way, and test out your new LoRa link, etc.

Performance

With the above config.py settings, a throughput test on my own TARPN node with a "bench setup" (2 LoRa transceivers right next to each other), I achieved 135bytes/sec. That's about as good as a very solid 9600 baud link with a NinoTNC and high quality mobile radios.

It can probably be made to go much faster with additional optimization. It's unclear if the KISS service running in Python represents a cap on the throughput, or if it's just the settings.