libraries/OpenThread/examples/Native/ThreadScan/ThreadScan_Discover/README.md
Part of the Thread Network Discovery demo. This sketch:
begin(false) (no NVS auto-load),networkInterfaceUp() (Thread start not required),OThreadScan.discoverNetworks() in blocking mode every 10 seconds,OThreadNetworkInfo (network name, Extended PAN ID, PAN ID,
extended address, channel, RSSI, LQI, joinable flag),scanDelete() after each scan.It demonstrates the WiFiScan-style blocking pattern on Thread MLE discover
(otThreadDiscover() / CLI discover).
| SoC | Thread | Status |
|---|---|---|
| ESP32-H2 | yes | Supported |
| ESP32-C6 | yes | Supported |
| ESP32-C5 | yes | Supported |
| Feature | Why |
|---|---|
CONFIG_OPENTHREAD_ENABLED=y | Build the OpenThread stack. |
CONFIG_SOC_IEEE802154_SUPPORTED=y | Ensure the SoC has the 802.15.4 radio. |
LeaderNode (network former) must be running as Leader within RF range.
Flash the Leader first and wait for Role: Leader, then flash this sketch on
a second board.
// 1) Stack + IPv6 interface only (no Thread start).
OThread.begin(false);
OThread.networkInterfaceUp();
// 2) Blocking discover every 10 s in loop().
int n = OThreadScan.discoverNetworks();
for (int i = 0; i < n; ++i) {
const OThreadNetworkInfo &net = OThreadScan.getResult(i);
// print net.networkName, net.extendedPanIdStr(), net.panId, ...
}
OThreadScan.scanDelete();
Setup done — IPv6 interface up, Thread start not required
Thread discovery start
Thread discovery done
1 network(s) found
Nr | J | Network Name | Extended PAN | PAN | MAC Address | CH | dBm | LQI
1 | 1 | ESP_OpenThread | dead00beef00cafe | 1234 | aabbccddeeff0011 | 15 | -45 | 255
-------------------------------------
When no Leader is nearby:
Thread discovery start
Thread discovery done
no Thread networks found
-------------------------------------
On failure:
Thread discovery start
Thread discovery done
discovery failed (interface down, lock failure, or timeout)
-------------------------------------
If a previous scan is still running:
Thread discovery start
Thread discovery done
discovery already in progress (OT_DISCOVER_RUNNING)
-------------------------------------
The library keeps at most OT_DISCOVER_MAX_RESULTS unique networks per scan
(default 16). This sketch raises the limit to 32 for denser RF environments:
#define OT_DISCOVER_MAX_RESULTS 32
#include "OThreadScan.h"
The #define must appear before #include "OThreadScan.h" (in your .ino
or in a header included before it). You can also pass it from the build system, e.g.
-DOT_DISCOVER_MAX_RESULTS=32. Higher values use more RAM because result vectors
are pre-reserved to that size before each scan.
Discovery timeout defaults to 30 seconds in the library. Adjust before calling
discoverNetworks():
OThreadScan.setScanTimeout(60000); // ms
Limit to one channel (11..26) with OThreadScan.setChannel(15); 0 scans all
supported channels.
Startup order: Start LeaderNode (network former) first and wait for
Role: Leader. Then flash this sketch.
| Symptom | Likely cause |
|---|---|
no Thread networks found | Leader not running or out of range — start Leader on another board. |
discovery failed | Interface down, lock failure, or timeout — ensure networkInterfaceUp() was called; try a longer setScanTimeout(). |
discovery already in progress | Previous scan still running (OT_DISCOVER_RUNNING) — wait for it to finish or call scanDelete() after completion. |
| Wrong network name / XPAN | Multiple Thread networks nearby — compare Extended PAN ID with the Leader. |
| No serial output | Serial Monitor not at 115200. |
scanComplete() polling.discover command).Apache License 2.0.