# WiFi Management

Configure and manage WiFi credentials on the MD1.

## AP Mode (Setup Mode)

When no WiFi credentials are stored, the MD1 starts in Access Point mode:
- SSID: `MD1-Setup-XXXXXX` (XXXXXX = first 6 chars of MAC)
- IP: `192.168.4.1`

## Configure WiFi

```
POST /wifi
Content-Type: application/json
```

**Request Body:**
```json
{
  "ssid": "YourNetworkName",
  "password": "YourPassword"
}
```

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

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

The device temporarily connects to verify credentials before saving. If connection fails, credentials are not stored.

## Clear WiFi Credentials

```
GET /wifi/clear
```

**Response:**
```html
<p>WiFi credentials cleared. Reboot device to enter AP mode.</p>
```

After clearing, restart the device to enter AP mode.

## Restart Device

```
POST /restart
```

**Response:**
```json
{
  "status": "Success",
  "message": "Restarting..."
}
```

## Factory Reset

Hold the **BOOT** button for 10+ seconds to:
- Clear WiFi credentials
- Clear device configuration
- Restart in AP mode

## Network Discovery (mDNS)

Once connected, the MD1 advertises via mDNS:
- Hostname: `swychmd1-XXXXXX.local`
- Service: `_http._tcp` on port 80
- Instance name: "Brewpilot Swych MD1"

Use mDNS to discover devices on your network without knowing their IP addresses.
