driver: Bituo SPM01R (SPM01R FLEX) single-phase Modbus energy meter

Open
#601 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
nodejs, typescript
Domain
embedded-iot

Research direction

Start from packages/driver-ex9em and packages/driver-or-we-516, plus docs/NEW-PACKAGE.md, to copy the package layout and see how readFloatBE decoding and DEFAULT_CONFIG/SUPPORTED_CONFIG are done. Create packages/driver-spm01r with src/index.ts and src/index.test.ts, write the mocked-transport tests first, and register the package in the root jest.config.js and tsconfig.json. Done when npm test, lint, typecheck and build pass with at least 95% coverage, and the register map is confirmed on real hardware.

Written by the indexing model from the issue text.

Description

question type:feature

Device information

  • Manufacturer: Bituo Technik
  • Model: SPM01R FLEX, order code SPM01-D2M1 (the shop used to call it SPM01/M1). The same user guide also covers the 3-phase SPM02R, which is out of scope here; it could be added later as a second device in the same package.
  • Device type: energy meter, 1 phase + N, 63 A, built-in current sensor (the live wire passes through a hole in the housing). RS-485 is 4 kV isolated. It is powered from its own L and N cables (220-240 VAC, at most 2 VA).
  • Price (for reference): USD 42.25 in the maker's shop, seen 2026-10-14: https://shop.bituo-technik.com/products/spm01-flex-miniature-energy-meter

Register documentation

Function codes 03 (read holding) and 04 (read input) both return the same data. Float32 is big-endian (ABCD), 2 registers each. Addresses are as printed in the guide.

Data points to implement (single-frame block, registers 20000-20023, readable in one request of 24 registers):

Register Hex Type Size Encoding Description Unit in guide Scale / driver output Suggested data point id
20000 0x4E20 input/holding 2 float32be Voltage V x1, V voltage
20002 0x4E22 input/holding 2 float32be Current A x1, A current
20004 0x4E24 input/holding 2 float32be Active power kW x1000, W active_power
20006 0x4E26 input/holding 2 float32be Power factor none x1 power_factor
20008 0x4E28 input/holding 2 float32be Frequency Hz x1, Hz frequency
20010 0x4E2A input/holding 2 float32be Import active energy (can be reset) kWh x1, kWh import_active_energy
20012 0x4E2C input/holding 2 float32be Export active energy (can be reset) kWh x1, kWh export_active_energy
20014 0x4E2E input/holding 2 float32be Total (absolute) active energy kWh x1, kWh total_active_energy
20016 0x4E30 input/holding 2 float32be Import active energy, non-resettable kWh x1, kWh total_import_active_energy
20018 0x4E32 input/holding 2 float32be Export active energy, non-resettable kWh x1, kWh total_export_active_energy
20020 0x4E34 input/holding 2 float32be Total active energy, non-resettable kWh x1, kWh total_active_energy_nonresettable
20022 0x4E36 input/holding 2 float32be Apparent power kVA x1000, VA apparent_power

Names follow driver-ex9em (voltage, current, active_power, apparent_power, power_factor, frequency). The energy names are only a suggestion; choose what is consistent with the other energy-meter drivers.

Settings registers (read/write, FC 03/04 read, 06/10 write), mark these pollType: 'on-demand':

Register Hex Type Description Values
6000 0x1770 uint16 Modbus address 1-247 (default 247)
6001 0x1771 uint16 Baud rate 0=9600, 1=2400, 2=4800, 3=9600 (default), 4=19200, 5=38400 (the guide lists 0 and 3 both as 9600; check on the device)
6002 0x1772 uint16 Parity and stop bits 0=N81 (default), 1=E81, 2=O81, 3=N82

Other registers in the guide (not data points, optional):

  • Product identification, UTF-8 strings: 100 meter type ("SPM01" or "SPM02"), 120 product ID, 125 serial number, 130 hardware version, 135 firmware version. Meter type could be used for auto-detection.
  • 10000 (0x2710), FC 06, write 0x5055: blinks the LED for 15 s, to find the device in a panel.
  • 10001 (0x2711), FC 06, write 0x51AA: resets the resettable energy counters. Do not expose as a normal writable data point.
  • 30000 (0x7530), FC 10, broadcast address 0, write 0x55AA + new address (1-246): only the meter whose reset button is currently pressed accepts it. Probably out of scope.
  • A full per-register table also exists at 1000-1076 (same values as float32, laid out for the 3-phase SPM02R; SPM01R fills only phase A, frequency and energy: V 1000, A 1006, W 1012, VA 1024, PF 1030, Hz 1052, import 1054, export 1056, absolute 1058). The single-frame block above is simpler and is marked "SPM01R only" in the guide.

Device defaults

  • Default slave ID: 247
  • Default baud rate: 9600
  • Default parity: none
  • Default stop bits: 1 (8 data bits)
  • A press of 5 seconds on the reset button restores address, baud rate and format to these defaults.

