SensorsIot / IOTstack

Docker stack for getting started on IOT on the Raspberry PI
GNU General Public License v3.0
1.42k stars 303 forks source link

Would you add MQTT Explorer to the stack? #686

Open smadds opened 1 year ago

smadds commented 1 year ago

It would be great to have MQTT Explorer in the IOTStack.

I have found that the smeagolworms4/mqtt-explorer docker image is stable on my RPi

Thanks for all your good work

Paraphraser commented 1 year ago

I thought this sounded like a good idea and I was going to prepare a Pull Request to add the container to IOTstack but I'm not having much luck.

By way of background, I have been running the macOS version of MQTT Explorer. The macOS version works perfectly so I don't know why that experience isn't translating to the Docker version.

This is the service definition I'm using:

  mqtt-explorer:
    container_name: mqtt-explorer
    image: smeagolworms4/mqtt-explorer
    restart: unless-stopped
    environment:
      - HTTP_PORT=4000
      - CONFIG_PATH=/mqtt-explorer/config
      # - HTTP_USER=
      # - HTTP_PASSWORD=
      # - SSL_KEY_PATH=
      # - SSH_CERT_PATH=
    ports:
      - "4000:4000"
    volumes:
      - ./volumes/mqtt-explorer:/mqtt-explorer/config

I start the container, then check its log:

$ docker logs mqtt-explorer
LOAD MODULE WRAPPED: electron
Start MQTT Explorer node server

    - http-port: 4000
    - config-path: /mqtt-explorer/config
    - http-user: 
    - http-password: 
    - ssl-key-path: 
    - ssl-cert-path: 

subscribing connection/add/mqtt
subscribing connection/remove
subscribing storage/store
subscribing storage/load
subscribing storage/clear
server is listening on 4000

