IMD SolutionComputing LibraryShop main store

Selection guide

Selecting MQTT I/O hardware for a single sensor signal

Edge computing and IIoT Published 7 min read

Short answer

For one discrete sensor, choose an Ethernet I/O block whose input matches the sensor's 24 V PNP or NPN output, publish on state change, and verify hostname, TLS and QoS support in the documentation before buying. QoS 2 guarantees delivery only between client and broker, so prove the path with a staged wiring-to-subscriber test.

On this page
  1. What hardware publishes a single sensor to MQTT over LAN?
  2. Does the input match the sensor's PNP or NPN output?
  3. Is an I/O block, a controller, or an edge PC the better fit?
  4. Does QoS 2 guarantee every sensor event arrives?
  5. Will my broker actually honor QoS 2?
  6. How fast must the input be to catch every pulse?
  7. What should I verify for hostname, TLS, and PoE before ordering?
  8. How do I test the path before trusting it?
  9. Questions asked

For one discrete sensor on MQTT, the reliable path is an Ethernet I/O block with a discrete input documented for the sensor's output type, publishing on state change. QoS 2 covers only the hop between the publishing client and the broker, so the reliability you are paying for comes from earlier decisions: an input that actually matches the sensor's PNP or NPN output, a device whose documentation shows hostname and TLS support, and a staged test from wiring to subscriber. Work those in the order below and the protocol checkbox stops being the risk.

What hardware publishes a single sensor to MQTT over LAN? #

For one sensor, an Ethernet I/O block with discrete inputs and native MQTT is the answer: documented units read 8 to 16 inputs at the low DC logic levels their datasheets list, publish over wired LAN, and need no controller in between.

What current documentation shows, as examples rather than endorsements: the ADAM-6000/6200 line actively publishes MQTT messages at a user-defined interval and raises alarm event notifications, with TLS listed; the LucidIoT input module offers 16 isolated channels across multiple DC voltage ranges with MQTT, Modbus TCP/IP and logging; the MQ-7255M combines 8-channel DI with 8-channel DO over MQTT and Modbus TCP. A compact controller, an HMI with an MQTT driver, a router with onboard I/O, or an edge PC with an input card will also carry one signal; the choice among them is the decision after the input match.

Does the input match the sensor's PNP or NPN output? #

Read the sensor datasheet first: a typical retroreflective sensor runs on 24 V DC and switches either PNP, sourcing the positive line, or NPN, sinking to 0 V, and the input must be documented for exactly that type.

A PNP sensor drives the supply voltage onto the signal wire when the beam returns from the reflector; an NPN sensor pulls the wire toward 0 V. Match that to the block: an input that sinks current takes the PNP sensor directly, an input that sources takes the NPN sensor, and a plain voltage input takes either using the wiring arrangement the module manual draws. Channel isolation, documented on the 16-channel example above, decides whether sensor ground and block ground must be tied. If this sensor also serves a safety function, leave that circuit alone and fit a second sensor for monitoring; a repurposed signal is not a safety design.

The decision rule is absolute: no documented input match in the module manual, no purchase, whatever the MQTT feature list says.

Is an I/O block, a controller, or an edge PC the better fit? #

For one signal with no logic, buy the I/O block; move to a compact controller when the signal needs local logic or buffering, and to an edge PC only when this box will carry other data work too.

Route Documented examples Why pick it Verify before buying
Ethernet I/O block 16 isolated inputs with MQTT, Modbus TCP/IP and logging; 8-input/8-output units with both protocols; one family with interval publishing, event notification and TLS Fewest layers between sensor and broker for a single signal Input type per channel, event-driven publishing, TLS detail
Compact controller Any small controller with a documented MQTT client and a matching input card Local debouncing, logic and buffering under your control Engineering time for one signal is the real cost
HMI with an MQTT driver Operator panels with documented MQTT support Gives a display where one is wanted anyway Adds a display and configuration layer a one-signal job does not need
Edge PC with an input interface A compact PC plus a discrete-input card matched to the sensor Any maintained MQTT client, plus room for dashboards or a historian Most wiring and software work of the four routes

If the box will also collect other tags, host a dashboard or buffer for a historian, choose a fanless mini PC plus an input card matched to the sensor's output; for the sensor alone, the block wins on layers and wiring.

Does QoS 2 guarantee every sensor event arrives? #

No. QoS 2 guarantees exactly-once delivery of each published message between the client and the broker through a four-step handshake, and it says nothing about whether the input ever sampled the transition or whether the subscriber processed the message.

The handshake costs round trips, and its guarantee stops at the broker. End to end you are chaining four links: input sampling, the publish trigger, client-to-broker delivery, subscriber processing. QoS 2 hardens only the third. Set the level on both the publish and the subscribe side, because delivery is negotiated at the lower of the two, and check what the subscriber actually reports rather than what the publisher is configured for. When the pipeline carries alarms instead of raw state, the same trade-off drives choosing QoS and FFT analysis for MQTT vibration alerts. If you need every transition over time rather than the current state, start from whether an MQTT broker stores historic data you can query, because most do not.

Will my broker actually honor QoS 2? #

Not always. AWS IoT Core documents that a publish requesting QoS 2 gets no exactly-once exchange and is delivered zero or more times, so the broker's documented QoS support is a hard gate on this selection.

