-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] Display in the console the network identifier to which the card is connected, in addition to the role #10295
Comments
@SuGlider Can you please take a look? |
I've managed to display all the information using the void loop() {
Serial.print("Thread Node State: ");
Serial.println(otGetStringDeviceRole());
// Prints information about the current Thread network
// https://github.com/espressif/arduino-esp32/blob/master/libraries/OpenThread/helper_functions.md
Serial.println("Thread NetworkInformation: ");
Serial.println("---------------------------");
otPrintNetworkInformation(Serial);
Serial.println("---------------------------");
delay(5000);
} Here is the result:
|
To compare, I manually entered the CLI commands with the example SimpleCLI.ino I can see that it works properly:
|
@lboue - Yes, there are two ways to obtain the PANID of the current connected network.
char resp[32];
otGetRespCmd("panid", resp); It seems that there is a synchronization problem with the CLI method. Anyway, the first method works fine.Example: #include "OThreadCLI.h"
#include "OThreadCLI_Util.h"
// Leader node shall use the same Network Key and channel
#define CLI_NETWORK_KEY "dataset networkkey 00112233445566778899aabbccddeeff"
#define CLI_NETWORK_CHANEL "dataset channel 24"
void setup() {
Serial.begin(115200);
OThreadCLI.begin(false); // No AutoStart - fresh start
Serial.println("Setting up OpenThread Node as Router/Child");
Serial.println("Make sure the Leader Node is already running");
OThreadCLI.println("dataset clear");
OThreadCLI.println(CLI_NETWORK_KEY);
OThreadCLI.println(CLI_NETWORK_CHANEL);
OThreadCLI.println("dataset commit active");
OThreadCLI.println("ifconfig up");
OThreadCLI.println("thread start");
// wait for the node to enter in the router state
uint32_t timeout = millis() + 90000; // waits 90 seconds to
bool nodeIsReady = true;
while (otGetDeviceRole() != OT_ROLE_CHILD && otGetDeviceRole() != OT_ROLE_ROUTER) {
Serial.print(".");
if (millis() > timeout) {
Serial.println("\r\n\t===> Timeout! Failed.");
nodeIsReady = false;
break;
}
delay(500);
}
if (nodeIsReady) {
// print the PanID using 2 methods
// CLI
char resp[32];
if (otGetRespCmd("panid", resp)) {
Serial.printf("\r\nPanID[using CLI]: %s\r\n", resp);
} else {
Serial.printf("\r\nPanID[using CLI]: FAILED!\r\n");
}
// OpenThread API
Serial.printf("PanID[using OT API]: %x\r\n", (uint16_t) otLinkGetPanId(esp_openthread_get_instance()));
}
}
void loop() {
} |
I found out that the CLI sends a "Done" for a previous command and this causes a shift with the CLI responses. As I wrote above, |
Thank you very much. I'll give it a try. |
OK.... I've got the issue. The code executes many In order to fix it, the code shall be this: #include "OThreadCLI.h"
#include "OThreadCLI_Util.h"
// Leader node shall use the same Network Key and channel
#define CLI_NETWORK_KEY "dataset networkkey 00112233445566778899aabbccddeeff"
#define CLI_NETWORK_CHANEL "dataset channel 24"
bool otStatus = true;
void setup() {
Serial.begin(115200);
OThreadCLI.begin(false); // No AutoStart - fresh start
Serial.println("Setting up OpenThread Node as Router/Child");
Serial.println("Make sure the Leader Node is already running");
char resp[256];
otStatus &= otGetRespCmd("dataset clear", resp);
otStatus &= otGetRespCmd(CLI_NETWORK_KEY, resp);
otStatus &= otGetRespCmd(CLI_NETWORK_CHANEL, resp);
otStatus &= otGetRespCmd("dataset commit active", resp);
otStatus &= otGetRespCmd("ifconfig up", resp);
otStatus &= otGetRespCmd("thread start", resp);
if (!otStatus) {
Serial.println("\r\n\t===> Failed starting Thread Network!");
return;
}
// wait for the node to enter in the router state
uint32_t timeout = millis() + 90000; // waits 90 seconds to
while (otGetDeviceRole() != OT_ROLE_CHILD && otGetDeviceRole() != OT_ROLE_ROUTER) {
Serial.print(".");
if (millis() > timeout) {
Serial.println("\r\n\t===> Timeout! Failed.");
otStatus = false;
break;
}
delay(500);
}
if (otStatus) {
// print the PanID using 2 methods
// CLI
if (otGetRespCmd("panid", resp)) {
Serial.printf("\r\nPanID[using CLI]: %s\r\n", resp);
} else {
Serial.printf("\r\nPanID[using CLI]: FAILED!\r\n");
}
// OpenThread API
Serial.printf("PanID[using OT API]: 0x%x\r\n", (uint16_t) otLinkGetPanId(esp_openthread_get_instance()));
}
Serial.println("\r\n");
}
void loop() {
if (otStatus) {
Serial.println("Thread Network Information: ");
Serial.println("---------------------------");
otPrintNetworkInformation(Serial);
Serial.println("---------------------------");
} else {
Serial.println("Some OpenThread operation has failed...");
}
delay(10000);
} Output
|
I'll add this example to the Arduino Core to help future users. |
Related area
OpenThread
Hardware specification
ESP32-C6, ESP32-H2
Is your feature request related to a problem?
Hello,
I'm using this example: RouterNode.ino to test the connection to my existing Thread network.
I want to make sure that my board is connected to the right network (PANID).
Is there any way of accessing this information and displaying it in the console?
Regards
Describe the solution you'd like
Display in the console the network identifier to which the card is connected, in addition to the role.
Describe alternatives you've considered
No response
Additional context
No response
I have checked existing list of Feature requests and the Contribution Guide
The text was updated successfully, but these errors were encountered: