Local control over BLE: get_modbus_specs
:::note Status
Server side implemented and unit-tested (2026-10-08): the
get_modbus_specs request, its replies, the detection rules and the
decoder test vectors. Not yet verified on hardware: whether the WFBLE
logger forwards raw Modbus RTU frames over BLE has not been bench-tested
yet (see Bench checklist). The mobile side is not
built yet; this page is its specification.
:::
Building the app side? Follow the Flutter implementation guide. It has the build order, Dart code and a release checklist. This page is the contract it implements.
Local control lets the mobile app read and write an inverter directly over the logger's BLE link, with no backend involved. It works for any inverter, whether or not it is registered in our database, and with no internet at the site.
The backend's only role is to hand the app the Modbus profiles and the rules for picking the right one, while the app is online. Everything after that happens on the phone.
Nothing done over BLE reaches the backend at the time. There is no
ownership check, and the cloud learns of a changed setting only the next time
tcpserver reads that register. This is deliberate; see
What is not covered. To get BLE writes into the
Activity Trail, cache each one in the app and upload the cache later with
sync_ble_activity.
1. Fetching the profiles
Send:
{"type": "get_modbus_specs"}
No deviceKey, userId or login is needed. The profiles are vendor protocol
documents, not user data.
The gateway answers with one modbus_spec per profile, in model order,
then one modbus_detection, always last:
{"type":"modbus_spec","ok":true,"index":1,"total":3,
"model":"Nexus","sha256":"9f2c…","unchanged":false,
"modbusCapable":true,"detectable":true,
"requiredFeatures":["bit_field","datetime","scale_rule","variant_selector"],
"spec":{ … }}
{"type":"modbus_spec","ok":true,"index":2,"total":3,"model":"Yorker", … }
{"type":"modbus_spec","ok":true,"index":3,"total":3,"model":"IP20 3K6/5K",
"publicModel":"Yorker","modbusCapable":false,"detectable":false, … }
{"type":"modbus_detection","ok":true,"sha256":"41d0…","detection":{ … }}
| Field | Meaning |
|---|---|
index, total | 1-based position. If an index is missing (a message was dropped because the connection was busy), send the request again. |
sha256 | Hex SHA-256 of the exact spec bytes. Use it as the cache key and send it back in have. |
unchanged | true when you already hold this sha256; spec is then absent. |
modbusCapable | false for IP20 3K6/5K: it speaks a proprietary ASCII command protocol, not Modbus. Its spec is the server's raw profile ("transport": "ascii", registers named by text query and reply field, synthetic addresses that never go on the wire, no function codes), sent for completeness; it cannot be used over BLE. Its devices are shown as "Yorker" everywhere else (publicModel); model here stays the profile key, which have is keyed by. The cloud serves this model normally (see IP20 3K6/5K). |
detectable | Whether modbus_detection has rules for this profile. Only detectable profiles can be used. |
requiredFeatures | Interpreter features the profile needs (see Required features). Refuse a profile that needs one your app does not implement. |
ratedPowersKw | The nameplate ratings, in kW, that update_device's ratedPowerKw accepts for this model: the choices for a rating picker. Absent for a model that reports its own rating (Nexus). Present on unchanged replies too. See Setting the rated power. |
spec | The profile itself (see The profile). |
On failure, including a malformed request (for example have that is not an
object), there is a single {"type":"modbus_spec","ok":false,"error":"…"}.
Keep using whatever you already cached.
Skipping unchanged profiles
Send the hashes you hold, keyed by model:
{"type":"get_modbus_specs",
"have":{"Nexus":"9f2c…","Yorker":"77ab…"}}
A profile whose hash matches comes back with unchanged: true and no body.
index, total, requiredFeatures and the flags are still present. The
detection rules are always sent in full (about 1 KB). At most 32 have
entries are accepted.
Sizes
Measured on the current profiles: about 680 KB of JSON in total, about
66 KB on the wire with permessage-deflate, which the gateway negotiates
automatically. A request where nothing changed is about 2 KB.
Caching
- Cache everything as soon as it arrives: all profiles and the detection rules. Don't wait for a successful detection. Local control matters most when there is no internet, so the app must already have the profiles when it reaches the site.
- Refresh on every app start while online, with
have. - Ship a built-in copy. Bundle the replies of a
get_modbus_specscall made at app build time, with their hashes, and use them only until the first successful download. Without this, a fresh install at a site with no internet cannot do local control at all. Always prefer a downloaded copy over the built-in one.
2. The profile
spec is the profile exactly as tcpserver parsed it from
server/internal/modbus/specs/*.json, with snake_case keys as in those
files. It is not the raw file: anything the server does not parse is absent
here too, and these fields are normalised.
| Field | Use |
|---|---|
registers[] | Every register: address, name, data_type, length, scale, scale_rule, unit, access, category, sheet, variant, low_limit/high_limit, notes. |
registers[].data_type | Canonical: uint16, int16, uint32, int32, ascii or datetime. The vendor spellings (U16, S16, missing, …) are mapped exactly as the server decodes them. A missing type is decoded as uint16. |
registers[].read_function_code | The function code to read with (3 or 4). Present on every register the server can read. Absent on write-only registers. |
registers[].write_function_code | The function code to write with (6 or 16). Present on every writable register (access W or RW). |
registers[].function_code | The vendor's original value. Don't use it. Use the two fields above. |
telemetry_registers | Indexes into registers of what tcpserver polls every cycle. Apply the device's variant on top. |
variant_selector | Where the hardware variant is read from (Aotai: register 87). See Variants. |
batch_within_sheet | A read must stay inside one sheet (IP20). See Reading. |
alerts[], alarm_scan_registers | The alert catalog and the registers to read for it. See Alerts. |
display_variant_selector | Which screen variant prints alert codes differently (IP20 6KU). |
identity_register | Name of the serial-number register. |
connection | The vendor's notes. The slave address is in the detection rules. |
3. Detecting the right profile
The app tries the detectable profiles one by one against the inverter, and
uses one only when it is certain. The rules come in modbus_detection:
{"algorithmVersion": 1,
"read": {"responseTimeoutMs": 5000, "retries": 2, "ignoreLinesWithPrefix": "AT+"},
"models": [
{"model": "Nexus", "slaveAddress": 1,
"confirm": [
{"check":"plausible_value","register":"dc_voltage_1","address":0,"quantity":1,
"functionCode":3,"dataType":"uint16","scale":0.1,"min":0,"max":1500},
{"check":"serial_text","register":"sn","address":1380,"quantity":10,
"functionCode":3,"dataType":"ascii","minLength":8}],
"variant":
{"check":"variant","register":"device_parameter_display_selection","address":87,"quantity":1,
"functionCode":3,"dataType":"uint16","bit":13,"width":3,"values":{"0":"1ph","1":"3ph"}}},
{"model": "Yorker", "slaveAddress": 1,
"confirm": [
{"check":"plausible_value","register":"protocol_version_high_word","address":16,"quantity":1,
"functionCode":3,"dataType":"uint16","scale":1},
{"check":"serial_text","register":"serial_number_sn_code","address":0,"quantity":10,
"functionCode":3,"dataType":"ascii","minLength":8}]}
]}
Every check spells out its read in full (address, quantity, function code,
type), so the app does not need to look anything up by name. If
algorithmVersion is higher than the version your app implements, don't
detect. Ask the user to update the app.
The check kinds (algorithm version 1)
check | Read | Passes when |
|---|---|---|
plausible_value | quantity registers at address | The device answers with data, and raw × scale (decoded as dataType) is within [min, max]. With no min/max, any answer passes. |
serial_text | The serial register | It decodes as text (see Text) to at least minLength characters. |
variant | The variant register | Not pass/fail. Run it after confirmation: (raw >> bit) & (2^width − 1) looked up in values. A value missing from values means unknown variant. |
The procedure (algorithm version 1)
-
Try every model in
models, in order. For each, run itsconfirmchecks in order:- every check passes: the model is confirmed;
- a check fails on a real answer (data that fails the check, or a Modbus exception): the model is rejected, move to the next;
- a read gets no valid reply after
retriesretries: the model is unanswered, move to the next.
Don't stop at the first confirmed model. Try them all.
-
Decide:
Result Do Exactly one confirmed, none unanswered ✅ Use it. Read its variant, if it has one.Any model unanswered ❌ Fail and retry detection. Never pick a model while one went unheard. Two or more confirmed ❌ Fail as "ambiguous". Report it; the rules need a stronger check. None confirmed, all answered ❌ Fail as "unsupported inverter". -
Never operate on an unconfirmed profile. Local control can write to the inverter.
The "unanswered" rule exists because the server learned it the hard way. On 2026-09-26 and 2026-10-02 an Aotai's first read was lost on a flaky link, the next candidate's probe passed, and the Aotai was decoded as an IP20.
Why the serial is the real proof. The probe alone cannot tell the models
apart: an idle Aotai passes the IP20 probe, and the reverse is also true.
Read under the wrong profile, the serial register returns a Modbus exception
or bytes that are not text. minLength: 8 is stricter than the server: a
wrong read can decode to one or two printable characters by chance (41 00
is "A"). Both serials seen on real hardware are much longer (Aotai 12
characters, IP20 17).
Remembering the result
After detection, store on the phone:
inverter serial → { model, spec sha256, variant }.
On the next connection, read the serial with the remembered profile first.
If it decodes to the same serial, use it straight away. Otherwise run full
detection: it's a different inverter, or the logger was moved. Do the same
when the remembered profile's sha256 has changed since.
4. Talking Modbus over BLE
Each request is a Modbus RTU frame, written to the logger's BLE write characteristic:
read: [slave][fn 03/04][addr hi][addr lo][qty hi][qty lo][crc lo][crc hi]
reply: [slave][fn][byte count = 2×qty][data …][crc lo][crc hi]
error: [slave][fn | 0x80][exception code][crc lo][crc hi]
- CRC: CRC-16/MODBUS (initial value
0xFFFF, reflected polynomial0xA001), sent low byte first.01 03 00 00 00 01→84 0A. - Reassemble the reply. BLE notifications carry about 20 bytes each by
default, so a 25-byte reply arrives in pieces. Collect bytes until you have
5 + byte count(or 5 for an exception), then check the CRC, slave and function code. - Drop text lines. The logger mixes its own
AT+…lines into the stream (a strayAT+TBT:R001was seen in production). Discard anything starting withignoreLinesWithPrefixup to its line end before parsing. - Timeout and retry. Wait
responseTimeoutMs. Before retrying, discard anything that arrives late, or it will be taken as the next read's answer. - One request at a time. Modbus RTU has no request IDs.
- Slave address:
slaveAddressfrom the detection rules (1). The Aotai's address can be changed in its settings (register 1344), so allow an advanced override.
5. Interpreting the profile
These are the rules tcpserver follows. The
decoder test vectors check an implementation against
the server's own output.
Numbers
Big-endian, two bytes per register. uint32/int32 span two registers, high
word first. Value = raw × scale (a scale of 0 means 1). Compare decoded
floats with a small tolerance.
Text
ascii: two characters per register, high byte first. Stop at the first
byte outside 0x20–0x7E, then trim spaces. If nothing printable is left,
it's an error, never an empty string.
Date/time
datetime, three registers, one byte per field: year − 2000, month, day,
hour, minute, second. All zero means "never set". This is the inverter's own
clock, with no time zone.
Scale rules
A register with scale_rule has a scale chosen by one bit of another register:
"scale_rule": {"register": 90, "bit": 1, "scale_if_clear": 0.001, "scale_if_set": 0.01}
Read the selector register (as a plain uint16, function 3) before
decoding. If it could not be read:
- for display, decode with
scale_if_clear(the server does the same) and flag the value; - for a write, refuse. The wrong scale writes a value 10× off.
Bit fields
A register with bit (one bit) or bits (an inclusive [low, high] range)
is a field inside a 16-bit word shared with other settings. Aotai has five:
1063 bits 0, 1, 7 and 12–14, and 1138 bit 2.
- Decode:
(raw >> low) & ((1 << width) - 1), wherelowisbitorbits[0]andwidthis 1 orbits[1] - bits[0] + 1. - Write: read the register (function 3), clear the field's bits, OR in
value << low, and write the whole word back. The vendor requires the other bits to be written back as read. Never write the field value as the whole word:lvrt_enable = 1sent as0x0001sets bit 0 instead of bit 1 and clears every other setting in 1063. - If the read fails, refuse the write. Refuse a value that isn't a whole
number in
0..2^width - 1.
Variants
Aotai documents single-phase and three-phase rows side by side. Some addresses mean different things on each.
- Variant known: keep rows whose
variantis empty or equals it. - Variant unknown (undefined value, or not read yet): keep rows with no
variant, plus variant rows whosenameexists for only one variant. Drop any name that two variants define differently until the variant is known.
Reading
- What to poll:
telemetry_registers, after the variant filter. - Batch neighbouring addresses into one read, at most 125 registers. Some devices cap lower: if a large read fails, retry it in smaller pieces.
- If
batch_within_sheetis true (IP20), never let one read span twosheets. The IP20 rejects that with exception04even when each address is fine alone. - If a read is refused with an exception, split it in half and retry each half, down to single registers. Both inverters refuse a whole read when any address in it is not readable, including an undocumented gap. Only a register refused on its own is really unreadable.
- Read with
read_function_code.
Looking registers up by name
Names repeat (Aotai documents some settings on two sheets, with
contradictory value meanings). When showing or writing a setting by name,
pick the row whose access contains R (RW) over a write-only row, which
is the same rule the server's write uses. Prefer addressing by
address + variant where you can.
Writing
- Pick the writable row (see above) and resolve its scale.
- Check the value against
low_limit/high_limitwhen they give a numeric range. - Encode:
round(value ÷ scale), asuint16orint16. Refuse if it is out of range for the type (never let it wrap), and refuse multi-register (length> 1) writes. The server supports neither. For a row withbit/bits, merge into the register's current value instead (see Bit fields). - Send with
write_function_code(6 = write single register, 16 = write multiple registers). - Read it back to confirm.
switch_on_and_off_enable (Aotai, register 1056) physically switches the
inverter off when written 0.
Alerts
To show alarms offline, read alarm_scan_registers each scan and evaluate
alerts[]:
modbus_bit: active when bitbitof registerregisteris set.state: active when(value & state_mask) == state_equals, or!= state_not_equals.state_maskdefaults to0xFFFF.only_when: evaluate only while registeronly_when.registerholds one ofonly_when.in. Otherwise leave the alert's state as it is.- Hysteresis: raise after
raise_afterconsecutive active scans (default 1 forcritical, 2 otherwise), clear afterclear_after(default 2). The server scans every 30 s; keep a similar cadence or the counts mean something else.
Required features
A profile lists, in requiredFeatures, everything beyond plain decoding it
needs. Implement all of these, and refuse a profile that names one you
don't know: skipping a scale_rule shows values 10× off that still look
reasonable.
| Feature | Section |
|---|---|
scale_rule | Scale rules |
bit_field | Bit fields |
variant_selector | Variants |
batch_within_sheet | Reading |
datetime | Date/time |
alert_gate | only_when in Alerts |
display_variant_selector | Per-screen alert codes (display_code_variants) |
Decoder test vectors
local-control-vectors.json holds raw bytes
and the value the server's decoder produces for them. It covers every data
type, text termination, date/time, scale rules (both bit states), variant
decoding, write encoding (including refusals), bit-field decoding and
merging (encode_bit_field: rawHex is the word as read, expect.rawHex
the word to write) and alert conditions. Run them
in the app's unit tests: an interpreter that passes all of them decodes like
the server.
They are generated by server/internal/modbus/local_control_vectors_test.go.
The source of truth is server/internal/modbus/testdata/local-control-vectors.json
in cse_tcp_be; this copy is refreshed whenever that file changes.
Bench checklist
Before relying on local control, check on real hardware:
- BLE pass-through. With nRF Connect, enable notifications and send
01030564000A84DE(Aotai serial). Expect01 03 14 …, which decodes to the inverter's serial. For the IP20, send01030000000AC5CD: the server reads the IP20 serial at address 0 (WF_Version), not the second copy at 4128. - Wrong-profile reads. Read the Aotai serial address on an IP20 and the reverse. Expect an exception or non-text. This is what makes detection reliable.
- Cloud collision. While the logger is also connected to
tcpserver, repeat reads and watch for timeouts. Both share the inverter's single RS-485 line. - Identity registers. Read Aotai
model_code(32) and IP20protocol_id_code_b(57). If they hold stable, model-specific values, they can become an additional detection check in a later algorithm version.
Keeping the server and phone in step
The detection rules are not maintained by hand. ws-gateway builds them at
startup from the same functions tcpserver uses: the probe register
(Profile.ProbeRegister), the plausibility ranges (modbus.PlausibleRange),
the serial register (Profile.SerialRegister) and the variant selector. A
change to a profile reaches phones on their next refresh, with no release.
A change to the procedure (a new check kind, a changed outcome rule) must
bump modbus.DetectionAlgorithmVersion and update this page.
TestDetectionCheckKindsPinned fails if a new check kind appears without a
bump. A new feature name is a breaking change for apps, and needs an app
release before a profile may require it.
What is not covered
- No access control or audit on BLE. Anyone with the app within BLE range of a logger can read and write that inverter. Nothing is checked or logged by the backend, by design. Whatever protection exists is the logger's own BLE pairing.
- The cloud is not told at the time. A setting changed over BLE shows up
in the cloud only when
tcpservernext reads it. It appears in the Activity Trail (withchannel: "ble") only once the app uploads it withsync_ble_activity, and only as the app's own claim. - BLE pass-through is unverified (see Bench checklist).
- IP20 3K6/5K cannot be used over BLE: its protocol is not Modbus. Control it through the cloud (
write) instead. model_codes(Aotai's model code table) is not parsed by the server, so it is not in the profile and not used for detection yet.minLength: 8for the serial is a judgement from two known serials. Lower it only if a real inverter's serial is shorter.
Cost
The replies are prebuilt at gateway startup; a request costs no database or device work. A full download is about 66 KB compressed and an unchanged refresh about 2 KB. A million phones re-downloading after a profile change is about 66 GB of data transfer out, roughly $6 at $0.09/GB.