File tree 2 files changed +14
-6
lines changed
libraries/OpenThread/examples/COAP
2 files changed +14
-6
lines changed Original file line number Diff line number Diff line change 3
3
4
4
#define OT_CHANNEL " 24"
5
5
#define OT_NETWORK_KEY " 00112233445566778899aabbccddeeff"
6
+ #define OT_MCAST_ADDR " ff05::abcd"
7
+ #define OT_COAP_RESOURCE_NAME " Lamp"
6
8
7
9
const char *otSetupLeader[] = {
8
10
// clear/disable all
@@ -22,10 +24,10 @@ const char *otSetupLeader[] = {
22
24
23
25
const char *otCoapLamp[] = {
24
26
// create a multicast IPv6 Address for this device
25
- " ipmaddr add" , " ff05::abcd " ,
27
+ " ipmaddr add" , OT_MCAST_ADDR ,
26
28
// start and create a CoAP resource
27
29
" coap" , " start" ,
28
- " coap resource" , " Lamp " ,
30
+ " coap resource" , OT_COAP_RESOURCE_NAME ,
29
31
" coap set" , " 0"
30
32
};
31
33
Original file line number Diff line number Diff line change 4
4
#define USER_BUTTON 9 // C6/H2 Boot button
5
5
#define OT_CHANNEL " 24"
6
6
#define OT_NETWORK_KEY " 00112233445566778899aabbccddeeff"
7
+ #define OT_MCAST_ADDR " ff05::abcd"
8
+ #define OT_COAP_RESOURCE_NAME " Lamp"
7
9
8
10
const char *otSetupChild[] = {
9
11
// clear/disable all
@@ -88,13 +90,17 @@ void setupNode() {
88
90
// Sends the CoAP frame to the Lamp node
89
91
bool otCoapPUT (bool lampState) {
90
92
bool gotDone = false , gotConfirmation = false ;
91
- char coapMsg[] = " coap put ff05::abcd Lamp con 0" ;
93
+ String coapMsg = " coap put " ;
94
+ coapMsg += OT_MCAST_ADDR;
95
+ coapMsg += " " ;
96
+ coapMsg += OT_COAP_RESOURCE_NAME;
97
+ coapMsg += " con 0" ;
92
98
93
99
if (lampState) {
94
- coapMsg[strlen ( coapMsg) - 1 ] = ' 1' ;
100
+ coapMsg[coapMsg. length ( ) - 1 ] = ' 1' ;
95
101
}
96
- OThreadCLI.println (coapMsg);
97
- log_d (" Send CLI CMD:[%s]" , coapMsg);
102
+ OThreadCLI.println (coapMsg. c_str () );
103
+ log_d (" Send CLI CMD:[%s]" , coapMsg. c_str () );
98
104
99
105
char cliResp[256 ];
100
106
// waits for the CoAP confirmation and Done message for about 5 seconds
You can’t perform that action at this time.
0 commit comments