# Getting Started

This guide covers initial setup and your first API interaction with the MD1.

## Initial WiFi Setup

When the MD1 has no stored WiFi credentials, it automatically starts in **AP Mode**.

### Step 1: Connect to the MD1 Access Point

1. Power on the MD1
2. On your computer/phone, connect to WiFi network: `MD1-Setup-XXXXXX`  
   (XXXXXX = first 6 characters of the device MAC address)
3. Open a browser and navigate to `http://192.168.4.1`

### Step 2: Configure WiFi Credentials

Send a POST request to configure WiFi:

```bash
curl -X POST http://192.168.4.1/wifi \
  -H "Content-Type: application/json" \
  -d '{"ssid": "YourNetworkName", "password": "YourPassword"}'
```

**Response (Success):**
```json
{
  "success": true,
  "ip": "192.168.1.100",
  "mdns": "swychmd1-AABBCC.local"
}
```

**Response (Failure):**
```json
{
  "success": false,
  "message": "Failed to connect to WiFi. Check credentials."
}
```

## Finding Your Device

Once connected, the MD1 is discoverable via:

### mDNS (Recommended)
Access your device at: `http://swychmd1-XXXXXX.local`

### IP Address
Use the IP returned during WiFi setup, or check your router's connected devices.

## First API Call

Verify connectivity by fetching device info:

```bash
curl http://swychmd1-XXXXXX.local/api/devices
```

**Response:**
```json
{
  "AABBCCDDEEFF": {
    "id": "AABBCCDDEEFF",
    "firmware": "1.0.2",
    "model": "SwychTemp MD1",
    "states": {},
    "lastUpdated": "2026-02-01T06:00:00Z"
  }
}
```

## Factory Reset

To clear all settings and return to AP mode:
1. Hold the **BOOT** button for 10+ seconds
2. The device will restart in AP mode

Alternatively, clear settings via API:
```bash
curl http://device-ip/wifi/clear
```

## Next Steps

- [Configure Modbus devices](configuration.md)
- [Read device states](devices.md)
