Skip to main content

Writing to a device

Send {"type":"write","deviceKey":"...","register":"switch_on_and_off_enable","value":1,"userId":"17833b2e-a851-4a17-a764-62524d667959"} to change a register on a live device (turn it on/off, change a charge setting, etc.) — you get exactly one write_result back:

// success
{"type": "write_result", "deviceKey": "7c9e6679-7425-40de-944b-e07fc1f90ae7", "register": "switch_on_and_off_enable", "ok": true, "value": 1, "readBack": 1, "applied": true}

// acknowledged, but the inverter kept its old value (out-of-range setpoint)
{"type": "write_result", "deviceKey": "7c9e6679-7425-40de-944b-e07fc1f90ae7", "register": "dual_output_cutoff_voltage", "ok": true, "value": 40, "readBack": 48, "applied": false}

// failure (bad register, wrong owner, device offline, timeout, ...)
{"type": "write_result", "deviceKey": "7c9e6679-7425-40de-944b-e07fc1f90ae7", "register": "switch_on_and_off_enable", "ok": false, "error": "not authorized to control this device", "value": 1}

register must match a register's name field exactly, from that device model's protocol spec (see the per-model register reference pages, e.g. Nexus) — and that register must be marked writable (access: "W" or access: "RW") in that spec. A single-register write (the register's own length is 1) is sent as Modbus function code 6 or function code 16 with quantity=1, whichever that register's spec documents; the server picks the right one per register automatically, so this isn't something a client needs to know or specify. (On the Nexus, for example, a time-slot setting such as end_time_1 is written as its whole six-register slot in one function-16 frame: the server reads the slot, replaces the one value and writes it back, because the inverter ignores a single-register write there. The slot read costs one extra round trip, and if it fails nothing is sent. Pending live confirmation after the next deploy; see Nexus.) The one multi-register write supported is a datetime setting, the Aotai clock set_rtc_time (see Setting the inverter clock). Any other multi-register write target (length > 1) is always rejected, because there's no documented byte/word-packing scheme to encode it correctly — each protocol reference page's own "Write via WebSocket" section lists exactly which registers qualify for that model. See Nexus for an example — link to the page, not a fragment into that specific section: its heading text (and therefore its auto-generated anchor) embeds a live writable-register count that changes whenever the register data is regenerated, so a fragment link into it goes stale easily.

IP20 3K6/5K (since 2026-11-23) is not Modbus: a write is sent as one text command (TCCV28.2 for 28.2 V), answered ACK or NAK, then read back with the setting's query. The value must fit the command's format exactly (0.1 V steps for a voltage point, whole numbers elsewhere), or the write is refused before anything is sent. A NAK comes back as ok: false ("the inverter refused … (NAK)"): the value is outside what the inverter accepts, or the setting cannot be changed in its current mode (output_frequency and restore_factory_defaults only in standby or AC mode). power_switch (1 on, 0 off) carries no applied, since its read-back cannot confirm it. Custom commands are refused for this model. Its telemetry cycle is about 9 s of one-by-one queries, so a write that arrives mid-cycle is run between two queries rather than after the cycle, and waits at most about half a second. See IP20 3K6/5K.

value is in engineering units — the same units read_registers, readBack and the catalog's value report (e.g. 56.4 for 56.4 V). The server divides it by the register's scale and rounds to the nearest raw integer before sending it, so a value finer than the register's resolution is rounded, and one outside the register's 16-bit range is rejected.

A register with a codec in the catalog (see What each register carries) takes its value in the codec's form instead, and the server does the vendor encoding:

codecRegisters (Aotai)valueRefused
hhmmstart_time_1…6, end_time_1…6hour × 100 + minute: 1800 for 18:00, 2359 for 23:59a fraction, a negative, an hour over 23 or a minute over 59 (1860)
pf_aotaipower_factor_regulationthe power factor: -1…-0.8 or 0.8…1, in steps of 0.01anything between −0.8 and 0.8, or beyond ±1

A refused value comes back as ok: false with an error naming the register and the accepted form; nothing is sent to the inverter. readBack is in the same form (1800, 0.95).

Setting the inverter clock​

set_rtc_time (Aotai, Basic Set) is dataType datetime, three registers long, written in one function-16 request. Send value as the number YYYYMMDDhhmmss:

{"type": "write", "deviceKey": "…", "register": "set_rtc_time", "value": 20261105183000, "userId": "…"}

That sets 2026-11-05 18:30:00. The inverter clock has no time zone: send the local wall-clock time the installer wants the inverter to show. The year must be 2011–2099 and the date must exist; anything else is refused. The write_result carries no readBack or applied, because the clock has moved on by the time it could be read. Reading the register returns text "YYYY-MM-DDTHH:MM:SS", like the other date/time registers.

readBack and applied. After a successful write the server reads the register back and reports it as readBack, rounded to the register's scale (a 0.1 V register reads back 47.3, never 47.300000000000004). applied is true when readBack equals value to within one step of the scale, and false when it doesn't. Both are absent when the register can't be read back.

If the first read-back doesn't match, the server reads the register again, up to 2 more times, 700 ms apart, and reports applied: false only if none matches (readBack is the last value read). The Nexus acknowledges some writes before it stores them: on dev on 2026-11-04, parallel_address_setting written to 30 read back 0 straight away, yet the next write found 30 already stored. Reporting that first read made the app show "Settings Failed" for a write that had worked (cse-mobile issue #98). This adds at most about 2 s, and only to a write whose first read-back doesn't match.

Two re-reads were not always enough. The dev write audit of 2026-11-03 shows parallel_address_setting writes reported "kept a different value" whose value was stored 4–5 s later (cse-mobile issue #117). A register can therefore carry its own, longer wait: since 2026-11-16 the Nexus parallel_address_setting keeps re-reading for up to 6 s, 700 ms apart. The server stops re-reading early enough that write_result still arrives inside the ~10 s write budget, so a mismatch still answers applied: false rather than timing out. A Nexus that really does not store the value (one write in that audit never stored) still gets applied: false.

applied is sent on every successful write that could be read back, whether or not the value changed: true for a write that stored the value (including a write of the value the register already held), false for one the device kept a different value for. It is absent only when the write failed (ok: false), when the register cannot be read back (write-only, or the read-back failed: readBack is absent too), or when the register resets itself after a command (below), where readBack is present but applied is not.

applied: false with ok: true means the inverter acknowledged the write but did not store the value. The IP20 firmware answers an out-of-range setpoint this way, with no error: on a Yorker 5 kW, writing 40.0 V to dual_output_cutoff_voltage (range 44–60 V) returns readBack: 48. Show the user that the setting did not change, and display readBack, not the value you sent. Don't retry: the same write gets the same answer. Use applied, rather than comparing value and readBack yourself.

Refused before sending​

For settings with per-device limits (today the IP20 6KU's, see the Settings reference), the server checks the value against the same limits get_registers reports for that device, and refuses a write that breaks them without sending it:

{"type": "write_result", "deviceKey": "7c9e6679-7425-40de-944b-e07fc1f90ae7", "register": "constant_voltage_point", "ok": false, "error": "Constant Voltage Charging Point can't be changed on this inverter right now: fixed for lead-acid and flooded batteries; set Battery Type to lithium or custom to adjust it", "value": 56}

{"type": "write_result", "deviceKey": "7c9e6679-7425-40de-944b-e07fc1f90ae7", "register": "dual_output_cutoff_voltage", "ok": false, "error": "Dual Output Cutoff Voltage must be between 44 V and 58 V on this inverter", "value": 60}

Show error as it is. The check costs one device read before the write (model code, battery type and the settings the limits depend on). When that read fails for another reason, nothing is refused and the inverter decides, so applied: false can still happen. When the device does not answer that read at all (no session, or no reply within ~10 s), the write is not sent and you get device offline or unreachable, the same as a write that got no reply. Before 2026-11-12 this case waited out the read and then answered timed out waiting for the write to complete, which looked like a slow inverter (cse-mobile issue #128). It typically happens right after a logger has been moved or re-registered, or while tcpserver is being redeployed. Refused writes are not sent, so they are not in the write audit.

A command register that the inverter resets once the command starts (start equalization now, restore defaults, clear an alarm) can read back 0 straight after a write that worked. Where the vendor documents that, the server leaves applied out: today that is IP20 execute_not_connected_detection_immediately and, since 2026-11-05, Aotai restore_factory_settings (1122). For these, show "Sent" rather than "Applied" or "Failed". For the other one-shot commands, treat applied: false as "the register reads back different", not as proof the command failed.

A write that resets the inverter: unconfirmed. The Nexus restore_factory_settings (1122; 1 Default Reset, 2 Factory Reset) can reset the inverter before it answers the write. On dev on 2026-11-05 a Default Reset ended in write round trip: read response: … i/o timeout, reported as a failure (cse-mobile issue #117). Since 2026-11-16, when such a write gets no reply, write_result is ok: true with unconfirmed: true and a note, and no readBack or applied:

{"type": "write_result", "deviceKey": "7c9e6679-7425-40de-944b-e07fc1f90ae7", "register": "restore_factory_settings", "ok": true, "value": 1, "unconfirmed": true, "note": "the inverter did not answer the write; it resets on this command, which can cut its reply off, so the write was sent once but could not be confirmed. Check the inverter once it is back online."}

Show "Reset sent, the inverter is restarting", not an error. The write was sent exactly once and is never re-sent, not even after a garbled reply. A Modbus exception reply is still ok: false. The write audit records the attempt as ok with the note.

What the two resets did on real hardware (bench Nexus AEP-6KS48, inverter Y25419070162, 2026-11-17; the inverter answered every write, so unconfirmed did not come up). Compared over the 95 settings get_registers returns, before and after:

  • Default Reset (1) put Parallel Address and Total Number in Parallel back to 2 and 2 on a single inverter that had them at 0/0. Nothing else changed. The inverter's stored "defaults" are therefore not the factory zeros: a single inverter reset this way comes back thinking it is slave 2 of a pair, and shows "AC stop" and "Parallel Phase Loss" until the two are set to 0 again (with the inverter switched off).
  • Factory Reset (2), sent twice, was acknowledged and changed nothing readable: the parallel settings stayed at 2, the BMS protocol was unchanged, and the lifetime energy counters were unchanged. The cause is on the inverter side and is not known yet (both resets were sent with the inverter running).

Neither reset is a reliable way to return a Nexus to factory state yet. After either one, re-read the settings and tell the user what changed.

The dropdown. Since 2026-11-17 the catalog offers only 1 Default Reset (marked default) and 2 Factory Reset for restore_factory_settings, and carries selfClearing: true. The vendor's 0 ("Invalid") is the value the register reads back once a command has run, never a choice; listing it made the app pre-select "Invalid" (cse-mobile issue #117). For a selfClearing register, pre-select the option marked default instead of matching value.

A few Aotai settings are one bit, or a bit range, of a register shared with other settings (lvrt_enable is bit 1 of 1063). For these, value is the field's own value (0/1), not the whole word. The server reads the register first and changes only that field, so a bit-field write costs one extra round trip. If the read fails, the write is refused and nothing is sent. The Settings reference lists which settings are bit fields.

Privileged settings​

On every grouped model (Nexus, Yorker and IP20 3K6/5K), the writable registers of the More group, and on the Nexus work_mode option 1 (Anti-reflux to Meter), may only be written by a Crown Super Admin or Admin (realtime ticket claim "sa": true or "pa": true; see Privileged settings). For anyone else, including a ticketless device-owner connection, the write is refused before anything is sent to the inverter:

{"type": "write_result", "deviceKey": "…", "register": "anti_reflux_enable", "ok": false, "error": "settings in \"More\" can only be changed by a Crown Super Admin or Admin", "value": 1}
{"type": "write_result", "deviceKey": "…", "register": "work_mode", "ok": false, "error": "this option can only be chosen by a Crown Super Admin or Admin", "value": 1}

The refusal is recorded in the register write audit as denied, with denied_level SUPER_ADMIN. Other work_mode values are not affected.

The web console's send_command with kind: write_register applies the same rule; see Commands.

Custom commands (raw Modbus)​

custom_command sends one Modbus request built by hand, bypassing the register catalog. It is a diagnostic and commissioning tool for Crown staff only: the connection must be authenticated with a verified ticket carrying "sa": true or "pa": true, otherwise it is refused with custom commands are only for a Crown Super Admin or Admin. A read also needs registersRead VIEW on the device, a write registersWrite EDIT. An address in the device's firmware registers (its version registers, or IP20's OTA block 16384 to 16546, which is how firmware is loaded) also needs firmware VIEW to read and firmware EDIT to write; a Crown Administrator holds firmware VIEW only. The refusal is this address is in the device's firmware registers; needs FIRMWARE <level> on this device, and a refused write is recorded in the audit as denied. For a device whose model is not identified yet, every raw command needs the firmware level. An IP20 3K6/5K speaks the ASCII command protocol, not Modbus, so every custom command to it is refused with custom commands are Modbus frames; this inverter speaks the ASCII command protocol.

// read 4 words from 1056 (function 3 or 4: count 1-64)
{"type": "custom_command", "deviceKey": "…", "functionCode": 3, "address": 1056, "count": 4}
// write one word (function 6), or 1-64 words (function 16, "values")
{"type": "custom_command", "deviceKey": "…", "functionCode": 6, "address": 1147, "values": [2]}
{"type": "custom_command", "deviceKey": "…", "functionCode": 16, "address": 1007, "values": [6667, 1285, 4638]}
FieldNotes
functionCode3 or 4 (read count words, 1–64, no values), 6 (exactly one value) or 16 (1–64 values)
address0–65535; the request must not run past 65535
countReads only
valuesWrites only; each a 16-bit word, 0–65535
unitIdOptional, 1–247: another unit on the device's bus. Omitted means the device's own. Echoed in the reply when sent
frameInstead of all the fields above: a complete Modbus RTU request in hex, CRC included, spaces allowed, sent to the inverter as-is

With frame, e.g. the Nexus fan start and stop:

{"type": "custom_command", "deviceKey": "…", "frame": "010604E0000148CC"}
{"type": "custom_command", "deviceKey": "…", "frame": "01 06 04 E0 00 00 89 0C"}

The frame is checked before it is sent: the CRC must be correct, the unit id 1–247, the function 03, 04, 06 or 10 (16), and a read at most 64 words. frame can't be combined with functionCode, address, count or values (send either a frame or functionCode/address/count/values, not both), and it is refused on a Modbus TCP connection (logger/RTU only). The reply's functionCode, unitId and address are taken from the frame, a read returns values, and a function-16 write the Nexus echoes back counts as success. Writes are audited as raw:fc<function>@<address>, like the other form.

{"type": "custom_command_result", "deviceKey": "…", "ok": true, "functionCode": 3, "address": 1056,
"values": [1, 0, 2, 100], "requestHex": "…", "responseHex": "…", "durationMs": 180}

values in the reply holds the words a read returned, raw. There is no scale, no range check and no read-back: the server sends exactly what you asked for. requestHex/responseHex are the frames on the wire. A device-side failure (Modbus exception, timeout) is ok: false with error.

Every write is recorded in the register write audit as register raw:fc<function>@<address> (e.g. raw:fc6@1147), source ws_write, with the first word as the new value. Since 2026-11-30 every refused write is recorded too, as denied with the caller and the reason: denied_level SUPER_ADMIN (no sa/pa), registersWrite EDIT (no write level, or a device outside the ticket's grants), or firmware EDIT. Refused reads are not audited. A custom command shares the connection's one-write-in-flight slot with write (a write or custom command is already in progress for this connection, try again shortly), and a device runs one custom command at a time (a custom command is already in progress for this device, try again shortly).

Common error values: userId is required, device not found, not authorized to control this device, device offline or unreachable (no tcpserver session holds the device, or it didn't answer within ~10s), a write is already in progress for this connection, try again shortly, this device has no logger fitted, so it cannot be controlled; fit it a logger first (a deactivated device — see Reusing a logger; answered at once rather than after the ~10s timeout), ownership check unavailable (device database not configured), and internal error. Anything else is the device-side reason reported by tcpserver (unknown or non-writable register, value out of range, a Modbus exception, ...).

userId is not verified against anything cryptographic — read this carefully. The gateway checks that userId matches the device's recorded owner (devices.owner_user_id), and rejects the write if it doesn't, or if the device has no owner yet, or if userId is missing. It does not verify the connecting client actually is that user — there is no authentication system in front of this endpoint yet (same gap as Known gaps below). This closes "any client can write to any device," not "any client can claim to be any user." Do not rely on this as a real security boundary until a proper auth system exists in front of it.

Claiming a device. Use the register message above — it sets owner_user_id as part of creating the pending registration, so a device registered that way is already claimed by the time it connects. A device row with no owner (created a different way during early testing) fails the ownership check unconditionally — no userId value succeeds against a NULL owner_user_id. To claim one directly on a local development database, set that column yourself (it's a Postgres UUID column — the value must be a syntactically valid UUID) and reuse the same value as userId:

UPDATE devices SET owner_user_id = '17833b2e-a851-4a17-a764-62524d667959'
WHERE id = '<deviceKey>';

The UUID above is just an example — any valid UUID works (SELECT gen_random_uuid(); in psql, or uuidgen on the command line). The gateway's own check is a plain case-insensitive string compare against this column, not a format check, so whatever you put in the DB is exactly what has to come back as userId.