Skip to content

Commit

Permalink
chore: Added docker-compose examples with mosquitto
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorfdl committed Jun 21, 2024
1 parent 0d045f6 commit eb794c6
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 2 deletions.
46 changes: 46 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -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
```
17 changes: 17 additions & 0 deletions examples/basic-docker-compose/.tagoio-mqtt-relay.toml
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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=""
Expand Down
17 changes: 17 additions & 0 deletions examples/mosquitto-relay-setup/.tagoio-mqtt-relay.toml
Original file line number Diff line number Diff line change
@@ -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.
42 changes: 42 additions & 0 deletions examples/mosquitto-relay-setup/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions examples/mosquitto-relay-setup/mosquitto/config/mosquitto.conf
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit eb794c6

Please sign in to comment.