# APRS to MQTT bridge

The APRS to MQTT bridge can relay commands from an MQTT broker to the APRS nodes via the Linux AX.25 stack. For now, only commands which response with a defined acknowledge (commands 10 and higher) are supported.

This program is a utility for the APRS telemetry system used by PE1RXF. The telemetry is embedded in an APRS message which can travel over the existing APRS network. For more information about this open protocol visit this link: https://www.meezenest.nl/mees-elektronica/projects/aprs_telemetry/APRS_protocol_nodes_PE1RXF.pdf

## Configuration

The program is configured via a YAML file. The global section defines the MQTT broker and some APRS transmit settings. The topics define the MQTT topics on which a client can publish a request. The full path of the topic is 'topic_root/topic_name'. Call, server and port define the AX.25 settings where 'call' is the call of the APRS node the message is send to, 'server' is the call of the APRS server which sends the message (typically this is the call assigned to the ax25 port) and 'port' is the Linux AX.25 port on which the radio is connected.

Lets say we have an APRS node which can switch several power rails. (https://www.meezenest.nl/mees-elektronica/RPi-pico-LoRa-APRS.html). We connected a 5GHz HamNet dish to output 2 of this APRS node. The node is assigned the call 'PE1RXF-6'. Assume this node can be reached via the radio connected to AX.25 port ax2 on our server. The node switches the output to high when it receives command '33{33'. We want the bridge to send this command when it receives payload 'ON' via MQTT on topic 'hamnet_aprs_nodes/ubiquity_dish_ptmp_workshop'. With the below example configuration, we can achieve just that. And by sending MQTT payload 'OFF', the APRS node switches the ouptut off again.

Multiple topics for the same or another APRS node can be defined as shown in the example.

```
# Global settings apply to all other entries
global:
        broker: pe1rxf.ampr.org             # The MQTT broker we are going to use
        port: 1883                          # The tcp port of the MQTT broker
        topic_root: hamnet_aprs_nodes       # MQTT topic root
        transmit_rate: 20                   # Number of seconds between each transmision
        retry: 3                            # Try this often before giving up
        destination: APRX29                 # Destination or program ID
        digi_path: WIDE2-1                  # Digi path of APRS messages
        #beacon_program: /usr/sbin/beacon   # The external AX.25 beacon program => obsolete


topics:
    # MQTT topic: 5GHz dish at workshop (must be unique name)
    - name: ubiquity_dish_ptmp_workshop
      call: PE1RXF-6                        # Call of node to which commands below are send
      server: PE1RXF-3                      # Call of APRS server sending the commands
      port: ax2                             # Name of AX.25 port to use
      command:
        - payload: 'ON'                     # This is the payload we have to receive
          cmd: 33{33                        # This command is send to the node
          response: ack33                   # This response is expected from the node
        - payload: 'OFF'
          cmd: 32{32
          response: ack32

    # Server at tiny house
    - name: server_tiny_house
      call: PE1RXF-7
      server: PE1RXF-3
      port: ax2
      command:
        - payload: 'ON'
          cmd: 31{31
          response: ack31
        - payload: 'OFF'
          cmd: 30{30
          response: ack30
```
The configuration entry 'global:retry' sets the amount of APRS message retries we attempt before giving up. The configuration entry 'global:transmit_rate' sets the time between retries.

For now, the state of the outputs of the APRS nodes is not published to the MQTT broker. In the future, this could be implemented in the software. It is possible to poll the nodes via command '06' to get the current state of the outputs.

## Requirements

- Python3
- Python AX.25 Module for Python3 (https://github.com/ha5di/pyax25)
- pathlib
- yaml
- paho-mqtt
- Linux AX.25 stack

