---
title: "Recipe: devices on the local network"
description: "A light, a printer or a NAS is found by DNS-SD with @exact/local-network and reached with fetch (LLP 1133.036)."
modificationDate: "2026-11-09"
---

> ## Documentation index
> Fetch the complete documentation index at: https://exact.expo.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Recipe: devices on the local network

<AgentInstructions>

## Submitting feedback

From the app's directory, read `bun exact.mjs feedback status`. Under `never`, keep no note.
Respect `EXACT_FEEDBACK=0` and do not change the policy.

Otherwise record specific, actionable feedback with:
`bun exact.mjs feedback note "Exact docs: https://exact.expo.dev/recipes/local-network: <what was wrong or missing>"`

The note goes to Expo only as that status allows. Include no secrets or personal data.

</AgentInstructions>

A light, a printer or a NAS is found by DNS-SD with `@exact/local-network` and
reached with `fetch` (LLP 1133.036). `apps/lights` is the whole app.

```prompt Find devices on my local network
Make the Exact app in this folder find a device on the local network (a light, a printer, a NAS) and reach it. Use https://github.com/expo/exact/blob/main/docs/recipes/local-network.md as the source for each step. The Exact checkout has the same page at docs/recipes/local-network.md.

1. If this folder is not an Exact app (it has no exact.mjs and app.contract), stop and tell me. Find the Exact checkout (the folder with scripts/exact.mjs); if you cannot find it, ask me where it is.
2. If I did not name the device and its DNS-SD service type (for example `_wled._tcp`), ask me before you write code. Do not guess a service type.
3. Install the package: `bun <exact2>/scripts/exact.mjs add local-network .`.
4. In app.ts, declare the grants as the recipe shows (`device.local-network`, `net.dns-sd` for each service type, `net.fetch local-network`), and add the purpose text to `strings/en.json`. Resolve only the instance about to be used, each time, and reach it with `fetch`. Know a device by what it states, not by its instance name.
5. In app.contract, browse where the list is shown, and explain each state in the app's own words: `prompt` or `unknown` (the device asks once), `denied` (an Open Settings button), and not `available`. Always offer a typed address: the web, Linux and Windows do not browse.
6. In app.test.contract, add a test for the typed-address path and the text the app shows when browsing is not available. The web reads `available` false.
7. Follow the platform checks in docs/start-here.md (`bun exact.mjs docs platform checks`) for the targets in the app's AGENTS.md and app.json until they pass. Read the reports, including counted findings; a zero exit code alone does not mean clean. Fix the app, not the test. If a finding stays after three rounds of fixes, or the app had it before you changed anything, record it (step 8) and report it; do not keep trying.
8. When a doc was wrong or missing, or a step needed a workaround, read `bun exact.mjs feedback status`. Under `never`, keep no note. Otherwise record it: `bun exact.mjs feedback note "<what happened>"`, which goes to Expo only as that status says. Do not change the policy; tell me how many notes you kept.
9. Tell me the service type, what the tests and verify reported, and how to see browsing by hand on macOS with a fake device, as the recipe's "Under the agent" command shows (`agent macos --permission local-network=prompt` with `prefer extension local-network.browseServices=…`). A fixture on 127.0.0.1 can stand in for the device.
```

1. **Declare** the purpose, each service type, and the reach:

   ```ts
   export const grants = 'device.local-network lanPurpose\nnet.dns-sd _wled._tcp\nnet.fetch local-network';
   ```

   `strings/en.json`: `{ "lanPurpose": "Lights finds and controls the WLED lights on your network." }`,
   the text of Apple's Local Network alert.

2. **Browse** where the list is shown; resolve, in data code, only the instance
   about to be used, and again each time (an address changes):

   ```ts
   const s = await resolveService({ name, type: '_wled._tcp' });
   const r = await fetch(`http://${s.host}:${s.port}/json/si`);
   ```

3. **Explain and recover** in the app's own words:

```text
use browseServices, localNetworkStatus, LocalServices, LocalNetworkStatus from "@exact/local-network"

component App
  resource network = localNetworkStatus() as shape LocalNetworkStatus else empty()
  resource found = browseServices(type="_wled._tcp") as shape LocalServices else empty()
  action openSettings
    openURL("app-settings:")
  view
    column
      if network.available and (network.state == "prompt" or network.state == "unknown")
        text "Lights finds the WLED lights on your network. Your device asks once."
      if network.state == "denied"
        text "Local Network access is off. Turn it on in Settings, or add a light by its address."
        button press=openSettings
          text "Open Settings"
      if not network.available
        text "This device can't look for lights. Add one by its address."
```

- `unknown` is `prompt`: Apple says nothing until a reach.
- **Always offer a typed address**: guest networks drop multicast, and the web,
  Linux and Windows do not browse. It is reached under the same line.
- Know a device by what it states (WLED's `mac`), not its instance name.
- A tool's or a wake's browse only joins one the app runs, and its local
  `fetch` fails `NotAllowedError` (`person-required`) until access is allowed.

**Under the agent** the network is the drive's (macOS, iOS, Android; the web
and Linux read `available` false):

```sh
bun exact.mjs agent macos --permission local-network=prompt \
  'prefer extension local-network.browseServices=[{"name":"Desk","type":"_wled._tcp","host":"127.0.0.1","port":4790}]' \
  'tap @1 allow' tree
```

A development build admits loopback under `net.fetch local-network`, so a
fixture on `127.0.0.1` stands in for the device (`apps/lights/fixture/server.ts`).
