# SA API and reduced commands :id=top

------

> _Doc Ver:_ 1.3   
_API Ver:_ 2.11   
_App Ver:_ 2.6.6.53  
_Date:_ 09/09/2026

------

> SA1 2.x field ports (`sa-di` + `sa-web`):
> * HTTP **80 / 8080 / 81** — `sa-web`; sign in at `/login` first
> * Browser spectrum — HTTP **`/ws`** (not 7091; do not connect to 7094 from a PC)
> * TCP **127.0.0.1:7090** — `sa-di` command port, **localhost only**; not reachable from the LAN
> * TCP **127.0.0.1:7094** — spectrum stream, **sa-web only**
> * UDP **8190** — demodulated data (LAN)
> * UDP **7082** — physical-value character / UDP commands (LAN)
> * TCP **1502** — Modbus TCP slave (**off** until Addon → Modbus Configure); see [Modbus TCP slave](modbus_tcp_slave.md)
>
> Older help listed Websocket **7091**. That port is gone.
>
> Note:
> * TCP 7090 is a short connection: it closes after one reply.
> * `*CHS!` / `*CHW!` are not allowed through the browser gateway. Switch spectrum with `:DATA:ODT OS` / `:DATA:ODT WAV`.
> * Do not send `:CMD?` to run a shell. Do not `killall -9 sa-di`.
>
> HTTP ops (after login): `GET /api/ops/health`; operators `POST /api/ops/action` (`confirm:true`). Fields: §8 below. Field binaries: `sa-doctor` / `sa-cli` / `sa-mcp` — [Ops tools](ops.md) · [sa-doctor](sa-doctor.md) · [sa-cli](sa-cli.md) · [sa-mcp](sa-mcp.md).

------

## 1. System base commands :id=base 

    1. :SYS:VER?        System command version
    2. :SYS:APP?        System application version
    3. :SYS:ERR?        System error code and description
    4. :SYS:IDN?        System IDN, IP, and serial number.
    5. :SYS:SN?         System serial number
    6. :SYS:IP?         System IP
    7. :SYS:TIME?       System time, Unix timestamp format.
    8. :SYS:RST         System restart
    9. :SYS:RES         System reset; clear error flags.
    10. :SYS:SHUTDOWN   System shutdown.
    11. :SYS:HELP?      System help.
    12. :SYS:RELOAD     Hot-load persist (including Modbus start/stop). Returns `0`. See [Modbus TCP slave](modbus_tcp_slave.md).

## 2. System debug commands  :id=debug

    1. :SYS:DEBUG?         Query whether the system is in debug mode
        :DEBUG?
    2. :SYS:DEBUG:ON       Set the system to debug mode 
        :DEBUG:ON
    3. :SYS:DEBUG:OFF      Turn off system debug mode
        :DEBUG:OFF
    4. :SYS:DEBUG:CLS      Clear the output cache in debug mode
        :DEBUG:CLS

