HarmonyOS Native SDK
Device Discovery
LAN Discovery

LAN Discovery

GizLanManager discovers devices through UDP broadcast. Initialize the core and LAN modules first, and keep the phone and device on the same network with broadcast traffic allowed.

Observe discovered devices

import { GizDevice } from '@gizwits/smart-sdk';
import { GizLanManager } from '@gizwits/smart-sdk-lan';
 
let lanDevices: Array<GizDevice> = [];
const unsubscribeLan = GizLanManager.subscribeLanDeviceList().subscribe(
  (devices: Array<GizDevice>): void => {
    lanDevices = devices;
  }
);

Start discovery

await GizLanManager.startDiscovery();

This creates UDP sockets, broadcasts a discovery request, and refreshes periodically.

Refresh immediately

await GizLanManager.refreshDiscovery();

It broadcasts immediately when discovery is running, or starts discovery when needed.

Read discovery state

const discovering: boolean = GizLanManager.isDiscovering();

Stop discovery

await GizLanManager.stopDiscovery();
unsubscribeLan();

The SDK closes sockets and marks current LAN devices offline.

Read profiles and low-level sessions

const profile = GizLanManager.getProfile(device.id);
const session = GizLanManager.getSession(device.id);

Normal applications should communicate through device.lanCapability and should not manage GizLanDeviceSession directly.

If no device appears, check the current Wi-Fi network, GET_WIFI_INFO permission, AP isolation, guest-network restrictions, and router broadcast policy.