# OCPP 1.6j Migrate CSMS URL

After completing this procedure, the Charging Station will connect to a new CSMS URL.

> Available from firmware 4.2.85 & 3.5.54.

---

## Actors
- Charging Station having root certificates for CSMS 1 and CSMS 2 already installed.
- CSMS 1 (current backend)  having endpoint URL as wss://csms-1.example.com/ocpp
- CSMS 2 (new backend)  having endpoint URL as wss://csms-2.example.com/ocpp

---

## Prerequisite
- The **CSMS 2 root certificate** must already be installed on the Charging Station.
- Ensure the Charging Station is **added and whitelisted/authorized** in the new CSMS 2 backend before starting the migration process.

---

## OCPP Configuration Keys used during the migration process

The following configuration keys must be available via `GetConfiguration`:

- `NetworkConnectionProfile1`
- `NetworkConnectionProfile2`
- `NetworkConfigurationPriority`
- `NetworkProfileConnectionTimeoutSec`

Refer to document [OCPP 1.6j Configuration Settings](ocpp-settings.md#networkconnectionprofile1)

---

## Migration Procedure showing migration from CSMS-1 to CSMS-2

### 1. Retrieve Current Network Configuration

Send `GetConfiguration.req` from the CSMS-1 OCPP backend and note the values of:

- `NetworkConnectionProfile1`
- `NetworkConnectionProfile2`
- `NetworkConfigurationPriority`

#### Example Response snippet
```json
[
  3,
  "d3931e2a-fc0c-4068-9935-cf2221646620",
  {
    "configurationKey": [
      {
        "key": "NetworkConnectionProfile1",
        "readonly": false,
        "value": "wss://csms-1.example.com/ocpp"
      },
      {
        "key": "NetworkConnectionProfile2",
        "readonly": false,
        "value": ""
      },
      {
        "key": "NetworkConfigurationPriority",
        "readonly": false,
        "value": "NetworkConnectionProfile1,NetworkConnectionProfile2"
      }
    ]
  }
]
```

## Step 2 — Configure New CSMS URL

The `NetworkConfigurationPriority` value indicates which CSMS URL is currently in use.

From Step 1, since the value is:

`NetworkConnectionProfile1,NetworkConnectionProfile2`

this means:

- **NetworkConnectionProfile1** → Currently active CSMS
- **NetworkConnectionProfile2** → Available to configure with the new CSMS URL

Therefore, we will use **NetworkConnectionProfile2** to set the new CSMS 2 URL.

Set the value of `NetworkConnectionProfile2` to:

`wss://csms-2.example.com/ocpp`

using a `ChangeConfiguration.req` command.

> **Important:**
> - Do **not** include quotes inside the value itself.
> - The value must **not** include the Charging Station identity.
> - The value must **not contain any whitespace** (no spaces, tabs, or line breaks).
> - The request must return a status of **"Accepted"** before proceeding.

---

### Sample ChangeConfiguration Request

```json
[
  2,
  "a1bc4eed-1eb0-461d-9dd0-5977a165e90a",
  "ChangeConfiguration",
  {
    "key": "NetworkConnectionProfile2",
    "value": "wss://csms-2.example.com/ocpp"
  }
]
```

### Sample ChangeConfiguration Response

```json
[
  3,
  "a1bc4eed-1eb0-461d-9dd0-5977a165e90a",
  { "status": "Accepted" }
]
```

## Step 3 — Update Network Configuration Priority

Next, update the `NetworkConfigurationPriority` so that the newly configured network profile becomes the **highest priority** connection.

In this example, since the new CSMS URL was set in `NetworkConnectionProfile2`, we must update the priority order to:

`NetworkConnectionProfile2,NetworkConnectionProfile1`

This ensures the Charging Station will attempt to connect to **CSMS 2 first** after reboot.

> **Important:**
> - The value must **not contain any whitespace** (no spaces, tabs, or line breaks).
> - The response to this request is expected to be **"RebootRequired"**.
> - A Charging Station reboot is necessary for the new priority to take effect.

---

### Sample ChangeConfiguration Request

```json
[
  2,
  "990d9cab-fa79-47dc-8464-af542080f614",
  "ChangeConfiguration",
  {
    "key": "NetworkConfigurationPriority",
    "value": "NetworkConnectionProfile2,NetworkConnectionProfile1"
  }
]
```

### Sample ChangeConfiguration Response

```json
[
  3,
  "990d9cab-fa79-47dc-8464-af542080f614",
  { "status": "RebootRequired" }
]
```

## Step 4 — Reboot the Charging Station

Reboot the Charging Station from the backend to apply the updated network configuration.

Send a **Reset** using the `Reset.req` command.

---

### Sample Reset Request

```json
[
  2,
  "100ae5aa-a168-47c8-827e-4cd250b2055a",
  "Reset",
  { "type": "Hard" }
]
```

### Sample ChangeConfiguration Response

```json
[
  3,
  "100ae5aa-a168-47c8-827e-4cd250b2055a",
  { "status": "Accepted" }
]
```

## Step 5 — Verify Connection

After the Charging Station reboots:

- The Charging Station should now connect to the **new CSMS**.
- A **BootNotification** is received by the new backend, confirming successful connection.
- Ensure normal operation resumes and the Charging Station is communicating with CSMS 2.

---

## Step 6 — Finalizing migration

Once migration is verified:

- Request the operator of the **old CSMS** to remove the Charging Station from their backend.
- Confirm that the old CSMS no longer shows the Charging Station as active.

---

## Step 7 - Cleanup (optional)

Once done, you may optionally remove the previous `NetworkConnectionProfile1` csms url, by writing an empty string to the value.

---

## CSMS Migration Flow Diagram

```{mermaid}
sequenceDiagram
    participant CSMS1
    participant Charging Station
    participant CSMS2

    CSMS1->>Charging Station: GetConfiguration.req
    Charging Station-->>CSMS1: GetConfiguration.conf

    CSMS1->>Charging Station: ChangeConfiguration(NetworkConnectionProfile2 = wss://csms-2.example.com/ocpp)
    Charging Station-->>CSMS1: Accepted

    CSMS1->>Charging Station: ChangeConfiguration(NetworkConfigurationPriority = NetworkConnectionProfile2,NetworkConnectionProfile1)
    Charging Station-->>CSMS1: RebootRequired

    CSMS1->>Charging Station: Reset.req (Hard)
    Charging Station-->>CSMS1: Accepted

    Note over Charging Station: Charging Station Reboots

    Charging Station->>CSMS2: Connect to new URL
    Charging Station->>CSMS2: BootNotification.req
    CSMS2-->>Charging Station: BootNotification.conf

    Note over CSMS1: Remove Charging Station from old backend
```