## 3. Sensor commands    :id=sensor

    1. :FBG:CH:NUM?                Get the number of valid channels after sensor configuration.
    2. :FBG:ACF                    Auto-configure sensors according to the set parameters.
    3. :FBG:ACS ch=xx wl=xx        Auto-configure a single sensor; ch is channel, wl is wavelength.
    4. :FBG:CFG?                   Get configuration of all sensors on the device.
        Format:
        {
          "Sensor":[[1,1,1532000,0],[2,1,1540000,1],[3,2,1532000,0],[4,2,1540000,1]],
          "Unit":["pm","pm","pm","pm"],
          "SN":["6820013","6830013","6820014","6830014"]
        }
        Meaning:
        Sensor: numeric sensor information
            [1,2,3,4]
            1: Sensor ID on the device
            2: Device channel of the sensor
            3: Sensor initial wavelength WL0
            4: Sensor alarm level ID
        Unit:
            Physical-value unit array for each sensor in Sensor.
        SN:
            Serial number of each sensor in Sensor; maximum 16 characters.

    5. :FBG:RES id=xx,yy,zz         Reset sensors and clear error codes; ‘xx,yy,zz’ is an ID array; if empty, reset all.
         Example: 
         ':FBG:RES id=1,3,5'        Reset sensors with IDs 1, 3, and 5
         ':FBG:RES'                 Reset all sensors

    6. :FBG:GET id=xxx              Get sensor information by sensor ID.

        Format:

        {
          "ID": 1,
          "SN": "6820013",
          "PN": 1001,
          "Name": "T6820013",
          "Type": 0,
          "AlarmID": 0,
          "Channel": 1,
          "WLExt": {"Enable": 0,"WLRng": 500,"WLTrigger": [20, 50]},
          "Function": [{"WL0": 1532000,"WL": [1530000, 1533000],
          "Parameters": [25.000000, 0.100000, -9.149000, 107.894000, 0.246000, 1548.900000,0.000000],
          "Formula": "w-wl0"}],
          "Unit": "pm",
          "Location": "",
          "Memo": ""
        }

        Meaning:

        ID:  Sensor ID on the device 
        SN:  Sensor serial number 
        PN:  Sensor type code 
        Name:     Sensor alias 
        AlarmID:  Alarm setting ID 
        WLExt.Enable:       Enable automatic wavelength extension 
        WLExt.WLRng:        Wavelength range after automatic wavelength extension 
        WLExt.WLTrigger.1:  Minimum wavelength change that triggers automatic wavelength extension.
        WLExt.WLTrigger.2:  Maximum wavelength change that triggers automatic wavelength extension.
        WL0:    Sensor initial wavelength 
        WL.1:   Sensor wavelength range minimum 
        WL.2:   Sensor wavelength range maximum 
        T0:  Sensor initial temperature 
        TC:  Sensor temperature coefficient 
        Parameters: [A,B,C,D,K]:  Values of parameters referenced in the formula that computes the sensor physical value.
        Formula:  Formula that computes the sensor physical value. 
        Unit:  Unit of the sensor physical value. 
        Location:  Sensor location; the English "," character is not supported. 
        Memo:  Sensor remarks; the English "," character is not supported. 

    7. :FBG:SET id=xxx&data=yyy    Set sensor information by sensor ID; 'yyy' is the data to set and must match the format of item 15.
    8. :FBG:DEL id=xxx             Delete sensor information by sensor ID.
    9. :FBG:ERR? id=xxx            Query the sensor error code by sensor ID.
    10. :FBG:CLS id=xx,yy,zz       Clear sensor error codes by sensor ID array; if id is empty, clear all.

    11. :VS:ENABLE?                Get virtual-sensor enable status.
    12. :VS:NAME?                  Get the name list.
    13. :VS:CFG?                   Get all configuration.
    14. :VS:RES id=xx,yy,zz        Reset sensors; id= sensor id array.
    15. :VS:GET id=xxx             Get a single sensor's information by id. 
    16. :VS:SET id=xxx&data=yyy    Set sensor information by id.
    17. :VS:DEL id=xxx             Delete a sensor by id.
    18. :VS:ERR? id=xxx            Get sensor error information by id.
    19. :VS:CLS id=xx,yy,zz        Clear sensor error codes; id= sensor id array.
    20. :VS:WARN? id=xxx           Query sensor alarm information by id.
    21. :VS:WARN:CLS id=xx,yy,zz   Batch-clear sensor alarm information by sensor id list.

## 4. Device sampling commands   :id=daq

    1. :DAQ:FRQ?                    Get the device raw sampling frequency.
    2. :DATA:FRQ?                   Get the system demodulation frequency.

