IMD SolutionComputing LibraryShop main store

Troubleshooting

MQTT over WebSocket browser access for sensor data

Edge computing and IIoT Published 7 min read By IMD Solution engineering team

Short answer

WebSocket is a transport, not a delivery path. Prove the sensor's messages reach the broker by subscribing to the exact topic from a test client on its secure WebSocket listener, then serve stored readings from a database-backed web application or live values through broker-authorized MQTT-over-WebSocket subscriptions. Publishing the Node-RED editor to the internet is not an option.

On this page
  1. Prove the sensor's messages reach the broker first
  2. Choose the delivery path before opening a port
  3. Worked example: a lab sensor publishing every 10 seconds
  4. Reach the WebSocket listener from the browser
  5. Make the broker authorize the subscription
  6. Why a published Node-RED editor is not an option
  7. The decision for each case
  8. Questions asked

WebSocket is a transport, not a delivery path. A sensor publishing to an MQTT broker cannot reach a lab or plant full of browsers by itself, and no browser setting repairs a publisher that never connects. Prove first that the sensor's messages arrive at the broker: subscribe to the exact topic from a test client on the broker's secure WebSocket listener. Then choose one of two delivery paths — an authenticated web application over the database for stored readings, or broker-authorized MQTT-over-WebSocket subscriptions for live values. Publishing the Node-RED editor to the internet is not a third option.

Prove the sensor's messages reach the broker first #

A browser cannot correct a sensor, gateway or broker-ingestion failure, so trace the publishing side before touching the viewing side. Work down the list in order and stop at the first step that fails:

  • Record who actually publishes: the sensor's own firmware, or a gateway such as Node-RED publishing on its behalf. Write down the exact topic string.
  • Check the publisher's connection status and its publish counters or error logs. A working network link is not an authenticated MQTT session.
  • Subscribe to that exact topic from a test client. MQTTX works as a desktop diagnostic client and mqtt.js works in a script; connect either to the broker's MQTT-over-WebSocket Secure listener — the same endpoint a browser will use.
  • Generate a change you can recognize at the sensor and compare the arriving payload's value and timestamp with what the current dashboard shows.
  • If the test subscription receives the messages while other viewers still cannot, the publish path is proven and the fault sits downstream.

Every path in this article runs through one place, because MQTT clients publish and subscribe through the broker, so the broker's connection and authorization logs are the first evidence of where messages stop. If the test subscription stays silent, the fault is upstream of any browser work, and the repair is the same one that fixes an MQTT client that never reaches your broker.

Choose the delivery path before opening a port #

WebSocket carries bytes between a client and a broker. It is not a database interface and not an access-control system, so pick the path from what the viewers actually need:

Viewing requirement Delivery path What the browser runs Who authorizes access
Stored readings, reports, occasional refresh Sensor to broker to ingestion service, then database and web application An HTTPS session in the application The application checks each viewer before every database query
Live values on screen Sensor to broker to the MQTT-over-WebSocket listener, then browser An MQTT session holding permitted subscriptions The broker authorizes the browser identity per topic filter
Stored readings plus live values Database-backed application plus a live update channel Both of the above Historical and live permissions must agree

For recorded measurements, the application backed by the database is the simpler boundary to manage: viewers log in once and never hold broker credentials. For immediate values, direct browser subscriptions are a sound choice when the broker documents MQTT-over-WebSocket support and its identity model fits a browser page. A custom backend can also forward live updates to its own pages without ever handing a browser a broker connection.

Worked example: a lab sensor publishing every 10 seconds #

The case is a lab sensor feeding a cloud broker, where one person at a time can currently see the readings. The example proves the publish path before any viewer work starts; substitute your own interval and window.

Inputs

  • Publish interval: 10 seconds — an example value; read the real interval from the publisher's configuration or measure it from the test subscription's timestamps.
  • Test window: 120 seconds — two minutes of watching the test subscription.
  • Listener: the broker's MQTT-over-WebSocket Secure endpoint; AWS IoT Core documents WSS support on port 443, so the test client connects exactly the way a browser would.
  • Topic: the exact topic string the publisher writes, for example lab/sensor/temperature.

Rule in words: expected messages = test window ÷ publish interval, and the pass mark is the full expected count, every payload carrying the current value and a fresh timestamp.

Arithmetic: 120 s ÷ 10 s per message = 12 messages.

Result: the test subscription must show 12 messages inside the two minutes, and when you trip a change at the sensor, the next payload must track it.

Decision: 12 of 12 proves delivery to the broker, so the fault lies in distribution and the viewer work can begin. Fewer than 12 — nine arriving, say — means the publish path itself drops messages; keep every browser closed until the count reads 12 of 12, and repair the publisher side first. One check belongs in the same session: confirm the payload's field names, because a message with a renamed field passes this count test and still fails in the database or the page.

Reach the WebSocket listener from the browser #

The sensor's route and the viewer's route are separate: a sensor can deliver perfectly while every browser fails, because the browser uses another hostname, another listener, another proxy or another transport. Diagnose in stages:

  • Resolve the WebSocket hostname from a viewer's own network, not from the publisher's.
  • Confirm the firewall and any proxy pass the listener port. AWS IoT Core's documented WSS listener sits on port 443, which most corporate firewalls already pass for HTTPS; a self-managed broker usually keeps plain WebSocket on port 9001, wherever that listener is configured.
  • Check TLS before MQTT: the certificate must be trusted and must match the hostname, and a page served over HTTPS may open only secure WebSocket — browsers block plain ws:// before MQTT ever starts.
  • Separate the two stages. A completed WebSocket handshake proves only that the transport opened; the broker must then accept the MQTT connection on top of it. Read the client's logs to see which stage failed.

