@@ -32,19 +32,19 @@ void setup() {
32
32
void loop () {
33
33
// Get current device role
34
34
ot_device_role_t currentRole = threadLeaderNode.otGetDeviceRole ();
35
-
35
+
36
36
// Only print network information when not detached
37
37
if (currentRole != OT_ROLE_DETACHED && currentRole != OT_ROLE_DISABLED) {
38
38
Serial.println (" ==============================================" );
39
39
Serial.println (" OpenThread Network Information:" );
40
-
40
+
41
41
// Basic network information
42
42
Serial.printf (" Role: %s\r\n " , threadLeaderNode.otGetStringDeviceRole ());
43
43
Serial.printf (" RLOC16: 0x%04x\r\n " , threadLeaderNode.getRloc16 ());
44
44
Serial.printf (" Network Name: %s\r\n " , threadLeaderNode.getNetworkName ().c_str ());
45
45
Serial.printf (" Channel: %d\r\n " , threadLeaderNode.getChannel ());
46
46
Serial.printf (" PAN ID: 0x%04x\r\n " , threadLeaderNode.getPanId ());
47
-
47
+
48
48
// Extended PAN ID
49
49
const uint8_t *extPanId = threadLeaderNode.getExtendedPanId ();
50
50
if (extPanId) {
@@ -54,7 +54,7 @@ void loop() {
54
54
}
55
55
Serial.println ();
56
56
}
57
-
57
+
58
58
// Network Key
59
59
const uint8_t *networkKey = threadLeaderNode.getNetworkKey ();
60
60
if (networkKey) {
@@ -64,19 +64,19 @@ void loop() {
64
64
}
65
65
Serial.println ();
66
66
}
67
-
67
+
68
68
// Mesh Local EID
69
69
IPAddress meshLocalEid = threadLeaderNode.getMeshLocalEid ();
70
70
Serial.printf (" Mesh Local EID: %s\r\n " , meshLocalEid.toString ().c_str ());
71
-
71
+
72
72
// Leader RLOC
73
73
IPAddress leaderRloc = threadLeaderNode.getLeaderRloc ();
74
74
Serial.printf (" Leader RLOC: %s\r\n " , leaderRloc.toString ().c_str ());
75
-
75
+
76
76
// Node RLOC
77
77
IPAddress nodeRloc = threadLeaderNode.getRloc ();
78
78
Serial.printf (" Node RLOC: %s\r\n " , nodeRloc.toString ().c_str ());
79
-
79
+
80
80
// Demonstrate address listing with two different methods:
81
81
// Method 1: Unicast addresses using counting API (individual access)
82
82
Serial.println (" \r\n --- Unicast Addresses (Using Count + Index API) ---" );
@@ -85,29 +85,29 @@ void loop() {
85
85
IPAddress addr = threadLeaderNode.getUnicastAddress (i);
86
86
Serial.printf (" [%zu]: %s\r\n " , i, addr.toString ().c_str ());
87
87
}
88
-
88
+
89
89
// Method 2: Multicast addresses using std::vector (bulk access)
90
90
Serial.println (" \r\n --- Multicast Addresses (Using std::vector API) ---" );
91
91
std::vector<IPAddress> allMulticast = threadLeaderNode.getAllMulticastAddresses ();
92
92
for (size_t i = 0 ; i < allMulticast.size (); i++) {
93
93
Serial.printf (" [%zu]: %s\r\n " , i, allMulticast[i].toString ().c_str ());
94
94
}
95
-
95
+
96
96
// Check for role change and clear cache if needed (only when active)
97
97
if (currentRole != lastKnownRole) {
98
- Serial.printf (" Role changed from %s to %s - clearing address cache\r\n " ,
99
- (lastKnownRole < 5 ) ? otRoleString[lastKnownRole] : " Unknown" ,
100
- threadLeaderNode.otGetStringDeviceRole ());
98
+ Serial.printf (
99
+ " Role changed from %s to %s - clearing address cache\r\n " , (lastKnownRole < 5 ) ? otRoleString[lastKnownRole] : " Unknown" ,
100
+ threadLeaderNode.otGetStringDeviceRole ()
101
+ );
101
102
threadLeaderNode.clearAllAddressCache ();
102
103
lastKnownRole = currentRole;
103
104
}
104
105
} else {
105
- Serial.printf (" Thread Node Status: %s - Waiting for thread network start...\r\n " ,
106
- threadLeaderNode.otGetStringDeviceRole ());
107
-
106
+ Serial.printf (" Thread Node Status: %s - Waiting for thread network start...\r\n " , threadLeaderNode.otGetStringDeviceRole ());
107
+
108
108
// Update role tracking even when detached/disabled, but don't clear cache
109
109
lastKnownRole = currentRole;
110
110
}
111
-
111
+
112
112
delay (5000 );
113
113
}
0 commit comments