## 5. Data commands      :id=data

    1. :DATA:SAVE?              Get data-save status parameters.
    2. :DATA:SAVE:ON            Enable save
    3. :DATA:SAVE:OFF           Disable save
    4. :DATA:SAVE:START?        Query the save action
    5. :DATA:SAVE:START:ON      Start acquisition
    6. :DATA:SAVE:START:OFF     Pause acquisition
    7. :DATA:SAVE:COUNT?        Get the save counter
    8. :DATA:SAVE:FILE?         Get the saved file name
    9. :DATA:ODT WAV            Enable wavelength and physical-value demodulation mode.
        :DATA:ODT:WAV        
        :ODT:WAV
    10. :DATA:ODT OS            Enable spectrum output mode; binary data output; see: binary hardware protocol.
         :DATA:ODT:OS
         :ODT:OS    
    11. :DATA:ODT?              Get the data output mode, 0: wavelength physical value; 1: spectrum.
         :ODT?
    12. :DATA:PVJ? counter=xx   Get the latest physical-value frame in JSON format; counter is the previous frame's counter; if counter is not set, the default is -1. Use this after precise-wavelength calibration; do not verify with :DATA:PV?. Remote: `sa-cli scpi ':DATA:PVJ?'`. Vs wavemeter ~+22 pm → 0.5 pm. See [Precise wavelength](precise_wl.md).

        Format:

        {
            "Code":200,
            "Value":{
                "Counter":874527,
                "Count":11,
                "dt":[
                        [0,0,1,1520341,0.000000,0,0,0],
                        [1,15,8,1531963,-37.000000,6820020,0,0],
                        [1,16,8,1540065,179.249784,6830020,0,0],
                        [1,17,9,1531952,-48.000000,6820021,0,0],
                        [1,18,9,1540028,176.215936,6830021,0,0]
                    ],
                "vs":[
                        [1,38.577764,6820013,0,0]
                    ],
                "NIL":[1,2,3,4,5,6,13,14,19,20,21,22,23,24]
                }
        } 

        Meaning:

        Code: network code; 200 is normal
        Count: number of valid sensors in this frame 
        Counter: valid demodulation counter, also called heartbeat
        dt: one data frame.
            [1,2,3,4,5,6,7,8]
            1: whether the sensor matched
            2: sensor ID
            3: channel of the sensor
            4: sensor wavelength
            5: sensor physical value
            6: sensor serial number
            7: sensor exception count
            8: alarm level

        NIL: set of sensor IDs with empty data;
            Sensors already configured on the device that are not installed or have a fault, so they cannot be detected and have no data.

        vs:[1,2,3,4,5]; present when virtual sensors are enabled and configured.
            1: id
            2: computed value
            3: serial number
            4: error code
            5: warning code
                
    13. :DATA:WAVJ?                     Get the latest wavelength frame in JSON format
    14. :DATA:OS?CH=xx                  Get spectrum data; 'xx' is the channel number of the last channel already received
    15. :DATA:OS:CH?                    Get the channel number of the current frame
    16. :DATA:OS:CNT?                   Get the spectrum counter
    17. :DATA:RAW?                      Get first serial-port or network-interface data, binary; see [Binary data extended format](data-ext.md)
    18. :DATA:RAW2?                     Get second serial-port data, binary; see [Binary data extended format](data-ext.md)

## 6. Data transfer commands  :id=transfer

    1.  :DATA:UDP:RAW:STA?             Query source-data mode transfer status (runtime).
    2.  :DATA:UDP:RAW:ENABLE?          Query whether source-data mode is enabled.
    3.  :DATA:UDP:RAW:ENABLE:ON        Enable source-data mode.
    4.  :DATA:UDP:RAW:ENABLE:OFF       Disable source-data mode.
    5.  :DATA:UDP:RAW:PAUSE?           Query whether source-data mode is paused.
    6.  :DATA:UDP:RAW:PAUSE:ON         Pause source-data mode.
    7.  :DATA:UDP:RAW:PAUSE:OFF        Resume source-data mode.
    8.  :DATA:UDP:RAW:STA data=xxx     Set source-data mode transfer status (runtime).
    9.  :DATA:UDP:RAW:CFG?             Query source-data mode configuration.
    10. :DATA:UDP:RAW:CFG data=xxx     Set source-data mode configuration.

    11. :DATA:TCP:PJ:STA?              Query TCP-mode physical-value JSON status.
    12. :DATA:TCP:PJ:PAUSE?
    13. :DATA:TCP:PJ:PAUSE:ON
    14. :DATA:TCP:PJ:PAUSE:OFF
    15. :DATA:TCP:PJ:STA data=xxx
    16. :DATA:TCP:PJ:CFG?
    17. :DATA:TCP:PJ:CFG data=xxx

    18. :DATA:UDP:PJ:STA?              Query UDP-mode physical-value JSON status.
    19. :DATA:UDP:PJ:PAUSE?
    20. :DATA:UDP:PJ:PAUSE:ON
    21. :DATA:UDP:PJ:PAUSE:OFF
    22. :DATA:UDP:PJ:STA data=xxx
    23. :DATA:UDP:PJ:CFG?
    24. :DATA:UDP:PJ:CFG data=xxx

    25. :DATA:TCP:SC:STA?              Query TCP-mode cloud-service status.
    26. :DATA:TCP:SC:PAUSE?
    27. :DATA:TCP:SC:PAUSE:ON
    28. :DATA:TCP:SC:PAUSE:OFF
    29. :DATA:TCP:SC:STA data=xxx
    30. :DATA:TCP:SC:CFG?
    31. :DATA:TCP:SC:CFG data=xxx

