diff --git a/.gitignore b/.gitignore index 7a7135c..aae46c0 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,5 @@ configs/** **/*.log .env **/tidbyt-apps/** -**/users/** .DS_Store tidbyt-apps/ diff --git a/device_runner.py b/device_runner.py index 49b5b66..9beec48 100644 --- a/device_runner.py +++ b/device_runner.py @@ -25,12 +25,13 @@ def mqtt_setup(connect_string): url = urlparse(connect_string) user = url.username passw = url.password - host = url.hostname + host = url.hostname or 'mqtt' port = url.port topic = url.path topic = topic[1:] client = mqtt.Client() if user and passw : client.username_pw_set(user,passw) + dprint(f"Connecting to {host}:{port}") client.connect(host,port) client.loop_start() return client,topic diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..ec63dc4 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,23 @@ +version: '3.8' + +services: + web: + build: + context: . + dockerfile: Dockerfile + ports: + - "8000:8000" # Map port 8000 on the host to port 8000 in the container + - "5100:5100" # 5100 is used for pixlet serve interface during app configuration + environment: + - MQTT_BROKER_HOST=mqtt # Name of the MQTT service (hostname inside the Docker network) + - MQTT_BROKER_PORT=1883 + depends_on: + - mqtt + + mqtt: + image: eclipse-mosquitto:latest + ports: + - "1883:1883" # MQTT broker port + - "9001:9001" # (optional) WebSocket support + volumes: + - ./mosquitto.conf:/mosquitto/config/mosquitto.conf diff --git a/dockerfile b/dockerfile index 5514b27..ebf8c31 100644 --- a/dockerfile +++ b/dockerfile @@ -9,8 +9,8 @@ ENV DOMAIN=localhost # ################################### # install pixlet ENV NODE_URL=https://deb.nodesource.com/setup_21.x -ENV PIXLET_REPO=https://github.com/tavdog/pixlet -#ENV PIXLET_REPO_ZIP=https://github.com/tavdog/pixlet/archive/refs/heads/config_merge.zip +#ENV PIXLET_REPO=https://github.com/tavdog/pixlet +ENV PIXLET_REPO_ZIP=https://github.com/tavdog/pixlet/archive/refs/heads/config_merge.zip ENV TDM_REPO=https://github.com/tavdog/tidbyt-manager ENV TIDBYT_APPS_REPO=https://github.com/tidbyt/community @@ -20,10 +20,10 @@ RUN pip3 install --break-system-packages python-dotenv paho-mqtt python-pidfile WORKDIR /tmp RUN curl -fsSL $NODE_URL | bash - && apt-get install -y nodejs && node -v WORKDIR / -RUN git clone --depth 1 -b config_merge $PIXLET_REPO /pixlet -# RUN apt install unzip -# RUN wget $PIXLET_REPO_ZIP && unzip main.zip -# RUN mv pixlet-main pixlet +# RUN git clone --depth 1 -b config_merge $PIXLET_REPO /pixlet +RUN apt install unzip +RUN wget $PIXLET_REPO_ZIP -O pixlet-main.zip && unzip pixlet-main.zip +RUN mv pixlet-config_merge pixlet WORKDIR /pixlet RUN npm install && npm run build && make build diff --git a/mosquitto.conf b/mosquitto.conf new file mode 100644 index 0000000..2bf4887 --- /dev/null +++ b/mosquitto.conf @@ -0,0 +1,4 @@ +# Listen on port 1883 for all network interfaces (external hosts) +listener 1883 +# Allow anonymous connections (optional; for testing only) +allow_anonymous true diff --git a/tidbyt_manager/templates/manager/create.html b/tidbyt_manager/templates/manager/create.html index 49094b8..e1f7a70 100644 --- a/tidbyt_manager/templates/manager/create.html +++ b/tidbyt_manager/templates/manager/create.html @@ -5,7 +5,7 @@

{% block title %}New Tidbyt Device{% endblock %}

{% block content %}
(Descriptive name for this Tidbyt device) - (ID from Tidbyt app or mqtt url eg. mqtt://user:pass@hostname:1883/topic ) + (Leave Blank is using docker-compose.) -- ID from Tidbyt app or mqtt url eg. mqtt://user:pass@hostname:1883/topic (leave blank when using mqtt)