# Precise wavelength calibration :id=top

------

> _Doc Ver:_ 1.7  
_App Ver:_ 2.6.6.53  
_Date:_ 09/14/2026

------

SA1 2.x (`sa-di` + `sa-web`) can correct **every demodulated wavelength** against an external **temperature-insensitive etalon** (Fizeau / Fabry–Pérot comb) plugged into **any channel 1–32**. The etalon peaks were measured on a high-precision wavemeter; the demodulator's scanned wavelengths still have a bias. After this function is enabled, processed wavelength, physical value, save, report, and Modbus all see the calibrated values.

Factory default is **off**, and the etalon channel factory value is **16** (not 1, and not a misplug on 9). Plug the etalon into **any** port 1–32 and type the channel the spectrum actually shows. A lab unit once had the fibre in the wrong port, so software saw channel 9 that day — that was a wiring mistake, **not a recommended channel**. Do not put the site CSV into factory `precise_wl.json`.

See also: [Get data](get_data.md) · [Wavelength format](data-wl.md) · [Spectrum](data-os.md) · [Physical value](data-pv.md) · [Modbus](modbus_tcp_slave.md). This is not [precise refer](precise_refer.md) (per-sensor lookup). Contrast: [Precise refer ≠ precise wavelength](precise_vs.md).

