Merge pull request #4 from jeremiah-k/master

Lots of work
pull/9/head
Jeremiah K 2023-11-26 18:42:11 -06:00 zatwierdzone przez GitHub
commit c7f11a1d19
7 zmienionych plików z 50 dodań i 30 usunięć

1
.gitignore vendored 100644
Wyświetl plik

@ -0,0 +1 @@
docker-compose.yaml

Wyświetl plik

@ -11,4 +11,19 @@ Feel free to explore the **Meshtastic** project on their website: [https://mesht
git clone https://github.com/mate-dev/mmrelaynode.git
cd mmrelaynode && git submodule update --init
docker compose -f "docker-compose.yaml" up -d --build
```
```
If modifying the scripts, with the containers stopped, use these commands to rebuild them:
```
docker system prune -af
docker-compose build --no-cache
docker-compose up -d --force-recreate
```
Use the following command to see the output of command_wrapper.py & the MESHTASTIC_COMMAND_X commands:
```
docker exec -it mmrelaynode-app cat /home/mesh/app/command_output.txt
```
Note: If you have several commands, it may take a few minutes to finish them all.

Wyświetl plik

@ -1,13 +1,14 @@
FROM python:3.11-slim-bookworm AS app
LABEL "website"="https://github.com/mate-dev/mmrelaynode"
RUN groupadd -g 1000 mesh && useradd -ml -u 1000 -g 1000 -s /bin/bash mesh
RUN echo "export PATH=/home/mesh/.local/bin:\$PATH" >> /home/mesh/.bashrc
RUN pip install --upgrade pip -qq
RUN ln -s /home/mesh/.local/bin/meshtastic /bin/meshtastic
USER mesh
COPY --chown=mesh:mesh meshtastic-matrix-relay /home/mesh/app
COPY --chown=mesh:mesh --chmod=744 entrypoint.sh /usr/local/bin/entrypoint.sh
COPY --chown=mesh:mesh --chmod=744 wait-for-it.sh /home/mesh/.local/bin/wait-for-it.sh
COPY --chown=mesh:mesh conf_wrapper.py /home/mesh/app/
COPY --chown=mesh:mesh command_wrapper.py /home/mesh/app/
WORKDIR /home/mesh/app
RUN pip install -qq -r /home/mesh/app/requirements.txt --no-cache-dir
RUN echo "export PATH=/home/mesh/.local/bin:\$PATH" >> /home/mesh/.bashrc
RUN pip install -qq -r /home/mesh/app/requirements.txt --no-cache-dir

Wyświetl plik

@ -2,21 +2,30 @@ import os
import subprocess
import time
def log_to_file(message):
with open('/home/mesh/app/command_output.txt', 'a') as f:
f.write(message + "\n")
def execute_meshtastic_command(options):
"""Execute a meshtastic command with the given options."""
command = ["meshtastic", "--set"] + options.split()
subprocess.run(command)
time.sleep(30) # Pause for 30 seconds
command = ["meshtastic", "--host", "mmrelaydevice", "--port", "4403"] + options.split()
log_to_file(f"Executing command: {' '.join(command)}")
result = subprocess.run(command, capture_output=True, text=True)
log_to_file("Standard Output:\n" + result.stdout)
log_to_file("Standard Error:\n" + result.stderr)
time.sleep(1) # Pause for 1 second between commands
# Print all environment variables at the start
log_to_file("All environment variables:\n" + str(os.environ))
# Loop through environment variables in sequence
index = 1
while True:
command = os.environ.get(f'MESHTASTIC_COMMAND_{index}')
if command:
log_to_file(f"Found command variable: MESHTASTIC_COMMAND_{index} with value: {command}")
execute_meshtastic_command(command)
index += 1
else:
break
# Finally, run the main Meshtastic process (or whatever process you want to keep the container running)
subprocess.run(["meshtastic"])
log_to_file(f"No more MESHTASTIC_COMMAND variables found, ending at index {index-1}.")
break

Wyświetl plik

@ -0,0 +1,6 @@
#!/bin/bash
printenv
/home/mesh/.local/bin/wait-for-it.sh mmrelaydevice:4403 -t 60
python3 /home/mesh/app/command_wrapper.py
python3 /home/mesh/app/conf_wrapper.py
python3 /home/mesh/app/main.py

0
app/wait-for-it.sh 100644 → 100755
Wyświetl plik

Wyświetl plik

@ -13,10 +13,6 @@ services:
networks:
- mesh
entrypoint: ["sh", "-c", "meshtasticd"]
environment:
MESHTASTIC_COMMAND_1: "--set-owner 'LongName' --set-owner-short 'SHRT' --set-url https://meshtastic.org/e/#CgMSAQESDAgBOAFAA0gBUB5oAQ"
MESHTASTIC_COMMAND_2: "--set mqtt.enabled true --set mqtt.address mqtt.meshtastic.org --set mqtt.username meshdev --set mqtt.password large4cats"
# You can add as many MESHTASTIC_COMMAND_X as you need, they will be executed in order with a 30 second delay between or add all your setup in one command.
mmrelayapp:
build: app
@ -24,19 +20,19 @@ services:
container_name: mmrelaynode-app
restart: unless-stopped
depends_on:
- mmrelaynode
- mmrelayapp
volumes:
- mesh:/home/mesh
networks:
- mesh
entrypoint: [ "sh", "-c", "/home/mesh/.local/bin/wait-for-it.sh mmrelaynode:4403 -t 60 && python3 command_wrapper.py && python3 conf_wrapper.py && python3 main.py" ]
entrypoint: [ "bash", "-c", "entrypoint.sh" ]
environment:
MATRIX_HOMESERVER: "https://example.matrix.org"
MATRIX_ACCESS_TOKEN: "your_access_token"
MATRIX_BOT_USER_ID: "@botuser:example.matrix.org"
MESHTASTIC_CONNECTION_TYPE: "network" # "serial" or "network"
MESHTASTIC_SERIAL_PORT: "/dev/ttyUSB0"
MESHTASTIC_HOST: "mmrelaynode"
MESHTASTIC_HOST: "mmrelaydevice"
MESHTASTIC_MESHNET_NAME: "Your Meshnet Name"
MESHTASTIC_BROADCAST_ENABLED: "true"
LOGGING_LEVEL: "info"
@ -45,27 +41,19 @@ services:
MATRIX_ROOMS_MESHTASTIC_CHANNEL_1: "0"
# MATRIX_ROOMS_ID_2: "#someroomalias2:example.matrix.org"
# MATRIX_ROOMS_MESHTASTIC_CHANNEL_2: "1"
# MATRIX_ROOMS_ID_3: "#someroomalias3:example.matrix.org"
# MATRIX_ROOMS_MESHTASTIC_CHANNEL_3: "2"
# MATRIX_ROOMS_ID_4: "#someroomalias4:example.matrix.org"
# MATRIX_ROOMS_MESHTASTIC_CHANNEL_4: "3"
# MATRIX_ROOMS_ID_5: "#someroomalias5:example.matrix.org"
# MATRIX_ROOMS_MESHTASTIC_CHANNEL_5: "4"
# MATRIX_ROOMS_ID_6: "#someroomalias6:example.matrix.org"
# MATRIX_ROOMS_MESHTASTIC_CHANNEL_6: "5"
# MATRIX_ROOMS_ID_7: "#someroomalias7:example.matrix.org"
# MATRIX_ROOMS_MESHTASTIC_CHANNEL_7: "6"
# MATRIX_ROOMS_ID_8: "#someroomalias8:example.matrix.org"
# MATRIX_ROOMS_MESHTASTIC_CHANNEL_8: "7"
# Plugin environment variables
# HEALTH_PLUGIN_ACTIVE: "true"
# MAP_PLUGIN_ACTIVE: "true"
# NODES_PLUGIN_ACTIVE: "true"
MESHTASTIC_COMMAND_1: "--set-owner 'LongName' --set-owner-short 'SHRT' --set-url https://meshtastic.org/e/#CgMSAQESDAgBOAFAA0gBUB5oAQ"
MESHTASTIC_COMMAND_2: "--set mqtt.enabled true --set mqtt.address mqtt.meshtastic.org --set mqtt.username meshdev --set mqtt.password large4cats"
MESHTASTIC_COMMAND_3: "--ch-set uplink_enabled true --ch-set downlink_enabled true --ch-index 0"
# You can add as many MESHTASTIC_COMMAND_X as you need, they will be executed in order
networks:
mesh:
driver: bridge
volumes:
mesh:
mesh: