11
11
#include " OThreadCLI.h"
12
12
#include " OThreadCLI_Util.h"
13
13
14
- bool otPrintRespCLI (const char *cmd, Stream &output) {
15
- char cliResp[256 ];
16
- if (cmd == NULL ) {
17
- return true ;
18
- }
19
- OThreadCLI.println (cmd);
20
- while (1 ) {
21
- size_t len = OThreadCLI.readBytesUntil (' \n ' , cliResp, sizeof (cliResp));
22
- if (len == 0 ) {
23
- return false ; // timeout for reading a response from CLI
24
- }
25
- // clip it on EOL
26
- for (int i = 0 ; i < len; i++) {
27
- if (cliResp[i] == ' \r ' || cliResp[i] == ' \n ' ) {
28
- cliResp[i] = ' \0 ' ;
29
- }
30
- }
31
- if (!strncmp (cliResp, " Done" , 4 )) {
32
- return true ; // finished with success
33
- }
34
- if (!strncmp (cliResp, " Error" , 4 )) {
35
- return false ; // the CLI command or its arguments are not valid
36
- }
37
- output.println (cliResp);
38
- }
39
- }
40
-
41
14
void setup () {
42
15
Serial.begin (115200 );
43
16
OThreadCLI.begin (true ); // For scanning, AutoStart must be active, any setup
44
- OThreadCLI.setTimeout (10000 ); // 10 seconds for reading a line from CLI - scanning takes time
17
+ OThreadCLI.setTimeout (100 ); // Set a timeout for the CLI response
45
18
Serial.println ();
46
- Serial.println (" This sketch will continuosly scan the Thread Local Network and all devices IEEE 802.15.4 compatible" );
19
+ Serial.println (" This sketch will continuously scan the Thread Local Network and all devices IEEE 802.15.4 compatible" );
47
20
}
48
21
49
22
void loop () {
50
23
Serial.println ();
51
- Serial.println (" Scanning for near by IEEE 802.15.4 devices:" );
52
- // 802.15.4 Scan just need a previous OThreadCLI.begin() to tun on the 802.15.4 stack
53
- if (!otPrintRespCLI (" scan" , Serial)) {
54
- Serial.println (" 802.15.4 Scan Failed..." );
24
+ Serial.println (" Scanning for nearby IEEE 802.15.4 devices:" );
25
+ // 802.15.4 Scan just needs a previous OThreadCLI.begin()
26
+ if (!otPrintRespCLI (" scan" , Serial, 3000 )) {
27
+ Serial.println (" Scan Failed..." );
55
28
}
56
29
delay (5000 );
57
30
if (otGetDeviceRole () < OT_ROLE_CHILD) {
@@ -60,9 +33,9 @@ void loop() {
60
33
return ;
61
34
}
62
35
Serial.println ();
63
- Serial.println (" Scanning - MLE Discover:" );
64
- if (!otPrintRespCLI (" discover" , Serial)) {
65
- Serial.println (" MLE Discover Failed..." );
36
+ Serial.println (" Scanning MLE Discover:" );
37
+ if (!otPrintRespCLI (" discover" , Serial, 3000 )) {
38
+ Serial.println (" Discover Failed..." );
66
39
}
67
40
delay (5000 );
68
41
}
0 commit comments