arduino-esp32/libraries/OpenThread/examples/ThreadScan/ThreadScan.ino
Rodrigo Garcia d891ddfec7
New OpenThread CLI Arduino Library for ESP32-C6 and ESP32-H2 (#9908)
* feat(OThread): Add Library

* fix(OpenThread): fixes file list in CMakeLists.txt

* fix(openthread): Fixes JSON CI Files

* fix(openthread): Fixes JSON CI Files

* fix(openthread): Include Openthread guarding

* fix(openthread): COAP parametrization

* fix(openthread): Include Openthread guarding

* fix(openthread): Improves commentaries and code

* fix(openthread): Improves code

* fix(openthread): Includes StreamString.h

* feat(openthread): New Scan Example

* feat(openthread): Improved Scan Example

* feat(openthread): README.md

Initial documentation for ESP3 Arduino OpenThread CLI API.

* feat(openthread): helper functions documentation

Create helper_functions.md for ESP32 Arduino OpenThread API

* fix(openthread): begin end

* feat(openthread): onReceice example

* fix(openthread): tx queue error

* fix(doc): fixing documentation apresentation

Fixes the documentation first paragraph in order to make it easier fore reading. It also displays in the very top which SoC are supported by the library.

* fix(doc): documentation format

* feat(openthread): commentary

* fix(openthread): Typo, start/stop console

* fix(openthread): library properties

* ci(pre-commit): Apply automatic fixes

* feat(openthread): formatting text

* ci(pre-commit): Apply automatic fixes

---------

Co-authored-by: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com>
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
2024-06-24 19:26:42 +03:00

41 lines
1.3 KiB
C++

/*
OpenThread.begin(true) will automatically start a node in a Thread Network
Full scanning requires the thread node to be at least in Child state.
This will scan the IEEE 802.14.5 devices in the local area using CLI "scan" command
As soon as this device turns into a Child, Router or Leader, it will be able to
scan for Local Thread Networks as well.
*/
#include "OThreadCLI.h"
#include "OThreadCLI_Util.h"
void setup() {
Serial.begin(115200);
OThreadCLI.begin(true); // For scanning, AutoStart must be active, any setup
OThreadCLI.setTimeout(100); // Set a timeout for the CLI response
Serial.println();
Serial.println("This sketch will continuously scan the Thread Local Network and all devices IEEE 802.15.4 compatible");
}
void loop() {
Serial.println();
Serial.println("Scanning for nearby IEEE 802.15.4 devices:");
// 802.15.4 Scan just needs a previous OThreadCLI.begin()
if (!otPrintRespCLI("scan", Serial, 3000)) {
Serial.println("Scan Failed...");
}
delay(5000);
if (otGetDeviceRole() < OT_ROLE_CHILD) {
Serial.println();
Serial.println("This device has not started Thread yet, bypassing Discovery Scan");
return;
}
Serial.println();
Serial.println("Scanning MLE Discover:");
if (!otPrintRespCLI("discover", Serial, 3000)) {
Serial.println("Discover Failed...");
}
delay(5000);
}