Nothing that screams out as being wrong. I fire up a browser and connect to the instance. Then:

  1. I delete the two default connections.

  2. I hit + for a new connection:

    • I give it a name.

    • I turn off Validate certificate

    • Encryption is off - I leave it alone

    • For the host name I supply mqtt.my.domain.com. This is the same domain name as is used by every device in the house (ESP32, ESP8266, Pis, Macs) to publish, as well as any tool (except Node-RED) that subscribes to any topic.

      Node-RED is running on the same host as Mosquitto so flows just subscribe to mosquitto:1883 across the internal bridged network.

    • Port defaults to 1883 - I leave it alone

    • Username and password are empty - I leave them alone (my Mosquitto instance lives behind my firewall and is never exposed so I don't care about credentials)

    • I click Advanced:

      • All topics of interest match /merle/# so I add that
      • I delete the two default topics
      • I click Back
    • I click Save

    • I click Connect.

  3. The window repaints. Writes "disconnect" on the right hand side and puts mqtt.my.domain.com in the top left hand corner.

  4. Nothing else happens.

  5. I click on the domain name and …

Splat. The dialog box that appears contains:

Oooooops!
I hoped that you would never see this window, but MQTT-Explorer had an unexpected error.

cleanup@http://sec-dev.my.domain.com:4000/3.bundle.js:25338:38
@http://sec-dev.my.domain.com:4000/vendors.bundle.js:15158:251
@http://sec-dev.my.domain.com:4000/vendors.bundle.js:15274:468
Ki@http://sec-dev.my.domain.com:4000/vendors.bundle.js:15158:174
Mi@http://sec-dev.my.domain.com:4000/vendors.bundle.js:15165:223
Sj@http://sec-dev.my.domain.com:4000/vendors.bundle.js:15197:75
Sj@[native code]
@http://sec-dev.my.domain.com:4000/vendors.bundle.js:15274:468
Jj@http://sec-dev.my.domain.com:4000/vendors.bundle.js:15192:372
yj@http://sec-dev.my.domain.com:4000/vendors.bundle.js:15183:378
yj@[native code]
@http://sec-dev.my.domain.com:4000/vendors.bundle.js:15067:116
@http://sec-dev.my.domain.com:4000/vendors.bundle.js:15274:468
fg@http://sec-dev.my.domain.com:4000/vendors.bundle.js:15067:63
gg@http://sec-dev.my.domain.com:4000/vendors.bundle.js:15066:498
Ga@http://sec-dev.my.domain.com:4000/vendors.bundle.js:15231:97
gd@http://sec-dev.my.domain.com:4000/vendors.bundle.js:15012:373
gd@[native code]
Please report this issue with a short description of what happened to https://github.com/thomasnordquist/MQTT-Explorer/issues

I tap Restart and try again. Same result.

I re-check the log. The only additional lines are:

New client: b1ZomcXmzQGr6RP-AAAB
subscribing conn/publish/73227bd0-c070-4c92-bc4f-ae6d2eb7d47a
New client: OyvHogUEBzN0g9lvAAAD
unsubscribeAll conn/publish/73227bd0-c070-4c92-bc4f-ae6d2eb7d47a
subscribing conn/publish/73227bd0-c070-4c92-bc4f-ae6d2eb7d47a
New client: irs-S8dWqHOSnT6eAAAF

The settings file contains:

$ cat ~/IOTstack/volumes/mqtt-explorer/settings.json 
{
  "ConnectionManager_connections": {
    "73227bd0-c070-4c92-bc4f-ae6d2eb7d47a": {
      "configVersion": 1,
      "certValidation": false,
      "clientId": "mqtt-explorer-8dbb21e8",
      "id": "73227bd0-c070-4c92-bc4f-ae6d2eb7d47a",
      "name": "Merle",
      "encryption": false,
      "subscriptions": [
        {
          "topic": "/merle/#",
          "qos": 0
        }
      ],
      "type": "mqtt",
      "host": "mqtt.my.domain.com",
      "port": 1883,
      "protocol": "mqtt"
    }
  }
}

All looks correct.

When I very carefully do the identical configuration steps in the macOS app, I get:

image

which is obviously working, while the browser-based version just gets:

image

The "mqtt.my.domain.com" line in the browser never gets a disclosure triangle and, as I said, clicking on the line results in the error message.

Noting that the macOS version:

  1. starts by drawing the "mqtt.my.domain.com" line without the disclosure triangle; but
  2. almost immediately redraws with the disclosure triangle,

my working hypothesis was:

Not so. Proof.

I have a small bash script named mossieMonitor that uses mosquitto_sub to subscribe to /merle/# and bungs out timestamped messages as they arrive. Here it is running outside container-space on the Pi:

$ mossieMonitor 
2023-04-21T23:20:08+1000 /merle/camera/snoop/hello {"message": "camera passed hello test"}
2023-04-21T23:20:11+1000 /merle/box-hiking/grid {"T01":513.17,"T02":0.00,"a":0.00,"v":244.50,"w":0.00,"pf":1.00,"f":49.99}
2023-04-21T23:20:21+1000 /merle/box-hiking/grid {"T01":513.17,"T02":0.00,"a":0.00,"v":244.50,"w":0.00,"pf":1.00,"f":50.00}
2023-04-21T23:20:31+1000 /merle/box-hiking/grid {"T01":513.17,"T02":0.00,"a":0.00,"v":244.50,"w":0.00,"pf":1.00,"f":50.00}
^C

The mqtt-explorer container doesn't have the Mosquitto clients so I need to add those:

$ docker exec mqtt-explorer ash -c "apk update && apk add mosquitto-clients"
fetch https://dl-cdn.alpinelinux.org/alpine/v3.15/main/aarch64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.15/community/aarch64/APKINDEX.tar.gz
v3.15.8-46-gf5157076646 [https://dl-cdn.alpinelinux.org/alpine/v3.15/main]
v3.15.8-46-gf5157076646 [https://dl-cdn.alpinelinux.org/alpine/v3.15/community]
OK: 15742 distinct packages available
(1/4) Installing cjson (1.7.15-r0)
(2/4) Installing c-ares (1.18.1-r0)
(3/4) Installing mosquitto-libs (2.0.14-r1)
(4/4) Installing mosquitto-clients (2.0.14-r1)
Executing busybox-1.34.1-r5.trigger
OK: 8 MiB in 20 packages

Copy the script into the container:

$ docker cp ~/.local/bin/mossieMonitor mqtt-explorer:.
Preparing to copy...
Copying to container - 2.048kB
Successfully copied 2.048kB to mqtt-explorer:.

Run the script inside the container:

$ docker exec mqtt-explorer /mossieMonitor
2023-04-21T13:21:05+0000 /merle/camera/snoop/hello {"message": "camera passed hello test"}
2023-04-21T13:21:11+0000 /merle/box-hiking/grid {"T01":513.17,"T02":0.00,"a":0.00,"v":244.30,"w":0.00,"pf":1.00,"f":49.96}
2023-04-21T13:21:21+0000 /merle/box-hiking/grid {"T01":513.17,"T02":0.00,"a":0.00,"v":244.20,"w":0.00,"pf":1.00,"f":49.97}
^C

So, the container can definitely communicate with the broker.

I've tried Safari and Chrome to see if this is a browser difference. I've tried a laptop, desktop and iPad to see if it's a platform difference.

I'm stumped.

You say it's working perfectly well for you so it's probably something incredibly obvious and dumb that I'm doing. Any ideas?


I'm doing all this on a Pi4 running full 64-bit Bullseye:

$ uname -a
Linux sec-dev 6.1.21-v8+ #1642 SMP PREEMPT Mon Apr  3 17:24:16 BST 2023 aarch64 GNU/Linux