Raw MQTT straight over port 443 to a cloud endpoint is a different mode, one that needs ALPN negotiated on the TLS handshake; MQTT over WebSocket Secure rides ordinary HTTPS and does not. For what a browser script must get right when it opens the connection, the guide on implementing a WebSocket client with secure WSS connections covers the handshake and certificate details.

Make the broker authorize the subscription #

An open socket proves only the transport. The broker must accept the MQTT connection and grant the subscription, so read the connection acknowledgment and the subscription acknowledgment before blaming the network:

  • Authenticate the viewer through the identity system the application chose. On AWS IoT Core, the browser presents credentials governed by that service's policy; a self-managed broker enforces its own access rules. Either way, the backend hands out short-lived connection material, and privileged server credentials never ship inside downloadable JavaScript.
  • Grant the minimum: a read-only display needs subscribe permission on the sensor topics and nothing else — a viewer who may not publish should hold no publish right.
  • Match the topic filter to the publisher's exact topic, including case and hierarchy levels, and let wildcards span levels only where that is intended.
  • Trigger a known sensor change and watch it arrive under the browser identity. That is the only end-to-end proof the grant works.

For a fully worked set of broker-side rules that match topic strings, the walkthrough of writing MQTT Distributor ACL topic filters for Sparkplug B shows the pattern end to end.

Why a published Node-RED editor is not an option #

The editor is an administration surface, not a data service. Anyone who can reach it can change flows, and a changed flow can forward the sensor readings to any host on earth. It also gives every viewer the same administrative identity, so there is nothing left to authorize per person.

The dashboard route has the same shape in milder form: one shared address, one identity at best, and a single local computer as the only viewing path. Keep the editor and the dashboard on the lab or plant network, and serve viewers through one of the two delivery paths above. Node-RED stays useful on the publishing side, where the gateway can publish on the sensor's behalf.

The decision for each case #

  • Fewer than the expected count at the test subscription: the publish path is broken. Repair the publisher — connection, topic, credentials, broker permissions — before any browser work.
  • Full count, and viewers need history, reports or occasional refresh: ingest into the database and serve an authenticated web application. Browsers never speak MQTT on this path.
  • Full count, and viewers need live values: broker-authorized MQTT-over-WebSocket subscriptions on the secure listener, with subscribe-only grants on the sensor topics and short-lived connection material issued by your backend.
  • Any plan that begins by publishing the Node-RED editor or a bare dashboard address to the internet is the wrong plan at either count.

Questions asked

Which port does MQTT over WebSocket use?

AWS IoT Core documents MQTT over WebSocket Secure on port 443, the same port as HTTPS, which most firewalls already pass. A self-managed broker typically exposes plain WebSocket on port 9001 and secure WebSocket wherever its TLS listener is configured. A plain TCP MQTT listener on port 1883 cannot accept a browser connection at all, because browser scripts cannot open raw TCP sockets.

Can several people subscribe to the same sensor topic at once?

Yes. A broker is built for many concurrent subscribers to one topic. Give each browser session its own client identifier: a second connection that reuses an identifier makes the broker drop the first session, which looks to users like random disconnects. Each session then subscribes independently, so one viewer closing a tab never disturbs the others.

Do I need a gateway product between the broker and the browsers?

Usually no. A broker that documents MQTT over WebSocket Secure already accepts browser subscriptions, and common browser libraries speak that transport. Add a gateway only when it supplies an integration or an access policy your broker genuinely lacks, because every extra hop is one more connection, one more credential set and one more failure point to maintain.

Why do browser MQTT connections drop after a few idle minutes?

Idle connections get closed on the path. A broker ends a session that sends nothing for roughly one and a half times the keepalive interval, and corporate proxies often kill idle tunnels sooner. Set the client's keepalive below half the shortest idle timeout in the path, so a heartbeat packet always crosses the link before any device gives up.

Is the Node-RED dashboard safe once it has a password?

A password guards the editor, not the data path. Anyone who gets past it can edit flows, and an edited flow can forward your sensor data to a host outside your control. Keep the editor on the lab network and give viewers the database-backed application or the broker-authorized subscriptions instead.

Keep reading

  • Explainer

    Why Databus 3.1 MQTT over WebSockets is limited to IIH apps

    Databus 3.1 enables MQTT over WebSockets only for Industrial Information Hub applications, with the Common Configurator on Industrial Edge Management as the stated consumer. No port or client contract is published for general use; the deciding check is the consuming application's identity, not the network. IIH applications take their endpoint from the integration, and every other client uses the documented MQTT interface.

    Edge computing and IIoT

  • How-to

    Bridge a cellular tracker's TCP stream into MQTT for AWS IoT Core

    Build a small ingest service on your edge PC: it terminates the tracker's raw TCP session, decodes each stored record, and republishes one MQTT message per fix over TLS on port 8883. Acknowledge a packet only after every publish is confirmed, or a coverage-gap batch is silently lost.

    Edge computing and IIoT

  • How-to

    Bridging OPC UA PLC data to MQTT with an edge PC

    Keep the OPC UA server on the PLC side and give MQTT publishing its own role on a separate edge PC that acts as the OPC UA client and MQTT publisher. Commission the two links independently — first a verified tag read, then a verified subscriber message — and only then widen the tag set.

    Edge computing and IIoT

What decides time correlation in multi-device test data logging