diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 0000000..8847947 --- /dev/null +++ b/examples/README.md @@ -0,0 +1,46 @@ +# TagoIO MQTT Relay Examples + +This directory contains example configurations for setting up the TagoIO MQTT Relay using Docker Compose. These examples demonstrate how to configure and deploy the relay with different setups. + +## Table of Contents + +- [Docker Compose Example](#docker-compose-example) +- [Mosquitto Docker Compose Example](#mosquitto-docker-compose-example) + +## Docker Compose Example + +This example demonstrates how to set up the TagoIO MQTT Relay using Docker Compose with a basic configuration. + +### Configuration + +- **File**: `docker-compose.yml` +- **Description**: This configuration sets up the TagoIO MQTT Relay service with the necessary ports and volumes. You can configure the relay using a `config.toml` file or environment variables. + +### Usage + +1. Navigate to the `docker-compose` directory. +2. Ensure the `config.toml` file is correctly configured. +3. Run the following command to start the service: + + ```sh + docker-compose up -d + ``` +## Mosquitto Docker Compose Example + +This example demonstrates how to set up the TagoIO MQTT Relay with an Eclipse Mosquitto broker using Docker Compose. + +### Configuration + +- **File**: `docker-compose.yml` +- **Description**: This configuration sets up the TagoIO MQTT Relay service and a Mosquitto broker. The relay is configured to connect to the Mosquitto broker using environment variables. + +### Usage + +1. Navigate to the `mosquitto-docker-compose` directory. +2. Ensure the `config.toml` file is correctly configured if you prefer using it over environment variables. +3. Ensure the `mosquitto/config/mosquitto.conf` file is correctly configured for mosquitto. +4. Run the following command to start the services: + + ```sh + docker-compose up -d + ``` \ No newline at end of file diff --git a/examples/basic-docker-compose/.tagoio-mqtt-relay.toml b/examples/basic-docker-compose/.tagoio-mqtt-relay.toml new file mode 100644 index 0000000..9be600f --- /dev/null +++ b/examples/basic-docker-compose/.tagoio-mqtt-relay.toml @@ -0,0 +1,17 @@ +[relay] +network_token="Your-Network-Token" # Generate a Network Token under your TagoIO Network Settings +authorization_token="Your-Authorization-Token" # Generate an Authorization Token under your TagoIO > Devices > Authorizations +tagoio_url="https://api.tago.io" # Default +downlink_port="3001" # Default is 3000 + +[relay.mqtt] +client_id="tagoio-relay" # Default is tagoio-relay +tls_enabled=false +address="localhost" +port="1883" +subscribe=["/device/#"] # MQTT topics to subscribe to +username="my-username" +password="my-passowrd" +# broker_tls_ca="" # The CA certificate. Alternative to username and password +# broker_tls_cert="" # The client certificate. +# broker_tls_key="" # The client key. diff --git a/examples/docker-compose/docker-compose.yml b/examples/basic-docker-compose/docker-compose.yml similarity index 89% rename from examples/docker-compose/docker-compose.yml rename to examples/basic-docker-compose/docker-compose.yml index e2e8f89..fdf6251 100644 --- a/examples/docker-compose/docker-compose.yml +++ b/examples/basic-docker-compose/docker-compose.yml @@ -6,7 +6,7 @@ services: # Port for the TCP server - "3001:3001" volumes: - - ./config.toml:/root/.config/.tagoio-mqtt-relay.toml + - .tagoio-mqtt-relay.toml:/root/.config/.tagoio-mqtt-relay.toml # Uncomment next lines to configure using environment variables instead of toml # environment: @@ -19,7 +19,7 @@ services: # - TAGOIO__RELAY__MQTT__TLS_ENABLED="false" # - TAGOIO__RELAY__MQTT__ADDRESS="localhost" # - TAGOIO__RELAY__MQTT__PORT="1883" - # - TAGOIO__RELAY__MQTT__SUBSCRIBE="/tago/# /topic/+" + # - TAGOIO__RELAY__MQTT__SUBSCRIBE__1="/device/#" # - TAGOIO__RELAY__MQTT__USERNAME="my-username" # - TAGOIO__RELAY__MQTT__PASSWORD="my-password" # - TAGOIO__RELAY__MQTT__BROKER_TLS_CA="" diff --git a/examples/mosquitto-relay-setup/.tagoio-mqtt-relay.toml b/examples/mosquitto-relay-setup/.tagoio-mqtt-relay.toml new file mode 100644 index 0000000..fee75aa --- /dev/null +++ b/examples/mosquitto-relay-setup/.tagoio-mqtt-relay.toml @@ -0,0 +1,17 @@ +[relay] +network_token="Your-Network-Token" # Generate a Network Token under your TagoIO Network Settings +authorization_token="Your-Authorization-Token" # Generate an Authorization Token under your TagoIO > Devices > Authorizations +tagoio_url="https://api.tago.io" # Default +downlink_port="3001" # Default is 3000 + +[relay.mqtt] +client_id="tagoio-relay" # Default is tagoio-relay +tls_enabled=false +address="mosquitto-broker" +port="1883" +subscribe=["/device/#"] # MQTT topics to subscribe to +username="my-username" +password="my-passowrd" +# broker_tls_ca="" # The CA certificate. Alternative to username and password +# broker_tls_cert="" # The client certificate. +# broker_tls_key="" # The client key. diff --git a/examples/mosquitto-relay-setup/docker-compose.yml b/examples/mosquitto-relay-setup/docker-compose.yml new file mode 100644 index 0000000..ba99f1c --- /dev/null +++ b/examples/mosquitto-relay-setup/docker-compose.yml @@ -0,0 +1,42 @@ +services: + tagoio-mqtt-relay: + image: tagoio/relay:latest + restart: always + depends_on: + - mosquitto-broker + ports: + # Port for the TCP server + - "3001:3001" + + volumes: + - .tagoio-mqtt-relay.toml:/root/.config/.tagoio-mqtt-relay.toml + + # Example using the environment variables for easy setup. You can use the .tagoio-mqtt-relay.toml above instead if you prefer. + environment: + # TagoIO Related Settings + - TAGOIO__RELAY__NETWORK_TOKEN="Your-Network-Token" + - TAGOIO__RELAY__AUTHORIZATION_TOKEN="Your-Authorization-Token" + + # Mosquitto Broker Settings for the Relay to connect to + - TAGOIO__RELAY__MQTT__ADDRESS=mosquitto-broker + - TAGOIO__RELAY__MQTT__TLS_ENABLED=false + - TAGOIO__RELAY__MQTT__CLIENT_ID=tagoio-relay + - TAGOIO__RELAY__MQTT__USERNAME=my-username + - TAGOIO__RELAY__MQTT__PASSWORD=my-password + - TAGOIO__RELAY__MQTT__SUBSCRIBE__1="/tago/#" + + # - TAGOIO__RELAY__MQTT__PORT=1883 + # - TAGOIO__RELAY__MQTT__BROKER_TLS_CA="" + # - TAGOIO__RELAY__MQTT__BROKER_TLS_CERT="" + # - TAGOIO__RELAY__MQTT__BROKER_TLS_KEY="" + + mosquitto-broker: + image: eclipse-mosquitto + restart: unless-stopped + ports: + - "1883:1883" + - "8883:8883" # Port for TLS + volumes: + - ./mosquitto/config:/mosquitto/config:rw + - ./mosquitto/data:/mosquitto/data:rw + - ./mosquitto/log:/mosquitto/log:rw diff --git a/examples/mosquitto-relay-setup/mosquitto/config/mosquitto.conf b/examples/mosquitto-relay-setup/mosquitto/config/mosquitto.conf new file mode 100644 index 0000000..bdabc89 --- /dev/null +++ b/examples/mosquitto-relay-setup/mosquitto/config/mosquitto.conf @@ -0,0 +1,21 @@ +# mosquitto.conf + +# Default listener (non-TLS) +listener 1883 + +# TLS listener +listener 8883 +#cafile /mosquitto/config/ca.crt +#certfile /mosquitto/config/server.crt +#keyfile /mosquitto/config/server.key + +# Persistence settings +persistence true +persistence_location /mosquitto/data/ + +# Log settings +log_dest file /mosquitto/log/mosquitto.log +log_type all # Log all events, including connection attempts + +# Allow anonymous connections (no password required) +allow_anonymous true