If the broker is one that downgrades QoS 2, stop requesting it: publish at QoS 1 and make the payload idempotent, a state plus a timestamp or sequence number, so the subscriber can discard the duplicates QoS 1 permits. What the device does with events while the network is down is a device behavior, not a QoS feature; read what the manual commits to and compare it against offline message delivery and what standard QoS covers before you trust queued data.

How fast must the input be to catch every pulse? #

The input must resolve the shortest pulse your process makes: an illustrative 100 ms flag pulse sampled every 250 ms can fall entirely between scans, so event-driven publishing beats fixed intervals whenever the pulse is brief.

Worked example, with illustrative numbers where the method is the point:

  • Conveyor speed 0.5 m/s, target flag 50 mm wide.
  • Pulse width = 0.050 m ÷ 0.5 m/s = 0.10 s = 100 ms.
  • Interval publishing every 250 ms samples the input 4 times per second; a 100 ms pulse fits between two samples, so it can be missed entirely.
  • Fix one: use the block's alarm or event notification so the transition itself triggers the message, where that is documented.
  • Fix two: widen the flag so the pulse spans at least two scans: 2 × 250 ms = 500 ms, which at 0.5 m/s needs 0.5 m/s × 0.500 s = 0.25 m of flag.

Decision: for counting or short-pulse detection, require event-driven or latched inputs and treat interval publishing as a heartbeat only.

What should I verify for hostname, TLS, and PoE before ordering? #

Verify three documented items that a basic MQTT checkbox hides: broker address entry by hostname rather than IP only, TLS with public-key or certificate import, and true PoE powered-device classification with a matching switch or injector.

The gap integrators hit late is the small one: units that connect happily by IP address but cannot resolve a hostname, or that expose TLS as a toggle with no way to load your certificate authority. One family in the examples above documents TLS; for the others, the manual must say so or the feature does not exist. An RJ45 jack is not PoE: confirm the device is a powered device, which type it is, and that the switch or injector supplies it. Then check where the sensor's supply comes from, because powering the block over PoE does not power the sensor unless the block documents a sensor supply output.

How do I test the path before trusting it? #

Test in four stages, input, network, broker session, subscriber, and treat the install as proven only when a real sensor transition arrives, with the right payload, at the subscriber after a deliberate network interruption.

  1. De-energize, wire the sensor to the input per both manuals, re-power, and confirm the input indicator toggles as the reflector target enters and leaves the beam.
  2. Connect Ethernet, confirm link and address, then resolve the broker hostname as a separate step if you use one.
  3. Configure the broker connection, a unique topic, the payload shape, QoS, and authentication or TLS to match the broker's policy, trying it first where you can run a secure Mosquitto MQTT lab broker with Node-RED.
  4. Subscribe with a test client, exercise the sensor through both states, and confirm topic, payload and message count.
  5. Pull the network link, change the sensor state if it is safe to do so, restore the link, and compare what arrives with what the manual promised for buffering.

A successful connection test proves nothing about the signal; only the observed transition at the subscriber does. If transitions are lost across the interruption and the process cannot tolerate that, select a device that queues events while disconnected instead of re-publishing only the current state.

Questions asked

Do I need a PLC between the sensor and the MQTT block?

No. The block reads the discrete input and publishes it directly, with no controller in the path. Add a controller only when the signal needs local logic or debouncing beyond what the block offers, or when the point already exists in a PLC whose MQTT client can publish it instead.

Can I power the sensor from the I/O block's terminals?

Only if the block documents a sensor supply output and its voltage and current limits cover the sensor's draw from its datasheet; many blocks power their own inputs but nothing external. Otherwise feed the sensor from the cabinet's 24 V DC distribution on its own protected branch, and keep the signal wire to the input as short as the layout allows.

What payload should one discrete signal publish?

Pick one shape and keep it stable: a short JSON object carrying the state and an ISO-8601 timestamp, or a plain 1 and 0 when the subscriber adds the context. The timestamp or a sequence number is also what lets a QoS 1 subscriber discard duplicates safely, which matters on brokers that do not honor QoS 2.

What does a retained message actually buy me?

The last known state, delivered to any subscriber that joins late. It is not an event history: transitions that occurred while nobody was listening are gone unless the device or a historian logged them. If the application needs counts or sequences over time, store them downstream of the broker rather than relying on the retained flag.

Keep reading

  • Selection guide

    Selecting a gateway to publish Modbus data to Azure IoT Hub

    Publish direct from the gateway only when its exact model and firmware documents an Azure IoT Hub connector with a configurable JSON payload and a configurable publish interval; Azure accepts TLS-secured MQTT at QoS 0 or 1 only. Otherwise keep acquisition on the gateway and run Azure messaging on a small edge application beside it.

    Edge computing and IIoT

  • Comparison

    PLC MQTT direct publishing versus an IoT gateway

    For publishing process data to an MQTT broker for web monitoring, put the MQTT client in a gateway and leave the S7-1500 out of broker session logic. Keep the LMQTT_Client block in the PLC only when publication must be coordinated with control logic or the gateway cannot meet your topic, payload and delivery requirements. A green MQTT status proves the broker connection only, never the S7 data behind it.

    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