Device limitations

  • Maximum registers per read request: not stated. The single-frame block is 24 registers, which the maker designed to be read in one request.
  • Forbidden/reserved register ranges: none stated. Registers 10001 (energy reset) and 30000 (broadcast address) are write-only commands; never read them in a poll.
  • Required delays between requests: not stated.
  • Other quirks:
    • The guide prints active and apparent power in kW / kVA. Confirm the scale on a real device with a known load before release (a 100 W load should read 0.1).
    • The minimum current for correct reading is not stated for this model (the Zigbee sibling is quoted at 50 mA start current). The characterisation run should include a low load (below 0.5 A).
    • Measures energy in both directions; "forward" is the direction of the arrow printed on the housing.

Device profile (recommended)

A device profile from real hardware is not available yet. The household plans to buy one unit; a profile will be attached then (ya-modbus-profile). Until then the driver is written from the vendor's register list and should say so in the README.

  • Device profile attached

Additional context

Use case: measuring the real power draw of a small server and its network switch on a UPS output, then feeding it to MQTT through ya-modbus-bridge. The household's existing homy stack currently reads its meters with its own modbus-serial driver files; it will use this driver if it has moved to ya-modbus by the time the meter is installed.

Notes from earlier tests of other drivers with the bridge, that apply here as well:

  • The bridge polls every data point, including pollType: 'on-demand' ones, and one failed read drops the whole poll (#599). So only list registers that are verified on hardware; an unverified register can silence the whole device (#598).
  • Use Node 22 for serial work (#507).

Layout and approach (follows the existing drivers, e.g. packages/driver-or-we-516 and packages/driver-ex9em)

  • New package packages/driver-spm01r, npm name @ya-modbus/driver-spm01r (lowercase letters, digits and hyphens only; the bridge rejects other names).
  • Files, copied from packages/driver-ex9em (single-phase meter, README.md, docs/, jest.config.cjs, tsconfig.*.json, package.json; start from docs/NEW-PACKAGE.md) and packages/driver-or-we-516 (float32 reading with readFloatBE, AGENTS.md/CLAUDE.md):
    • src/index.ts exports createDriver, DEFAULT_CONFIG (247, 9600, none, 8, 1) and SUPPORTED_CONFIG (baud rates 2400, 4800, 9600, 19200, 38400; parity none/even/odd; address 1-247).
    • src/index.test.ts next to it, with a mocked Transport.
    • package.json with keywords including ya-modbus-driver, engines field, repository directory set to the new package.
    • README.md with device info, defaults, usage and the data point table, and the note that the register list comes from the vendor and was (or was not yet) confirmed on hardware.
  • Read the 24-register block with one transport.readHoldingRegisters(20000, 24) call (or input registers; both work) and decode all configured data points from the same buffer in readDataPoints, as driver-or-we-516 does.
  • Output power in W and VA (the register values times 1000). Use V, A, W, VA, Hz, kWh units.
  • Register the package in the root jest.config.js (projects) and root tsconfig.json (references), as the other drivers are.

Done when

  • packages/driver-spm01r exists with the layout above, createDriver, DEFAULT_CONFIG and SUPPORTED_CONFIG.
  • Tests are written first with a mocked transport and cover: every data point decode (float32 big-endian fixtures, including the kW to W and kVA to VA scale), the single 24-register read in readDataPoints, unknown data point errors, read-only errors, writes of address, baud rate and parity (valid and invalid values), and a cross-check that DEFAULT_CONFIG is inside SUPPORTED_CONFIG.
  • Coverage is at least 95 % on all metrics, as docs/NEW-PACKAGE.md requires.
  • The package is added to the root jest.config.js and tsconfig.json; npm test from the root runs it.
  • npm run build, npm run lint, npm run typecheck, npm run validate:packages and npm run validate:dist-imports pass.
  • README.md in the package is written; the driver is listed in the root README next to the other drivers.
  • Config registers (address, baud rate, parity) are pollType: 'on-demand'; the reset-energy and broadcast-address registers are not exposed as normal data points.
  • A real-device check is done with npx ya-modbus read (and ya-modbus-profile if possible): values compared with a known load, the kW/kVA scale confirmed, and the result noted on this issue. The README then says the driver is hardware-verified.
  • If the emulator is used by other drivers' tests, an emulator-based test with the SPM01R register map is added too (@ya-modbus/emulator); if not, mocked-transport tests are enough.
  • The first release goes out through the normal release process (conventional commit feat(driver-spm01r): ..., trusted-publisher setup per docs/NEW-PACKAGE.md).
Dominant language
TypeScript
Stars
3
Forks
0
Avg merge
13h 46m
Merged PRs (30d)
58

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from groupsky/ya-modbus

All issues in groupsky/ya-modbus

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.