## 7. Service commands  :id=service

    1.  :SVR:CFG?                      Get configuration of all services. 
    2.  :SVR:STAT? id=xx               Get the status of a single service by service id.
    3.  :SVR:STAT data=yyyy            Set service status, JSON format; an id field is required to identify the service.
    4.  :SVR:DSP? id=xx                Get the description of a specific service.
    5.  :SVR:LINK? id=xx               Get the service configuration-file link; if id is empty, get all links.

------

## 8. HTTP ops surface (sa-web) :id=ops

The browser still uses the `/login` cookie. Scripts / `sa-cli` / `sa-mcp` JSON-login for a `token`, then `Authorization: Bearer <token>` (Cookie `sa_web_session` also works). Do not embed MCP in sa-web. Do not open 7090 on the LAN.

### 8.1 POST `/api/auth/login` (same as `/api/login`)

JSON: `{"username":"admin","password":"…"}` (also accepts `name` instead of `username`). Success:

```json
{"ok":"1","name":"admin","role":"administrator","token":"<session-id>"}
```

Failure: 401 `unauthorized`; disabled account 403 `disabled`. Form login still redirects to `/login?err=`.

Factory often `admin` / `temppwd` (change on site). Roles: `superuser`, `administrator` (legacy `operate` / `admin`), `user`, `guest`. `can_operate` is true for superuser and administrator.

### 8.2 GET `/api/info` (public, no login)

```json
{"name":"…","idn":"…","version":"2.6.6.24","version_raw":"2,6,6,23"}
```

`version` is four-part dotted. The login page reads this too.

### 8.3 GET `/api/me` (signed in)

```json
{
  "name": "admin",
  "role": "administrator",
  "display_name": "管理者",
  "enabled": true,
  "can_operate": true,
  "can_manage_users": true
}
```

No session → 401.

### 8.4 GET `/api/ops/health` (signed in; any signed-in role)

No session → 401. Old sa-web without this path → 404 (`sa-doctor` / `sa-cli` tell you to upgrade sa-web).

Top-level fields:

| Field | Meaning |
|-------|---------|
| `ok` | true when `worst` is not `fail` (still true if only warnings) |
| `product` | always `"sa1"` |
| `worst` | `pass` / `warn` / `fail` |
| `info` | same as `/api/info` |
| `init` | `systemd` / `sysv` / `supervise`; override with `SA1_INIT` |
| `processes` | `{"sa-di":1,"sa-web":1,"csdfu":1}` from local `/proc` |
| `mutex.ok` | true when no SA2 device processes |
| `mutex.conflicts` | e.g. `["sa_daq=1"]`. Names: `sa_daq` `sa_daq_c` `sa_web` `sa_broker` `sa_run` `sa_control` |
| `ports.login` | local `/login` URLs that work (80, 8080, 81) |
| `ports.di_cmd` | local 7090 `*IDN?` succeeded |
| `ports.di_os` | local 7094 TCP connect succeeded |
| `di.idn` / `di.ver` | raw `*IDN?` / `*VER?` |
| `disk` | `path` `total` `free` `used` `usage_percent` `sa_file_exists` |
| `version.display` / `raw` / `version_n` | from `version.json` |
| `version.di_ver` | `*VER?` as int |
| `version.match` | VersionN equals `*VER?` |
| `checks` | `[{id, ok, status, detail}]`; `status` is `pass`/`warn`/`fail`/`skip` |

`checks[].id` (complete list, typical order):