**Contents:** [Not this](#not) · [When](#when) · [Find the channel on the spectrum](#find) · [Hardware](#hw) · [Web](#ui) · [Algorithm](#algo) · [Integration](#integ) · [CLI](#cli) · [How much better](#gain) · [Scope](#scope) · [JSON](#json) · [Verify](#verify) · [Lab example](#example) · [Troubleshooting](#trouble) · [Ask](#ask) · [Help](#help)

------

## 0. This is not :id=not

| Feature | What it does |
|---------|----------------|
| **Precise wavelength** (this page) | One etalon channel → least-squares line over **all** matched pairs **measured pm → true pm**, applied to **all channels** |
| **Precise refer** | Per-sensor lookup table **WL or PV → true PV** (`precise_refer`) |
| **Internal scan etalon** | `sa.conf` `Etalon.Left/Right` for the scan engine FBG, not an output calibration |
| **Sensor `wl0` / formula** | Coefficients in the sensor register; this function rewrites wavelength **before** match and formula |

------

## 1. When to use it :id=when

Use it when the application needs **absolute wavelength**, not only relative FBG shift:

- Interrogator output must match a wavemeter / gas cell / transfer standard
- Long-term comparison across units or firmware
- Sensors whose coefficients were fitted against wavemeter wavelengths

Do **not** use it as a replacement for sensor `wl0` / formula calibration. If `wl0` was fitted on **uncorrected** scan wavelengths, PV will look worse until you re-fit against calibrated wavelengths.

------

## 2. Confirm the etalon channel on the spectrum (required) :id=find

**Trust the spectrum, not the panel silk-screen and not `sensors.json`.** The fibre may sit in a different port. A channel with dozens of sensors in the config only means it was scanned once; it does not mean there is light now.

### 2.1 Spectrum page

1. Log in as **admin**.
2. Open **Spectrum** (`os.php`). The page sends `:DATA:ODT OS`. Do not expect the browser to send `*CHS!` — sa-web **does not whitelist** `*CHS!` / `*CHW!`.
3. Tick channels 1–32 one by one. Look at **intensity**, not a naive peak count: empty channels produce dozens of noise “peaks”.
4. **Etalon**: a long **even comb** across the C-band, medium intensity (lab unit ~800–1200), spacing near the nominal FSR (800 pm class is often 730–800 pm). Count local maxima only with intensity **≥ 200**.
5. **FBG**: one to three strong peaks (lab maxI often > 3000).
6. **Empty port**: maxI about **1**, no comb.
7. Switch back to wavelength immediately: `:DATA:ODT WAV` / `:DATA:OS:OFF`. Staying in OS stops the wavelength stream.

Converted channel = 0-based byte at offset 34 of the OS packet **+ 1** (same numbering as the wavelength list `Channel`). With a non-zero `channelOffset`, the second 16-channel board is numbered 17–32.

### 2.2 Wavelength list is only supporting evidence

With cal **off** and **Output** on, the etalon channel shows a dense comb. That only means “this path has many peaks”. It is **not** a product rule (“more than 20 wavelengths ⇒ etalon” was a one-off lab observation).

Do **not** take the channel from:

| Source | Why it lies |
|--------|-------------|
| Panel silk-screen | Fibre may be in another port |
| `sensors.json` / PV Channel | Config table, not this frame’s light |
| Peak count with no intensity floor | Empty channels look busy |

Lab unit **`192.168.3.119` (2026-09-14)** is only a wiring example; the numbers are not factory specs:

| Wiring that day | Software channel | Notes |
|-----------------|------------------|-------|
| Fibre in the wrong port (morning) | **9** | ~51 teeth ≥200, maxI≈1112, spacing≈782 pm; channel 16 empty |
| Fibre moved later | **16** | Matches factory default 16; 24 nm table matches; cal-off vs wavemeter ~**+22 pm**. Array sat on 15 then 5 |

32 sensors on a channel in the config are a leftover table. Factory `WLCAL_CHANNEL` is **16**. Do not treat a misplug on **9** as the default, and do not copy another unit. Confirm on this unit’s spectrum.

------

## 3. Hardware :id=hw

- Machines may be configured with **1 to 32** optical channels. The etalon may sit on **any** of them. Factory channel is **16**; fill the spectrum-confirmed port. Do not treat a lab misplug on 9 as the default.
- Other channels keep normal FBG sensors.
- Typical **nominal** spacings: **200 / 400 / 800 / 1600 pm**. An FP etalon is only approximately equally spaced in wavelength (FSR is even in frequency). The value is a **pairing gate** only (`spacing / 2`, minimum 20 pm), not a two-point scan scale.
- The known list **may be incomplete**. Extra scanned peaks are unused; missing known lines are skipped. You need **at least two** successful pairs in a frame.

------

## 4. Configure on the Web :id=ui

Needs **admin** (`can_operate`). A normal `user` gets **403** on `setjson.php` and AfterCfg.

1. Open `http://<device>/login` (try `:8080` / `:81` if port 80 is down).
2. **Setting** → **Precise wavelength** (`addon.php?dir=precise_wl`).
3. Set **Etalon channel** to the channel confirmed in [§2](#find) (1–32).
4. Set **Nominal spacing (pm)** (200 / 400 / 800 / 1600 typical).
5. The **wavelength list** is a textarea (one value per line). You can also **import** CSV/txt or **Export CSV**.
   - Values **&lt; 10000** are **nm** (×1000 → internal absolute pm).
   - Values **&gt; 10000** are already **pm** (must be 1.4e6–1.7e6).
   - Separators: newline, CR, comma, semicolon, space, tab. A non-numeric header is skipped.
   - Wavemeter CSV is **nm, not pm**. The lab file `标准波长.csv` is **nm, four decimals** (e.g. `1527.2844`). Treating them as pm yields ~1.53 nm and the parser drops them.
6. **Output etalon-channel wavelengths**: off by default (the etalon is not a sensor). After a **successful** match that channel is omitted. Tick to show **only the comb teeth that matched the written table** (scan bias with cal off; residual after cal on). Extra scanned peaks not in the table are dropped. A failed match never strips the channel.
7. **Extend outside range**: on (default) applies the **same least-squares line fitted to all matched pairs**. Off = leave peaks outside the matched range at the demodulated value. **Do not calibrate from two neighbouring table lines** (an FP etalon is only approximately equally spaced in wavelength).
8. Tick **Enable**, **Save**. AfterCfg is **`:SYS:RELOAD`** and must return **`0`**. Do **not** `killall -9 sa-di`.
9. Enable requires at least **2** valid points; otherwise it stays off and logs `[wl-cal] enable requested but fewer than 2…`.

Help on that page opens this document (`help/#/{lang}precise_wl`). The **Config** button only runs AfterCfg; you must **Save** first.

------

## 5. Algorithm :id=algo

Internal unit is **absolute picometres** (double). Hot path: convert thread, **after** `std_data_equsn_set`, **before** Mode 0 wavelength save and before merge / PV. Spectrum (OS) and raw UDP save are **not** rewritten.

1. Read the etalon channel's scanned peaks. Sort.
2. Greedy 1:1 match of each known line to the closest unused scanned peak, gate = **spacing/2** (minimum 20 pm).
3. Need **≥ 2** pairs. Otherwise: **do not apply, do not hide**, throttled log `[wl-cal] match failed…` / `etalon channel … has n peaks`.
4. Sort pairs by measured wavelength. Fit `true = a·measured + b` by least squares over **all** pairs (an FP cavity is not equally spaced in wavelength; two neighbouring table lines are not a scan scale). Outside the table: same line if Extend is on, else leave the demodulated value.
5. Apply `f` to **every** peak on **every** channel in that standard wavelength packet.
6. After a successful match, compact the etalon channel: **Output** off → drop it; on → keep **only matched table lines**. Memmove later floats, rewrite `0xFEFEFEFE`, shrink `len`, recompute `VALID_CH`. Changing the count without moving floats corrupts later channels.
7. Dual source (data source 1/3): a packet that does not contain the etalon reuses the last successful map. A frame that **has** etalon peaks but fails to match is still fail-closed. Disable clears the cache.

Replay of files that were already calibrated: if etalon peaks remain, rematch ≈ identity. If they were stripped (`output=false`), match fails and the packet is left as-is.

------

## 6. Integration (readout / packet / save / masters) :id=integ

Calibration runs **after sa-di convert**. Hosts must read **processed** paths. SA1 and SA2 are mutually exclusive (same UDP **8190** / 7090 / 7094 / 80 / 8080 / 81). Stop `sa_daq` / `sa_web` / `sa_broker` / `sa_run` before testing SA1. Do not copy SA2 `web/` / `conf/`.

### 6.1 Data path

```
Hardware UDP 8190  →  convert (std packet)  →  precise-wl cal  →  WL save / merge / PV / report / Modbus
Spectrum 7094 / raw UDP save  skip this function
```

Sensor match and formulas see the **calibrated** `w`. If precise refer (the other feature) is also on, it looks up PV from that calibrated wavelength — that is not this page.

### 6.2 Which API to use

| Path | Calibrated? | Notes |
|------|-------------|-------|
| Monitor list / `get_phy_data.php` / `:DATA:PVJ?` | **Yes** | JSON rows `[matched, id, ch, wl, pv, …]`; `wl` is absolute pm |
| Processed WL packet (ver 0 / 4 / 5) | **Yes** | Counts at offset **35** (32 bytes); floats from **67**, value = **wavelength − 1 500 000 pm**; end `0xFEFEFEFE` |
| `:DATA:PV?` / `get_phy_data_bin.php` | **No** | Raw `gDcs` cache — **do not** use it to verify this function |
| UDP 8190 payload / `DS_SAVE_RAW` | **No** | Hardware scan |
| Spectrum page / `127.0.0.1:7094` | **No** | Use it to find the channel, not as calibrated WL |
| `data/wl` and `data/pv` save | **Yes** | Mode 0 writes WL after calibration |
| Modbus TCP FC03 (default **1502**) | **Yes** | Holding registers are calibrated PV |
| Browsers must not open 7094; commands go `/ws` → sa-web → local 7090 |

Local calibrated JSON (login first):

```bash
curl -sS -c /tmp/sa1.ck -b /tmp/sa1.ck \
  -d 'name=admin&password=temppwd' http://127.0.0.1:8080/api/login
curl -sS -b /tmp/sa1.ck http://127.0.0.1:8080/m/get_phy_data.php

printf ':DATA:PVJ?\n' | nc -w 2 127.0.0.1 7090
```

After save, sa-di logs `[wl-cal] loaded enable=… ch=… spacing=… known=… output=… extend=…`.

`:DATA:PVJ?` `Value.dt[]` rows are `[IsMatched, sensorID, Channel, wl_abs_pm, pv, SN, Error, AlarmLevel]`. `wl` is integer absolute pm (`1524963` = 1524.963 nm). Rank-match by channel then wavelength for on − off.

### 6.3 Reload

`Execute.AfterCfg.Name` must stay **`:SYS:RELOAD`**. Upgrade merge keeps site values by `ID`; a missing file is created from the package. Do not `killall -9`. Do not `sync-runtime.sh --conf` onto persist.

------

## 6.4 Command line (toggle and read) :id=cli

Save on the Web first, or edit persist JSON then reload. Remote HTTP only; touch `127.0.0.1:7090` on the device. sa-web does not whitelist `*CHS!` / `*CHW!`.

```bash
export SA1_URL=http://127.0.0.1:8080 SA1_USER=admin SA1_PASSWORD=…
sa-cli --help
sa-cli scpi '*VER?'
sa-cli scpi ':DATA:PVJ?'          # calibrated JSON; do not use :DATA:PV?
sa-cli reload --yes
printf ':DATA:PVJ?\n' | nc -w 2 127.0.0.1 7090
```

Toggle enable (keep the spectrum-confirmed channel; factory default **16**): edit `WLCAL_ENABLE` in `/var/sa/conf/precise_wl.json`, then `sa-cli reload --yes`. MCP: `sa1_scpi` with `:DATA:PVJ?`; `:SYS:RELOAD` needs `confirm: true`. See [sa-cli](sa-cli.md).

------

## 6.5 How much better :id=gain

Judge **etalon vs wavemeter residual**, not the sensor on−off delta. The sensor delta is the correction (scan bias removed). Negative means shorter after cal.

| | Cal off (scan bias) | Cal on (residual) |
|--|---------------------|-------------------|
| Lab 3.119, etalon on software **16** (after the fibre was moved; same as factory default 16; numbers are examples) | median **+22 to +23 pm** (max ~+50) | SA1 ~**0.5 pm** (integer pm); SA2 same day ~**0.02 pm** |
| Same unit earlier, fibre misplug, software **9** | median **+192 pm** | ~**0.5 pm** |

That is about **20–23 pm** of systematic error removed (or ~**190 pm** on the misplug). A 32-peak array on **channel 5** moved **−17 to −33 pm** (median **−25 pm**). CH5 vs CH15 on−off differed by ~**0.06 pm**. SA1 vs SA2 on CH5 differed by ~**1 pm**.

------

## 7. What is affected :id=scope

| Path | Calibrated? |
|------|-------------|
| Monitor list / data / report (processed WL) | Yes |
| Physical value (formulas use calibrated `w`) | Yes |
| `data/wl` and `data/pv` save | Yes |
| Modbus TCP holding registers | Yes |
| Precise refer (other feature) | Runs after this; input WL is the calibrated `w`. For lookup see [Precise refer](precise_refer.md) |
| Spectrum page / 7094 OS | **No** |
| Raw UDP file (`DS_SAVE_RAW`) | **No** |
| Internal `Etalon.Left/Right` | **No** |
| `:DATA:PV?` | **No** (raw cache) |

------

## 8. JSON :id=json

Truth: **`/var/sa/conf/precise_wl.json`**. The addon tab `precise_wl/index.json` points at the same basename (`getjson` prefers the top-level file).

| ID | Type | Default | Meaning |
|----|------|---------|---------|
| `WLCAL_ENABLE` | bool | false | Master switch |
| `WLCAL_CHANNEL` | num 1–32 | 16 | Etalon channel (spectrum on this unit; factory **16**, not 9) |
| `WLCAL_SPACING` | num 50–2000 | 800 | Nominal spacing pm |
| `WLCAL_OUTPUT` | bool | false | Output matched etalon-channel peaks only |
| `WLCAL_EXTEND` | bool | true | Extrapolate outside range |
| `WLCAL_WAVELENGTHS` | str | empty | Known list |

------

## 9. Verify (cal off vs on) :id=verify

1. Confirm the channel with [§2](#find). Set `WLCAL_CHANNEL`, import the wavemeter CSV, pick the nearest nominal spacing.
2. **Disable**, tick **Output**, Save (`:SYS:RELOAD` → 0). With `:DATA:PVJ?` record:
   - etalon peak count and greedy **scan bias** vs the table (measured − true);
   - other-channel sensor wavelengths.
3. **Enable**, keep Output on, capture the same set.
   - Matched comb teeth should sit on the table (residual ≪ scan bias; float quantisation ~0.5 pm);
   - in-range sensors should move by about the local scan bias;
   - out-of-range sensors move only if Extend is on, using the same all-points fit (not two neighbouring lines).
4. Turn **Output** off: the etalon channel disappears; neighbours stay.
5. Disable: uncorrected demodulator wavelengths return.
6. Leave Output off afterwards unless you want a live table comparison.

### 9.1 Lab numbers (examples only)

**Table A — fibre moved, etalon on software 16, array on 5** (2026-09-14 afternoon, 24 nm lines, spacing 800, extend on, 30-frame medians). Factory channel default is **16**.

| | Cal off | Cal on |
|--|---------|--------|
| Etalon CH16 vs table | median **+22.2 pm** (max ~+50) | residual ~**0.5 pm** (SA1 integer pm) |
| Etalon peak count | 32 (comb) | Output on keeps matched table lines (24) |
| CH5 array 32 peaks (1524.98–1549.39 nm) | — | on − off **−15 to −38 pm**, median **−26.5 pm** |
| CH1 ~1520 nm (outside, extend) | — | about **−11 pm** |

**Table B — earlier misplug, software channel 9** (same unit, same 24-line table; not a default):

| | Cal off | Cal on |
|--|---------|--------|
| Etalon channel vs table | median **+192 pm** (~+160 to +230) | residual ~**0.5 pm** |
| Etalon peak count | 32 (comb) | Output on keeps matched table lines |
| CH1 1528.188 nm (in table) | — | about **−200 pm** |
| CH4 1532.271 / 1540.634 nm | — | about **−168 / −190 pm** |
| CH1 1520.425 nm (outside) | — | about **+10 pm** (extend, not a miss) |

------

## 10. Lab wavelength list :id=example

Values are **nm**. Not every comb tooth is present. Set the channel the **spectrum on this unit** shows (factory default **16**; do not treat a misplug on 9 as the default) and spacing **800**:

```
1527.2844
1528.0249
1528.7920
1529.5858
1530.3638
1531.1430
1531.9452
1532.7098
1533.5026
1534.2782
1535.0706
1535.8553
1536.6368
1537.4179
1538.2190
1539.0141
1539.7965
1540.5907
1541.3823
1542.1759
1542.9635
1543.7635
1544.5563
1545.3528
```

------

## 11. Troubleshooting :id=trouble

| Symptom | Check |
|--------|--------|
| Nothing changes | Enable is off; list has &lt; 2 numbers; `:SYS:RELOAD` was not run; you are looking at spectrum / raw / **`:DATA:PV?`** |
| Log `match failed` / `has n peaks` | Wrong channel (re-check on the spectrum); threshold hiding etalon peaks; spacing so small the gate cannot pair; list in the wrong unit |
| Only some peaks move | Extend is off and those peaks sit outside the matched range |
| Out-of-range sensors jump by hundreds of pm | Old extend used two neighbouring lines; an FP table is not equally spaced in wavelength. Now fits all matched wavelengths together |
| Etalon channel missing | **Output** is off and match succeeded — intended |
| Too many wavelengths on the etalon after enable | Older builds kept unmatched comb teeth; 2.6.6.37 keeps only table lines when Output is on |
| PV looks worse | Sensor `wl0` was fitted on uncorrected wavelengths; re-fit or keep this function off |
| SA2 is also running | **Mutex**: stop SA2 before SA1. Same UDP **8190** / 7090 / 8080 |
| Page empty after upgrade | New JSON is merged in; if persist never had the file, the package copies it |
| Wavelength stream stopped after spectrum check | Still in OS mode; send `:DATA:ODT WAV` |
| Match fails after filling 9 | Factory default is **16**, not 9. Re-confirm on this unit’s spectrum |

Do not `killall -9`. Do not `sync-runtime.sh --conf` onto persist.

------

## 12. Ask (offline + chat) :id=ask

Chat: http://112.74.47.129:9999 (say **SA1 2.x** / `sa-di`, not `install_sa2.sh`). On-device: [ask.md](ask.md). Portal FAQ: 标准具 / precise wavelength / PVJ / 22 pm.

| Q | A |
|----|---|
| Does enable work? How much better? | Yes. Vs wavemeter, scan bias ~**+22 pm** (etalon on 16 on that lab unit) falls to ~**0.5 pm**. Earlier misplug on 9 was +192 pm → 0.5 pm. See [§gain](#gain). |
| Why did sensors move ~25 pm? | That is the correction (on − off), matching local scan bias. |
| Why `:DATA:PV?` unchanged? | Raw cache. Use `:DATA:PVJ?` / `get_phy_data.php` / `sa-cli scpi ':DATA:PVJ?'`. |
| CLI toggle? | Edit `WLCAL_ENABLE`, `sa-cli reload --yes`. [§CLI](#cli). |
| Channel 1 empty? | Factory default is **16**. Channel 1 is often empty. Confirm on the spectrum; a lab misplug once showed 9. |
| Outside-table move of hundreds of pm? | Old two-point slope. Now least-squares over all matched pairs. |
| How do I enable precise refer? | **Wrong page.** Setting → **Precise refer**, per-sensor lookup. [Precise refer](precise_refer.md) · [Two features](precise_vs.md). |

------

## 13. Help surfaces :id=help

| Surface | Where |
|--------|--------|
| Device Help menu | Precise wavelength / 精确波长校准 |
| Addon Help button | this page |
| Handbook (`help/tips/`) | SAH2026091302 Precise wavelength |
| Portal FAQ / hub search | 标准具 / etalon / spectrum channel |
| Online | `http://192.168.3.9/sa1/help/#/precise_wl` · `sc.casstk.com/sa1/help/` |
| Chat | http://112.74.47.129:9999 (say **SA1 2.x**) |
| On-device ask | [ask.md](ask.md) |
| SA2 (3.x) | Independent page `/wl-calibrate` and `wl_calibrate.json` — do not copy `web/` / `conf/` |

| Rev | Date | Note |
|-----|------|------|
|1.7|09/14/2026|Factory etalon channel is **16** (not 1; 9 remains a misplug example). Lab +22 pm / 0.5 pm are examples only.|
|1.6|09/14/2026|Special note: split from precise refer in Ask/FAQ; precise-refer questions do not belong here.|
|1.5|09/14/2026|CLI (sa-cli / PVJ / reload), accuracy (+22 pm→0.5 pm), CH5 array, ask; lab etalon later on 16 (still not factory).|
|1.4|09/14/2026|Fit all matched wavelengths together (OLS line). Do not use two neighbouring FP lines as a scan scale.|
|1.3|09/14/2026|Factory channel is 1; lab 9 was a misplug, not a default or recommended port.|
|1.2|09/14/2026|Spectrum channel ID, integration (do not use `:DATA:PV?`), verification table.|
|1.1|09/14/2026|Factory `WLCAL_OUTPUT` off; tick to compare vs the written table; CSV is nm (2.6.6.36).|
|1.0|09/13/2026|First release with sa-di piecewise calibration (2.6.6.35).|
