Skip to content

TPLinkDiscovery Class

Namespace: TPLinkSmartDevices

handles discovery of new smart devices and connection of factory new devices to a network

Properties

DiscoveredDevices

Returns a list of TPLinkSmartDevice's from the latest call of .Discover(). This property is read-only.
public List<TPLinkSmartDevice> DiscoveredDevices { get; private set; }

Methods

Discover(int, int, string)

Discovers smart devices within the network of the host via UDP broadcast. Returns a list of TPLinkSmartDevice's.

public async Task<List<TPLinkSmartDevice>> Discover(int port=9999, int timeout=5000, string target="255.255.255.255")

Parameters
  • int port: Listen to broadcast responses on this port, defaults to 9999
  • int timeout: Timespan after which the discovery finishes, defaults to 5000(5 seconds)
  • string target: ip address of discovery broadcast, defaults to 255.255.255.255

Tip

The discovery of devices within a network fails under certain circumstances. Some routers seem to block udp packets to the broadcast address (255.255.255.255), which is used to send out a discovery request. In case of using different subnet's, what seems to resolve the issue is broadcasting to the subnet's local broadcast IP (such as 192.168.0.255, if IP is 192.168.0.X with a subnet mask of 255.255.255.0)

Associate(string, string, int)

Makes smart device connect to specified network credentials

public async Task Associate(string ssid, string password, int type = 3)

Parameters
  • string ssid: Service Set Identifier (name) of network to connect to
  • string password: password of network to connect to
  • int type: network protection level, defaults to 3 indicating WPA2

Caution

Host who runs the application needs to be connected to the open configuration network! (TP-Link_Smart Plug_XXXX or similar)

Events

DeviceFound

Triggers when smart device is found during discovery process, granting access to all system properties of that device via the event args

public event EventHandler<DeviceFoundEventArgs> DeviceFound;

EventArgs
  • DeviceFoundEventArgs e
Example
new TPLinkDiscovery().DeviceFound += (s, e) {
    ...
    Console.WriteLine($"Device found: {e.Device.Alias}");
    ...
};