IMD SolutionComputing LibraryShop main store

Explainer

Choosing QoS and FFT analysis for MQTT vibration alerts

Edge computing and IIoT Published 7 min read

Short answer

Keep fault alerts at QoS 1: the repeat-suppression logic already absorbs the duplicates QoS 1 can produce, and QoS 2's four-way handshake buys nothing for a few alerts a day. Move the FFT to the edge PC and leave the ESP32 as a timed sampler, because bearing tones need kHz-range sampling with steady timing and re-analyzable raw blocks.

On this page
  1. What each QoS level actually guarantees
  2. Why QoS 1 is the right call for infrequent fault alerts
  3. What frequency analysis demands from the sampler
  4. Where the FFT belongs: the edge PC
  5. Sizing the sampling and FFT block for an 1800 RPM motor
  6. Verifying the alert path end to end
  7. Questions asked

Keep the fault alerts at QoS 1 and run the FFT on the edge PC. QoS 1 already guarantees the alert is delivered at least once, and the duplicate it can produce is absorbed by the repeat-suppression logic you already built; QoS 2's four-packet exchange adds latency and broker state without changing anything your team can see. On the analysis side, an ESP32 can sample vibration fast enough for bearing tones, but the transform belongs one hop up: publish timed raw blocks and let a PC do the FFT, so you keep the waveform, can re-window and re-size the transform in software, and never let the radio stack disturb the measurement. This pipeline tells people something changed; it does not replace the machine's hard-wired protection trip, which stays independent.

What each QoS level actually guarantees #

MQTT gives you three service levels, and the difference is packets on the wire. QoS 0 sends a PUBLISH and forgets it. QoS 1 waits for a PUBACK and retransmits until one arrives, which is what "at least once" means. QoS 2 is the highest level: a four-packet exchange — PUBLISH, PUBREC, PUBREL, PUBCOMP — that holds state at both ends until the sequence completes, so the message arrives exactly once and no duplicate can slip through.

Level Packets per message Delivery Duplicates Place in this pipeline
QoS 0 PUBLISH only At most once No retry, so none Routine readings
QoS 1 PUBLISH, PUBACK At least once Possible Fault alerts
QoS 2 PUBLISH, PUBREC, PUBREL, PUBCOMP Exactly once Prevented Not used

One rule decides what actually arrives: the delivered level is the lower of the level the publisher used and the level the broker granted the subscription. A QoS 2 publish that reaches a subscription granted QoS 1 is delivered as QoS 1, so before you chase exactly-once behavior, confirm what the broker grants — resolving a QoS 2 downgrade on QoS 1-only brokers starts with that check.

Why QoS 1 is the right call for infrequent fault alerts #

An alert path that fires a few times a day is not a throughput problem; it is a "did it arrive" problem, and QoS 1 answers it. The device retransmits until the broker acknowledges, so a dropped packet or a Wi-Fi reconnect does not swallow the alert.

The only thing QoS 2 adds is duplicate prevention, and you already own a deduplicator: your automation layer suppresses repeat alerts for an ongoing condition, and a QoS 1 duplicate looks exactly like that — the same alert arriving again. Trading two extra packets and longer broker state to prevent something your own logic absorbs is a bad deal on an infrequent path, and worse on a recovering link, where every extra exchange is another chance to stall.

Commit to this split: routine temperature and vibration readings publish at QoS 0, because a seconds-old reading is replaced by the next one; fault alerts publish at QoS 1 and the automation layer subscribes at QoS 1. Keep them on separate topics so acknowledgement traffic never touches the telemetry stream.

What frequency analysis demands from the sampler #

A raw threshold tells you how much the machine is shaking; frequency tells you which fault is doing it, because bearing wear, imbalance and misalignment each push energy into their own bands. Getting there is a sampling problem before it is a processing one:

  • Sample at least twice the highest frequency you want to see, and keep the tones of interest well below half the sample rate so nothing sits against the band edge.
  • Frequency resolution is the sampling rate divided by the FFT size; block duration is the FFT size divided by the sampling rate.
  • Samples must be evenly spaced. The transform assumes it, and jitter in the sample interval smears the peaks you are hunting.

The sensor chain sets the ceiling before any processor question. One documented setup, an ADXL337 analog accelerometer read from an Arduino, reached 1600 samples/s on X and Y and 550 samples/s on Z, which caps the usable band at 0–800 Hz and 0–275 Hz — enough for the bearing tones worked out below, and a number to verify for your own front end, because a different one moves it.

Where the FFT belongs: the edge PC #

An ESP32 can compute a Fourier transform; spectrum analyser projects built on the ArduinoFFT library run on ESP32-class boards. Doing it there is still the wrong call. First, the radio and the MQTT stack share the CPU with your sample loop, so unless sampling is hardware-timer driven, publishing disturbs the timing the transform depends on. Second, if the microcontroller publishes only the spectrum, the spectrum is all you keep; re-running with a different window or a bigger block means new firmware and a walk to the machine. Third, what you will want next — averaged spectra, band trends, machine-to-machine comparison — is a software change on a PC and a firmware project on a microcontroller.

Split the work instead:

  • ESP32: sample on a timer, buffer a completed block, publish the raw block plus the temperature reading, register a last-will message with the broker.
  • Edge PC: window the block, run the FFT, average spectra, hold band thresholds per machine, decide the alert, absorb duplicates.

