1
1
/*
2
- * OpenThread.begin(false) will not automatically start a node in a Thread Network
3
- * A Router/Child node is the device that will join an existing Thread Network
4
- *
5
- * In order to allow this node to join the network,
6
- * it shall use the same network master key as used by the Leader Node
7
- * The network master key is a 16-byte key that is used to secure the network
8
- *
9
- * Using the same channel will make the process faster
10
- *
11
- */
2
+ OpenThread.begin(false) will not automatically start a node in a Thread Network
3
+ A Router/Child node is the device that will join an existing Thread Network
4
+
5
+ In order to allow this node to join the network,
6
+ it shall use the same network master key as used by the Leader Node
7
+ The network master key is a 16-byte key that is used to secure the network
8
+
9
+ Using the same channel will make the process faster
10
+
11
+ */
12
12
13
13
#include " OThreadCLI.h"
14
14
#include " OThreadCLI_Util.h"
15
15
16
16
#define CLI_NETWORK_KEY " dataset networkkey 00112233445566778899aabbccddeeff"
17
17
#define CLI_NETWORK_CHANEL " dataset channel 24"
18
18
19
+ otInstance *aInstance = NULL ;
20
+
19
21
void setup () {
20
22
Serial.begin (115200 );
21
23
OThreadCLI.begin (false ); // No AutoStart - fresh start
24
+ Serial.println ();
22
25
Serial.println (" Setting up OpenThread Node as Router/Child" );
23
26
Serial.println (" Make sure the Leader Node is already running" );
27
+ aInstance = esp_openthread_get_instance ();
24
28
25
29
OThreadCLI.println (" dataset clear" );
26
30
OThreadCLI.println (CLI_NETWORK_KEY);
@@ -31,7 +35,53 @@ void setup() {
31
35
}
32
36
33
37
void loop () {
38
+ Serial.println (" =============================================" );
34
39
Serial.print (" Thread Node State: " );
35
40
Serial.println (otGetStringDeviceRole ());
41
+
42
+ // Native OpenThread API calls:
43
+ // wait until the node become Child or Router
44
+ if (otGetDeviceRole () == OT_ROLE_CHILD || otGetDeviceRole () == OT_ROLE_ROUTER) {
45
+ // Network Name
46
+ const char *networkName = otThreadGetNetworkName (aInstance);
47
+ Serial.printf (" Network Name: %s\r\n " , networkName);
48
+ // Channel
49
+ uint8_t channel = otLinkGetChannel (aInstance);
50
+ Serial.printf (" Channel: %d\r\n " , channel);
51
+ // PAN ID
52
+ uint16_t panId = otLinkGetPanId (aInstance);
53
+ Serial.printf (" PanID: 0x%04x\r\n " , panId);
54
+ // Extended PAN ID
55
+ const otExtendedPanId *extPanId = otThreadGetExtendedPanId (aInstance);
56
+ Serial.printf (" Extended PAN ID: " );
57
+ for (int i = 0 ; i < OT_EXT_PAN_ID_SIZE; i++) {
58
+ Serial.printf (" %02x" , extPanId->m8 [i]);
59
+ }
60
+ Serial.println ();
61
+ // Nettwork Key
62
+ otNetworkKey networkKey;
63
+ otThreadGetNetworkKey (aInstance, &networkKey);
64
+ Serial.printf (" Network Key: " );
65
+ for (int i = 0 ; i < OT_NETWORK_KEY_SIZE; i++) {
66
+ Serial.printf (" %02x" , networkKey.m8 [i]);
67
+ }
68
+ Serial.println ();
69
+ // IP Addresses
70
+ char buf[OT_IP6_ADDRESS_STRING_SIZE];
71
+ const otNetifAddress *address = otIp6GetUnicastAddresses (aInstance);
72
+ while (address != NULL ) {
73
+ otIp6AddressToString (&address->mAddress , buf, sizeof (buf));
74
+ Serial.printf (" IP Address: %s\r\n " , buf);
75
+ address = address->mNext ;
76
+ }
77
+ // Multicast IP Addresses
78
+ const otNetifMulticastAddress *mAddress = otIp6GetMulticastAddresses (aInstance);
79
+ while (mAddress != NULL ) {
80
+ otIp6AddressToString (&mAddress ->mAddress , buf, sizeof (buf));
81
+ printf (" Multicast IP Address: %s\n " , buf);
82
+ mAddress = mAddress ->mNext ;
83
+ }
84
+ }
85
+
36
86
delay (5000 );
37
87
}
0 commit comments