> ## Documentation Index
> Fetch the complete documentation index at: https://docs.getmelody.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Connection & Time Sync

> Check Melody device server connection state and synchronize internal device time using WiFi transport over the Melody production API.

Use these endpoints to inspect and manage the Melody device's connection to the **Melody sensation server** over WiFi transport.

All requests are made against the single production API:

```text theme={null}
https://api.getmelody.io
```

Authentication for protected endpoints uses **JWT Bearer tokens**, with required headers:

```http theme={null}
Authorization: Bearer <SESSION_TOKEN>
X-Device-Key: <DEVICE_KEY>
Content-Type: application/json
```

***

## Server Connection Status *(Read)*

### Server Connection Status

| Field       | Type   | Description                                                               |
| ----------- | ------ | ------------------------------------------------------------------------- |
| `connected` | `bool` | Whether the device is currently connected to the haptics sensation server |

### Server Session Status

| Field             | Type     | Description                                                                                             |
| ----------------- | -------- | ------------------------------------------------------------------------------------------------------- |
| `deviceIpAddress` | `uint32` | Device IP represented as a 4‑byte integer (e.g., `192.168.1.100` → `0xC0A80164`)                        |
| `connectedAt`     | `uint32` | Unix timestamp when the WiFi/server connection was established                                          |
| `serverSyncTime`  | `uint32` | Device internal time (milliseconds since power‑on) when the last time‑sync was received from the server |

***

## Server Time Synchronization *(Write)*

### Server Sync Time

Use this command to synchronize the device’s internal clock/timeline reference with official server time.

**Purpose:**

* Align device playback timeline with media or scripting engines
* Ensure scripts using large millisecond timestamps (Melody engine, HPS streams) reference a consistent time source

Typical request body:

```json theme={null}
{
  "serverSync": true
}
```

This write endpoint may:

* Update internal device time offset
* Improve timeline accuracy for upcoming sensation sessions

> Always request this *after* a device joins WiFi for reliable scripted playback sync.

***

## Integration Tips

* Call **Server Connection Status** to confirm the device is connected before sending timeline-based or streamed commands.
* Convert IP values properly if displaying to users — backend value is a 32‑bit integer.
* Request **Server Time Sync** during onboarding or prior to scripted video/VR playback.
* Use `serverSyncTime` to validate that new commands use a **current timeline reference**.

For implementation-ready endpoint details and advanced request/response schemas, explore the **WiFi API section in your API Reference tabs**.
