V1.13 (2026-01-28)
A command-line utility for communicating with R4DCB08 temperature sensor modules via serial port.
This utility allows you to:
- Read temperature data from up to 8 channels in real-time
- Configure device settings (address, baudrate)
- Read and set temperature correction values
- Monitor temperature with configurable intervals
- C compiler (GCC/Clang)
- Make utility
- Serial port support (Linux/Unix-based systems)
makesudo make install # Installs to /usr/local/bin
sudo make uninstall # Removes from /usr/local/bin- Connect the R4DCB08 module to your computer via USB-RS485 adapter
- Run the utility:
./r4dcb08Example output (reading 4 channels every 2 seconds):
$ ./r4dcb08 -n 4 -t 2
# Date Ch1 Ch2 Ch3 Ch4
2026-01-21 14:30:15.42 22.5 23.1 21.8 22.0
2026-01-21 14:30:17.42 22.6 23.0 21.9 22.1
2026-01-21 14:30:19.42 22.5 23.1 21.8 22.0
^C
Received SIGINT (Ctrl+C), measurement stopped
Output format: timestamp Ch1 Ch2 Ch3 ... - channels are printed in order from 1 to n, separated by spaces.
Press Ctrl+C to stop continuous measurements.
- Read temperature from channel 1 (default):
./r4dcb08- Read 4 channels every 2 seconds:
./r4dcb08 -n 4 -t 2- Single measurement without timestamp (useful for scripts):
./r4dcb08 -n 4 -f
# Output: 22.5 23.1 21.8 22.0- Use different serial port:
./r4dcb08 -p /dev/ttyUSB1- Enable median filter (smooths out noise/spikes):
./r4dcb08 -m- Enable MAF filter (moving average with trapezoidal weights):
./r4dcb08 -M 5- Combine filters (median → MAF pipeline):
./r4dcb08 -m -M 5 -n 4 -t 2The utility provides two digital filters that can be used separately or combined:
Median Filter (-m)
- Three-point median filter
- Removes isolated spikes while preserving signal edges
- Introduces 1 sample delay
MAF Filter (-M n)
- Moving Average Filter with trapezoidal weights
- Window size
nmust be odd (3, 5, 7, ... 15) - Weights:
[0.5, 1, 1, ..., 1, 0.5] - Formula:
MAF = (0.5·x[0] + x[1] + ... + x[n-2] + 0.5·x[n-1]) / (n-1) - Smooths high-frequency noise while reducing edge distortion compared to simple moving average
Filter Workflow
When both filters are enabled, data flows through the pipeline:
Raw data → Median Filter → MAF Filter → Output
Example with 4 channels, 2-second interval, median + MAF(5):
$ ./r4dcb08 -m -M 5 -n 4 -t 2
# Active three-point median filter for all data ...
# Active MAF filter (window size 5) for all data ...
#
# Date Ch1 Ch2 Ch3 Ch4
2026-01-28 10:15:03.12 22.5 23.1 21.8 22.0
2026-01-28 10:15:05.12 22.5 23.0 21.9 22.0
2026-01-28 10:15:07.12 22.5 23.1 21.8 22.0
^C
Received SIGINT (Ctrl+C), measurement stopped- Read current temperature correction values:
./r4dcb08 -c- Set temperature correction for channel 3 to +1.5°C:
./r4dcb08 -s 3,1.5Temperature correction is useful when sensor readings need calibration (e.g., sensor shows 21.0°C but actual temperature is 22.5°C → set correction to +1.5).
- Change device address from 1 to 5:
./r4dcb08 -a 1 -w 5Note: -a 1 specifies current address, -w 5 sets new address.
- Change device baudrate to 19200:
./r4dcb08 -x 4Baudrate codes: 0=1200, 1=2400, 2=4800, 3=9600, 4=19200. Change takes effect after device power cycle.
- Factory reset:
./r4dcb08 -rWrites factory defaults to EEPROM (address 1, baudrate 9600, all corrections 0). Power cycle needed to apply.
- Scan RS485 bus for devices:
./r4dcb08 -SScans addresses 1-254 and reports all responding devices. Useful for discovering device addresses on the bus.
Example output:
Found 2 device(s):
1
15
| Option | Description | Default |
|---|---|---|
-p [port] |
Serial port device | /dev/ttyUSB0 |
-a [1-254] |
Device address (for multi-device setups) | 1 |
-b [baud] |
Serial port baudrate {1200, 2400, 4800, 9600, 19200} | 9600 |
-t [seconds] |
Interval between measurements | 1 |
-n [1-8] |
Number of channels to read | 1 |
-c |
Read temperature correction values | - |
-w [1-254] |
Write new device address | - |
-x [0-4] |
Write device baudrate (0=1200, 1=2400, 2=4800, 3=9600, 4=19200) | - |
-s [ch,value] |
Set temperature correction for channel (e.g., -s 3,1.5) |
- |
-m |
Enable three-point median filter (reduces noise) | Off |
-M [3-15] |
Enable MAF filter with window size (must be odd) | Off |
-f |
One-shot measurement without timestamp | Off |
-r |
Factory reset (resets to address 1, baudrate 9600, corrections 0) | - |
-S |
Scan RS485 bus for devices (addresses 1-254) | - |
-h or -? |
Display help | - |
-bsets baudrate for this session (how fast your computer talks to the device)-xchanges baudrate stored in the device (permanent, survives power cycle)
Normally you only need -b if default 9600 doesn't work. Use -x only when you want to permanently change device speed.
- Temperature readings are in degrees Celsius
- Valid range: -55.0°C to 125.0°C (values outside show as
NaN) - Press Ctrl+C to stop continuous measurements
- Multiple devices can share one RS485 bus using different addresses
For continuous monitoring and integration with home automation systems, there's a separate MQTT daemon that publishes temperature readings to an MQTT broker.
Features:
- Publishes temperatures to MQTT broker (Mosquitto, etc.)
- TLS/SSL support
- Runs as systemd service or standalone
- Auto-reconnect, LWT for offline detection
- Works on systems without systemd (Alpine, FreeBSD)
Quick example:
cd mqtt_daemon
make
./r4dcb08-mqtt -p /dev/ttyUSB0 -H mqtt.local -vSee mqtt_daemon/README.md for full documentation.
- Added MAF (Moving Average Filter) with trapezoidal weights (-M option)
- Window size configurable (odd values 3-15)
- Filters can be chained: median → MAF
- Minor code improvements
- Added RS485 bus scan feature (-S option)
- Scans addresses 1-254 with 100ms timeout per address
- Reports all responding Modbus RTU devices
- Added factory reset command (-r option)
- Resets device to address 1, baudrate 9600, all corrections 0
- Replaced deprecated signal() with POSIX sigaction()
- Removed unsafe printf() from signal handler
- Added NULL check after now() call
- Replaced usleep() with POSIX nanosleep()
- Fixed type punning using portable bitwise operations
- Added exclusive file locking (flock) for serial port
- Improved reliability in multi-process environments
- Unified error handling system
- Centralized constants
- Fixed resource leak in port initialization
- Fixed baud rate table bug (1200 baud)
- Code cleanup and optimization
- Implemented AppStatus error codes
- Modularized configuration
- Improved signal handling
- Added median filter
- Enhanced input validation
This section is for developers and advanced users.
Modbus RTU over serial port:
- Function 0x03: Read holding registers
- Function 0x06: Write single register
| Register | Description | R/W | Values |
|---|---|---|---|
| 0x0000-0x0007 | Temperature readings (channels 1-8) | R | signed int16 / 10 |
| 0x0008-0x000F | Temperature correction values | R/W | signed int16 / 10 |
| 0x00FD | Automatic report interval | R/W | 0-255 (seconds, 0=disabled) |
| 0x00FE | Device address | R/W | 1-254 |
| 0x00FF | Baudrate setting | R/W | 0-4 (see codes below) |
| 0x00FF | Factory reset | W | 5 (triggers reset) |
Baudrate codes: 0=1200, 1=2400, 2=4800, 3=9600, 4=19200
Factory reset: Writing value 5 to register 0x00FF writes default values to EEPROM (address=1, baudrate=9600, corrections=0). Power cycle needed to load new settings from EEPROM.
- 0: Success
- -10 to -19: Argument errors
- -20 to -29: Communication errors
- -30 to -39: Operation errors