Industrial IoT • Modbus RTU • Commissioning
30 RS485 Temperature and Humidity Sensors to MQTT Cloud: Design and Commissioning Guide
Need live temperature and relative-humidity readings from 30 locations on a tablet, with cloud history and no missing data when the Internet drops? This guide turns that requirement into a practical RS485 Modbus RTU network, edge polling design, durable MQTT pipeline and repeatable acceptance test.
Illustrative industrial automation hero. The custom wiring and data-flow architecture below describes this specific 30-sensor design.
1. System architecture: field devices to tablet and cloud
Keep the physical serial line, data collection, local history and Internet connection as separate failure domains. If the broker is down, sensing should continue locally. If one sensor is unreachable, the other addresses should still be polled. If the gateway reboots, a stored device map and queued readings must survive.
Original conceptual diagram: sensing → serial acquisition → local persistence → secure synchronization. Cloud outages should not prevent local monitoring.
Choose whether the edge master is an industrial gateway, PLC or small computer. A PLC can handle deterministic local acquisition and a separate service can publish telemetry. A Linux computer with an isolated USB-RS485 adapter is useful for a laboratory proof of concept, but an industrial gateway with surge protection, watchdog and controlled power is usually easier to maintain on a plant floor. For foundational terminology, see PLC inputs, outputs and ladder logic.
2. RS485 wiring: a 30-node bus is not 30 separate serial ports
On a common two-wire, half-duplex Modbus RTU network, the transmit/receive pair runs as a trunk from the master to each instrument. Avoid a large star of long branches. Use twisted-pair cable of appropriate impedance, route away from noisy high-power conductors where possible, and keep derivations short. The installation should follow the gateway and sensor manufacturers’ EMC, shielding, isolation and grounding guidance.
| Item | Practical decision | What to verify on site |
|---|---|---|
| Network topology | Trunk / daisy chain with short drops | Measured run length, stub lengths, cable specification |
| Signal labels | D1/D0 or A/B and a signal common where specified | Vendor polarity labels differ; do not rely on the letter A alone |
| Termination | At the two physical ends, if required | Built-in terminators, cable impedance, no accidental middle terminators |
| Bias / polarization | One coordinated bias point when needed | Master and sensor manuals; avoid competing bias networks |
| Supply | Separate rated DC power distribution with protection | Total sensor current, voltage drop, fusing, isolation |
| Addresses | Unique IDs 1–30 in a documented plan | Duplicate address test before installing all nodes |
| Serial format | One agreed baud, parity and stop-bit configuration | 9600 8N1 is only an example, not a universal factory default |
The Modbus Organization’s current specification index points implementers to the Serial Line Protocol and Implementation Guide V1.02. It describes termination at both physical ends and how polarization should be coordinated; it does not justify placing a resistor at every sensor.
Do not guess terminal pins or apply 24 V to RS485 data terminals. The connector marked A/B/COM is a data interface; supply terminals are different. Check the exact sensor drawing and isolation arrangement before energizing. For long/noisy sites, choose isolated interfaces and an appropriate surge-protection strategy.
3. How fast can one gateway read 30 sensors?
Do not promise a fixed update rate from the sensor count alone. Polling depends on baud rate, serial framing, number of registers, device turnaround, gateway overhead, timeouts and retries. Many temperature/humidity applications need a reliable multi-second refresh rather than aggressive sub-second scanning.
Worked line-time illustration: reading two contiguous holding registers can require an eight-byte request and a nine-byte normal response. With an example 9600-baud, 8N1 link, 17 bytes × 10 bits/byte ÷ 9600 ≈ 17.7 ms of on-wire character time, before inter-frame silence and device processing. Multiply by 30 devices, then add turnaround and scheduled margins. A time-out on even one absent sensor may dominate the cycle. Actual Modbus RTU framing and timing must follow the equipment's protocol implementation.
A useful planning formula is:
round_time ≈ Σ (request + response + turnaround + gaps
+ retry allowance) per polled device
data_age = now - timestamp_of_last_valid_sample
Set a cycle-time objective, then measure the 95th-percentile and worst-case valid sample age with all 30 nodes attached. Pilot with three real sensors first, expand to 10, then 30. Do not compensate for a badly wired bus by simply increasing retries indefinitely.
4. Register map: temperature is not always register 0
Each sensor model has its own documented map. Some place temperature and humidity in adjacent holding registers; others use input registers, 32-bit floating values or status registers. Never assume that a raw value of 256 means 25.6 °C without checking the scaling, sign and register address convention.
| Field | Illustrative mapping only | Validation needed |
|---|---|---|
| Device ID | 01–30 | Exactly one responder per ID |
| Temperature | Holding register offset 0, signed 16-bit, ÷ 10 | Vendor register map, signedness and scale |
| Humidity | Holding register offset 1, unsigned 16-bit, ÷ 10 | Vendor register map, unit and range |
| Function code | 03 (holding) or 04 (input), depending on device | Confirm supported functions |
| Status / error | Optional vendor register | Sentinel values and documented exceptions |
Modbus PDU register addresses are zero-based even when a device manual displays a register as 40001. The Modbus Organization’s function-code introduction explains FC03 holding-register reads and address conventions. Use the tested vendor map in configuration, not an undocumented assumption in application code.
One safe read loop pattern
# Pseudocode; adapt to the gateway and register map
for sensor in configured_sensors:
try:
raw = read_modbus(sensor.slave_id, sensor.register_map)
value = decode_with_vendor_scale(raw)
if not within_plausible_physical_range(value):
record_invalid(sensor, reason="out_of_range")
continue
store_local(sensor.id, value, sampled_at_utc(), quality="ok")
except TimeoutOrCRCError as exc:
mark_sensor_stale(sensor.id, reason=type(exc).__name__)
continue
# A publisher reads only committed records from the local queue.
Separate acquisition from publishing. If a sensor times out, keep the previous value as historical data, but mark it stale. Do not quietly write 0 °C or 0% RH; those are potentially valid readings and would corrupt the history.
5. MQTT, offline buffering and a tablet dashboard
Think of a gateway as two independent services: a Modbus poller that writes valid samples locally, and a cloud publisher that uploads already-stored records. This prevents an Internet interruption from stopping collection. The local store can be SQLite with a bounded queue on a small computer or a vendor gateway’s documented nonvolatile buffer.
For each sample, store sensor_id, captured_at_utc, values, unit, quality, a monotonically assigned or unique sample_id, and an upload state. A representative message is:
Topic: factory/zone-a/sensors/th-07/telemetry
{
"sample_id": "zone-a-th07-20261116T041000Z-01",
"sensor_id": "th-07",
"captured_at": "2026-11-16T04:10:00Z",
"temperature_c": 28.4,
"humidity_pct": 57.2,
"quality": "ok"
}
Offline replay: append to a durable queue before acknowledging the polling result as stored; publish pending records in capture order where sensible; mark delivered only after the required acknowledgment; use unique sample IDs to deduplicate on the server. Check storage capacity and retention before rollout. A 30-sensor system sampling once every 30 seconds would produce about 86,400 samples per day if all nodes are healthy, so plan real storage and network budgets rather than assuming a free cloud tier is unlimited.
MQTT QoS 1 means at least once, not exactly once. It may deliver duplicates; persistent local storage and application-level deduplication are still required for trustworthy history. See the OASIS MQTT 5.0 standard for QoS, retained messages and session state.
What should the tablet show?
Give each instrument its own compact card: sensor name/location, current temperature, humidity, last successful sample time, freshness state and high/low alarm thresholds. Use an obvious offline / stale state rather than presenting an old number as current. When a tablet is on the same plant Wi-Fi, a local API can serve recent readings even with WAN down. Cloud history can synchronize when connectivity returns.
Choose a clear freshness policy. For example, if the nominal poll period is 5 seconds, marking data stale after 20 seconds might be an initial test hypothesis, not a universal standard. Set the alarm based on the actual measured end-to-end latency and site process risk; record why it was chosen.
Security and reliability
Use broker-side credentials per device, TLS with certificate validation, least-privilege publish topics, network segmentation between OT devices and the public Internet, controlled remote updates and secure time synchronization. Never expose the RS485 master directly to the Internet. NIST SP 800-82 Rev. 3 (final, September 2023) provides OT risk-management guidance; as of November 2026 a Revision 4 initial public draft was open for comment, so do not mistake it for the published final revision.
6. Practical bill of materials and buyer questions
Before requesting quotations, specify the network and operating requirements. A low-cost gateway that cannot retain data during a power loss may be more expensive in operational time than a slightly costlier industrial gateway with a documented local queue.
| Component | Quantity | What to ask the supplier |
|---|---|---|
| Industrial RS485 temperature/RH transmitters | 30 | Accuracy, calibration, ingress rating, response time, supply voltage, register map and unit load |
| Isolated RTU master / edge gateway | 1 | Supported addresses, polling, buffer size, watchdog, MQTT TLS, firmware support |
| 24 VDC supply, fuse and enclosure | Site-sized | Current and voltage-drop calculation, environmental protection and labeling |
| Shielded RS485 cable and terminations | By survey | Length, impedance, grounding, stub topology, pre-existing termination |
| Local LAN/Wi-Fi and optional 4G | By coverage | Outage behavior, fallback connectivity, cellular data and remote management |
| MQTT broker + durable history + dashboard | 1 stack | TLS, retention, backups, alerting, access control, tablet offline behavior |
Selection rule: insist on a real register-map PDF, a test utility, documented RS485 loading, and evidence of persistent store-and-forward before choosing the cheapest sensor or converter. Include calibration, installation and maintenance labor in total cost. Avoid quoting an unverified per-sensor price as if it applied to every vendor.
7. FAT/SAT commissioning checklist for 30 devices
- Bench test one instrument. Verify power, polarity using the vendor manual, Modbus ID, serial framing and raw register scaling against a reference thermometer/hygrometer.
- Create the address register. Record sensor ID, physical tag, location, register-map version, firmware and cable branch for all 30 nodes.
- Bench test three nodes. Confirm one response per ID and no timeouts. Deliberately duplicate an address only on an isolated test setup to confirm the fault can be diagnosed.
- Build the trunk. Inspect wiring for daisy-chain routing, termination only at ends, bias arrangement and compliant grounding/isolation; de-energize before wiring changes.
- Scale to 10 then 30. Log CRC, timeout and retry counters per device. Measure the last-good sample age, not only the number of loop iterations per second.
- Test an offline sensor. Remove one slave from the test network and verify the remaining 29 continue, while the missing device turns stale without false zero readings.
- Test WAN loss. Disconnect Internet while keeping plant LAN and power intact. Confirm values remain visible on the local dashboard and durable records accumulate.
- Test replay. Restore connectivity; verify every queued sample reaches cloud history without duplicates after deduplication, preserving original capture timestamps.
- Test power interruption. Reboot the gateway, inspect queue durability and ensure no corrupted data are shown as valid; reconcile unavoidable gaps transparently.
- Test alarms and maintenance. Use simulated over/under-limit values and approved test procedures; verify notification timing, role-based acknowledgement, backups and restore instructions.
Monitoring is not safety control. Temperature/RH telemetry over general-purpose Modbus, MQTT and cloud services must not be assumed to provide a safety-rated machine trip or life-safety alarm. Any protective function needs a separate documented hazard assessment, suitable devices and validated logic.
Frequently asked questions
Can one gateway handle all 30 temperature and humidity sensors?
Often yes, but only after checking the gateway's Modbus address count, RS485 transceiver unit loading, cable constraints and the time budget. The number 30 by itself is not an engineering guarantee.
Should every sensor use a different Modbus slave address?
Yes, every responder on one serial segment needs a unique configured address. A duplicate address is a common cause of unreliable data and apparent communication noise.
Do I install a 120-ohm terminator at each sensor?
No. Install termination at the appropriate two physical ends of the trunk when required. Confirm built-in terminations and cable characteristic impedance before adding external parts.
Can MQTT QoS 1 save readings during an Internet outage?
Not alone. A durable local database or supported gateway queue must store readings; QoS 1 can then help deliver them when connectivity returns. The cloud must handle duplicate deliveries.
Why does the tablet still show a temperature after a sensor goes offline?
Most systems retain the last value. That is fine for history, but it must be labeled stale with a timestamp and fault indicator so an operator cannot mistake it for a live reading.
Can the system automatically switch on a machine or trigger an emergency shutdown?
Only through separately engineered, approved and validated controls suitable for the actual hazard. A generic IoT dashboard is not a substitute for a safety instrumented or safety-rated function.
Primary references
- Modbus Organization — specifications and serial implementation guides (serial topology, RTU network implementation).
- Modbus Organization — introduction and function codes (register reading and address conventions).
- OASIS — MQTT Version 5.0 standard (QoS and session semantics).
- NIST SP 800-82 Rev. 3 — Guide to Operational Technology Security (network/security architecture, September 2023 final).