From 135b80cf3ffd34dbe338d52bb8a481f044f0d0ac Mon Sep 17 00:00:00 2001 From: marcel Date: Thu, 18 Jan 2024 14:15:45 +0100 Subject: [PATCH] Fixed some nasty repeater-flag problems --- CHANGELOG.md | 8 + KissHelper.py | 26 +- README.md | 20 + images/RPi_LoRa_shield.svg | 4318 ++++++++++++++++++++++++++++++++++++ 4 files changed, 4359 insertions(+), 13 deletions(-) create mode 100644 images/RPi_LoRa_shield.svg diff --git a/CHANGELOG.md b/CHANGELOG.md index 34a1b9d..e9d5760 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,3 +36,11 @@ All notable changes to this project will be documented in this file. ### Removed - Config.py as configuration is now completely removed. Configuration is now done completely via RPi-LoRa-KISS-TNC.ini + +## [0.0.4] - 2024-01-18 + +Should now be possible to use it as a real digipeater with aprx software + +### Fixed +- Added '*' to LoRa APRS TX string when the 'has-been-repeated' flag of the repeater(s) in the AX.25 frame is set. +- Proper handling of 'has-been-repeated' asterix in LoRa RX frames, also when no SSID is received diff --git a/KissHelper.py b/KissHelper.py index b6b210c..da914e6 100644 --- a/KissHelper.py +++ b/KissHelper.py @@ -30,6 +30,7 @@ # # 2022-01-23: - in encode_address() added correct handling of has_been_repeated flag '*' # 2022-01-28: - in encode_kiss() and encode_address(): better exeption handling for corrupted or mal-formatted APRS frames +# 2024-01-18: - in decode_kiss() add '*' to call when 'has-been-repeated' flag is set for reapeters # import struct @@ -44,6 +45,15 @@ KISS_TFESC = 0xDD # If after an escape, means there was an 0xDB in the source m # If it's the final address in the header, set the low bit to 1 # Ignoring command/response for simple example def encode_address(s, final): + + encoded_ssid = 0b00000000 + + # First we check if the call has the 'has_been_repeated' asterix at the ended. + # If so, set the 'has_been_repeated' flag and remove the asterix + if s[-1] == 42: + s = s[:-1] + encoded_ssid |= 0b10000000 + if b"-" not in s: s = s + b"-0" # default to SSID 0 call, ssid = s.split(b'-') @@ -51,19 +61,6 @@ def encode_address(s, final): call = call + b" "*(6 - len(call)) # pad with spaces encoded_call = [x << 1 for x in call[0:6]] - encoded_ssid = 0b00000000 - # If ssid ends with *, the message has been repeated, so we have to set the 'has_been_repeated' flag and remove the * from the ssid - if ssid[-1] == 42: - # print("Message has been repeated") - ssid = ssid[:-1] - encoded_ssid |= 0b10000000 - - # If SSID was not pressent (and we added the default -0 to it), the has_been_repeated flag could be at the end of the call, so check that as well - # Also, there is a lot of bad software around (including this code) and ignorance of the specifications (are there any specs for LoRa APRS?), so always check for the has_been_repeated flag - if call[-1] == 42: - call = call[:-1] - encoded_ssid |= 0b10000000 - # SSID should now be one or two postions long and contain a number (idealy between 0 and 15). if len(ssid) == 1 and ssid[0] > 47 and ssid[0] < 58: encoded_ssid |= (int(ssid) << 1) | 0b01100000 | (0b00000001 if final else 0) @@ -194,6 +191,9 @@ def decode_kiss(frame): # print("RPT: ", rpt_addr) pos += 7 result += b"," + rpt_addr.strip() + # Add repeater flag if set + if (rpt_hrr & 0x04) == 0x04: + result += b"*" result += b":" diff --git a/README.md b/README.md index 6beaebd..5543aec 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,34 @@ # Raspberry Pi LoRa KISS TNC +This project adds LoRa APRS to the Raspberry Pi. It is fully integrated in the Linux AX.25 stack for maximum flexibility. + This project was originally started by Tom Kottek (https://github.com/tomelec/RPi-LoRa-KISS-TNC). Because the program had some problems dealing with digipeated frames (it crashed when receiving a ssid with the 'has_been_digipeated' flag -*- set), I took on the task of fixing the code for my personal use. +The software is stable and can handle repeated frames (incomming and outgoing) so it can be used with the aprx software to make a digipeater. + ## Software The software controls the LoRa transceiver connected to the Raspberry´s SPI bus and emulates a KISS TNC over TCP. That makes it possible to use existing software like APRX. It is also possible to attach the KISS interface to the AX.25 stack via socat/kissattach. +Assuming you installed and configured the AX.25 stack, start the LoRa KISS TNC with these commands: + + #!/bin/bash + + # Start TNC software + /usr/bin/python3 ~/RPi-LoRa-KISS-TNC/Start_lora-tnc.py & + sleep 10 + # Attach TCP socket to virtual tty device located at /tmp/lorakisstnc + sudo /usr/bin/socat PTY,raw,echo=0,link=/tmp/lorakisstnc TCP4:127.0.0.1:10001 & + sleep 3 + # Attach virtual tty to AX.25 stack (port ax2) + sudo /usr/sbin/kissattach /tmp/lorakisstnc ax2 & + ## Hardware +[![How to connect LoRa module to Raspberry Pi](./images/RPi_LoRa_shield.svg)](./images/RPi_LoRa_shield.svg) + I also designed my own (open source) hardware for it: a board holding a Raspberry Pi Zero 2 W, an SX1278 LoRa transceiver and a power supply with on/off button to safely switch on and off the system. The design files can be found on my website: [RPi LoRa_shield](https://meezenest.nl/mees/RPi_LoRa_shield.html) ### To Do + * Add raw TCP KISS socket for true AX.25 over KISS diff --git a/images/RPi_LoRa_shield.svg b/images/RPi_LoRa_shield.svg new file mode 100644 index 0000000..e3252f2 --- /dev/null +++ b/images/RPi_LoRa_shield.svg @@ -0,0 +1,4318 @@ + + + + + + image/svg+xml + + SVG Picture created as RPi_LoRa_shield.svg date 2024/01/18 10:46:34 + + + + + + SVG Picture created as RPi_LoRa_shield.svg date 2024/01/18 10:46:34 + Picture generated by Eeschema-SVG + + + + + + + +3V3 + + +3V3 + + + + + + + + + + +5V + + +5V + + + + + + + GND + + GND + + + + + + GND + + GND + + + + + + + + + C1 + + C1 + + + + + 100n + + 100n + + + + + + + + + + + +3V3 + + +3V3 + + + + + + + + + GND + + GND + + + + + 1 + + 1 + + + + + DIO4 + + DIO4 + + + + + + + 10 + + 10 + + + + + + DIO5 + + DIO5 + + + + + + 11 + + 11 + + + + + + + SCK + + SCK + + + + + + + 12 + + 12 + + + + + + MISO + + MISO + + + + + + 13 + + 13 + + + + + + MOSI + + MOSI + + + + + + 14 + + 14 + + + + + + + NSS + + NSS + + + + + 15 + + 15 + + + + + + GND + + GND + + + + + 16 + + 16 + + + + + + GND + + GND + + + + + 2 + + 2 + + + + 3V3 + + 3V3 + + + + + 3 + + 3 + + + + RST + + RST + + + + + + + 4 + + 4 + + + + + DIO0 + + DIO0 + + + + + + 5 + + 5 + + + + DIO1 + + DIO1 + + + + + + + 6 + + 6 + + + + DIO2 + + DIO2 + + + + + + 7 + + 7 + + + + DIO3 + + DIO3 + + + + + + 8 + + 8 + + + + GND + + GND + + + + + 9 + + 9 + + + U1 + Ra-02 + + Ra-02 + + + + + + + + + + GND + + GND + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 3V3 + + + 3V3 + + + + + + 1 + + + 1 + + + + + + GND + + + GND + + + + + + 14 + + + 14 + + + + + + + MOSI0/GPIO10 + + MOSI0/GPIO10 + + + + + + + + + + + + + + + 19 + + 19 + + + + + + + 5V + + + 5V + + + + + 2 + + + 2 + + + + + GND + + + GND + + + + + + 20 + + + 20 + + + + + MISO0/GPIO9 + + MISO0/GPIO9 + + + + + + + + + + + + + 21 + + 21 + + + + + + SCLK0/GPIO11 + + SCLK0/GPIO11 + + + + + + + + + + + + + + + + + + 23 + + 23 + + + + + ~{CE0}/GPIO8 + + ~{CE0}/GPIO8 + + + + + + + + + + + + + + + 24 + + 24 + + + + + + + GND + + + GND + + + + + + 25 + + + 25 + + + + + GCLK1/GPIO5 + + GCLK1/GPIO5 + + + + + + + + + + + + + + + + 29 + + 29 + + + + + SDA/GPIO2 + + SDA/GPIO2 + + + + + + + + + + + + 3 + + 3 + + + + + GND + + + GND + + + + + + 30 + + + 30 + + + + + GCLK2/GPIO6 + + GCLK2/GPIO6 + + + + + + + + + + + + + + + 31 + + 31 + + + + + + + GND + + + GND + + + + + + 34 + + + 34 + + + + + + GPIO16 + + GPIO16 + + + + + + + + + 36 + + 36 + + + + + + GND + + + GND + + + + + + 39 + + + 39 + + + + + + 5V + + + 5V + + + + + 4 + + + 4 + + + + + GPIO21/SCLK1 + + GPIO21/SCLK1 + + + + + + + + + + + + + + + + + + 40 + + 40 + + + + + + SCL/GPIO3 + + SCL/GPIO3 + + + + + + + + + + + 5 + + 5 + + + + + GND + + + GND + + + + + + 6 + + + 6 + + + J1 + Raspberry_Pi_for_lora_module + LORA_RST + + + + + + + + + + + + + + DIO0 + + + + + + NSS + + + + + MOSI + + + + + + POWER_ON_RPI + SCK + + + + + + + MOSI + + + + + + MISO + + + + + + NSS + + + + + LORA_RST + + + + + + + + + + + + + + DIO0 + + + + + + MISO + + + + + + SCK + + + + + + + 433MHz LORA transceiver + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Raspberry Pi Zero 2 W + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +3V3 + + + + + + C1 + + + + 100n + + + + + + + + + GND + + + + + + + + + + + + + + +