The box for that job is a fanless mini PC in the control cabinet, subscribed to every machine's block topic. Per message the raw blocks are small, but continuous streaming from several machines turns into real storage, which is the moment to think through choosing edge storage for high-rate vibration data.

Sizing the sampling and FFT block for an 1800 RPM motor #

Inputs:

  • Shaft speed 1800 RPM — a four-pole motor on a 60 Hz supply, typical for this duty.
  • Tones of interest: rolling-bearing race defects land between about three and seven times shaft speed, depending on geometry; plan for that range.
  • Sampler: the documented chain above — 1600 samples/s on X and Y with an 800 Hz band, 550 samples/s on Z with a 275 Hz band.
  • FFT size 1024 samples, 16-bit samples, three axes.

Rules: the Nyquist minimum is twice the highest tone; resolution equals sample rate divided by FFT size; block time equals FFT size divided by sample rate; payload equals samples times bytes per sample times axes.

Arithmetic:

  • Shaft rate: 1800 ÷ 60 = 30 Hz.
  • Highest tone: 7 × 30 Hz = 210 Hz.
  • Nyquist minimum: 2 × 210 = 420 samples/s. Chosen rate on X and Y: 1600 samples/s, which puts 210 Hz at 210 ÷ 800 ≈ 26% of the band, far from the edge.
  • Z axis: 550 samples/s covers to 275 Hz, and 210 Hz sits three-quarters of the way up — confirm bearing tones on the radial axes.
  • Resolution: 1600 ÷ 1024 = 1.5625 Hz per bin. The 30 Hz shaft tone and a 90 Hz race tone are 60 Hz apart, about 38 bins apart.
  • Block time: 1024 ÷ 1600 = 0.64 s.
  • Payload: 1024 × 2 bytes × 3 axes = 6144 bytes, about 6 kB.

Decision: sample at 1600 samples/s on X and Y, publish one 1024-sample block per machine per minute — roughly 360 kB per hour — and run the FFT on the edge PC. Streaming every 0.64 s block instead would run 6144 ÷ 0.64 = 9.6 kB/s, about 35 MB per hour per machine, so cadence is a storage decision as much as a detection one. The threshold to watch is the 800 Hz band of the documented chain: above that, the sensor is your limit, not the processor argument; below it, the split above holds and the FFT stays on the PC.

Verifying the alert path end to end #

  • Publish one reading above the threshold and one below; confirm the machine tag is right, the first crossing alerts, and repeats for the same active condition do not.
  • Publish the same alert twice in quick succession and confirm the suppression absorbs the second copy — that is the QoS 1 duplicate case, handled.
  • Pull power on the ESP32 mid-run: the last-will message should arrive, and the automation layer should treat silence as a fault, not as health.
  • Clear the condition and confirm a later, different fault still alerts.
  • Prove the granted QoS on the bench first — run a secure Mosquitto MQTT lab broker with Node-RED and check what the subscription is granted before you trust the plant broker.

Questions asked

Where do QoS 1 duplicates actually come from?

From the retry. A QoS 1 sender retransmits the PUBLISH, marked as a duplicate, until it sees the PUBACK; if the first copy was delivered but the acknowledgement was lost, the broker sees the message twice. The protocol allows this on purpose, because at-least-once means the receiver handles deduplication.

What QoS should the routine temperature and vibration readings use?

QoS 0, on topics separate from the alert topics. A lost periodic reading is replaced by the next one seconds later, so acknowledgement traffic buys nothing, and splitting topics lets the automation layer subscribe to alerts at QoS 1 without paying it on the telemetry stream.

When is QoS 2 the right choice at all?

When a duplicate has a side effect you cannot undo downstream, such as a message that commands a physical move, adds a dose, or increments a counter, and both ends actually grant it. Notification text sent to a human almost never qualifies, because a repeated notification is merely annoying, not harmful.

What happens to the sampled block if Wi-Fi drops mid-publish?

Buffer the last completed block and publish it on reconnect, and register a last-will message with the broker so the automation layer learns the device is gone. Treat missing data as an alarm condition in the automation layer: silence from a machine is not the same as a healthy machine.

How much data do raw vibration blocks add up to?

One 1024-sample, three-axis, 16-bit block is 6144 bytes. Published once a minute that is about 360 kB per machine per hour; streamed continuously at 1600 samples/s it is about 9.6 kB/s, roughly 35 MB per hour, which is why cadence and the storage plan are worth deciding together.

Keep reading

  • Explainer

    MQTT to Kafka edge data pipeline without losing messages

    Keep MQTT on the sensor side of the plant, put the Kafka-class durable log on the site or cloud side of the uplink, and give the boundary one disk-backed store-and-forward buffer sized to the longest outage you will ride through. At 500 messages per second and an 8-hour outage, that queue holds 14.4 million messages and about 9.6 GB — set the ceiling above it and alarm on overflow.

    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

  • How-to

    Run Python and Node-RED beside PLC code on an edge PC

    Keep the IEC 61131-3 program in the controller runtime and run Python and Node-RED as separate Docker containers on the same edge PC. Exchange data over one MQTT interface with a fixed publish period, and declare data stale after three missed periods. One container per workload, and nothing from Python or Node-RED inside the control project.

    Edge computing and IIoT