| id | pass | otherwise |
|----|------|-----------|
| product | version is 2.6.x | not 2.6.x → warn |
| sa_di_count | exactly 1 | else fail |
| sa_web_count | exactly 1 | else fail |
| csdfu_count | exactly 1 | else **warn** (not fail) |
| mutex | no SA2 processes | present → fail |
| login_http | local /login HTTP&lt;400 | none of the three ports → fail |
| di_idn | `*IDN?` non-empty | fail |
| di_os | 7094 reachable | unreachable → **warn** (not fail) |
| version_match | VersionN == `*VER?` | lag → warn (`restart sa-di`); no `*VER?` → skip; no version.json → warn |
| disk | usage &lt;90% | ≥90% warn; ≥95% fail. Prefers the data dir, then `/` |
| init | systemd/sysv/supervise detected | unknown → warn |

`disk.sa_file_exists` is not its own check. `checks[].ok` is true for `pass` and `skip`.

### 8.5 POST `/api/ops/action` (operator + JSON `confirm:true`)

No session → 401. Non-operator → 403. `confirm` not true → 400 `{"error":"confirm required"}`. Bad JSON → 400 `bad json`. Unknown `op` → 400 `unknown op`. sa-di denied → 403 `denied`. Execution failure → 502.

Body:

```json
{"op":"reload","confirm":true}
{"op":"time","confirm":true,"value":"1710000000"}
{"op":"upgrade","confirm":true}
```

| op | Effect |
|----|--------|
| reload | `:SYS:RELOAD`; sa-di rereads conf (Addon Modbus Save uses this) |
| time | `:SYS:TIME <value>`. One token (Unix seconds or sa-di stamp); no space, tab, newline, `;` `&` `\|` |
| upgrade | background `/usr/local/bin/sa1-upgrader upgrade -y`, log `/home/debian/sa1/persist/log/sa1-upgrader.log`. **No reboot by default**. Not cspkg. |

Success:

```json
{"ok":"1","op":"reload","body":"…"}
```

`sa-cli --yes` and `sa-mcp` `confirm=true` are this `confirm` field. Without it the client refuses locally and does not hit the device.

### 8.6 Blade root load `/api/bladeload/*` (logged in; writes need operate)

Enable first: Setting → Fan Blade → Enable root load (`addon.php?dir=bladeload`, `BLADELOAD_ENABLE`). Save `:SYS:RELOAD`. Work UI: `bladeload.php`. Handbook: [Root load](bladeload.md).

| Method | Path | Role |
|-------|------|------|
| GET | `/api/bladeload/map` | any login |
| POST | `/api/bladeload/map` | operate |
| GET | `/api/bladeload/peaks` | any login (`:DATA:PVJ?`) |
| POST | `/api/bladeload/bind` | operate (channel + ±1500 pm window) |
| POST | `/api/bladeload/calib` | operate (multipart `ops`+`strain` or `csv`) |
| POST | `/api/bladeload/apply` | operate (writes VSS 201–208, then optional `:SYS:RELOAD`) |
| POST | `/api/bladeload/modbus` | operate (sparse `0=201…14=208`; does not set `MODBUS_ENABLE`) |
| GET | `/api/bladeload/csv/example` | any login |

Apply refuses if `BLADELOAD_ENABLE` is false. Virtual IDs 201–208. η FUN `RELSTD&(201,203,205)`.

------

## Change log :id=changelog

|Version|Date|Description|
|:--:|----|----------|
|2.12|09/17/2026|Blade root load `/api/bladeload/*` (enable `BLADELOAD_ENABLE`, not SA2 `sys_params`).|
|2.11|09/14/2026|PVJ CLI: sa-cli / sa-mcp; precise-wl ~+22 pm → 0.5 pm.|
|2.10|09/13/2026|Documented Modbus TCP slave on 1502 (off by default).|
|2.9|09/09/2026|HTTP ops: `/api/ops/health`, `/api/ops/action`, JSON login `token`.|
|2.7|09/03/2026|Rewritten for SA1 2.x ports: 7090/7094 localhost, `/ws`, 7091 removed.|
|2.6|06/05/2021|1. Use the new file structure.|

------

### [Top](#top)
