Skip to content

Commit 739b77c

Browse files
committed
fix(openthread): COAP parametrization
1 parent 1b2530d commit 739b77c

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

libraries/OpenThread/examples/COAP/coap_lamp/coap_lamp.ino

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#define OT_CHANNEL "24"
55
#define OT_NETWORK_KEY "00112233445566778899aabbccddeeff"
6+
#define OT_MCAST_ADDR "ff05::abcd"
7+
#define OT_COAP_RESOURCE_NAME "Lamp"
68

79
const char *otSetupLeader[] = {
810
// clear/disable all
@@ -22,10 +24,10 @@ const char *otSetupLeader[] = {
2224

2325
const char *otCoapLamp[] = {
2426
// create a multicast IPv6 Address for this device
25-
"ipmaddr add", "ff05::abcd",
27+
"ipmaddr add", OT_MCAST_ADDR,
2628
// start and create a CoAP resource
2729
"coap", "start",
28-
"coap resource", "Lamp",
30+
"coap resource", OT_COAP_RESOURCE_NAME,
2931
"coap set", "0"
3032
};
3133

libraries/OpenThread/examples/COAP/coap_switch/coap_switch.ino

+10-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#define USER_BUTTON 9 // C6/H2 Boot button
55
#define OT_CHANNEL "24"
66
#define OT_NETWORK_KEY "00112233445566778899aabbccddeeff"
7+
#define OT_MCAST_ADDR "ff05::abcd"
8+
#define OT_COAP_RESOURCE_NAME "Lamp"
79

810
const char *otSetupChild[] = {
911
// clear/disable all
@@ -88,13 +90,17 @@ void setupNode() {
8890
// Sends the CoAP frame to the Lamp node
8991
bool otCoapPUT(bool lampState) {
9092
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";
9298

9399
if (lampState) {
94-
coapMsg[strlen(coapMsg) - 1] = '1';
100+
coapMsg[coapMsg.length() - 1] = '1';
95101
}
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());
98104

99105
char cliResp[256];
100106
// waits for the CoAP confirmation and Done message for about 5 seconds

0 commit comments

Comments
 (0)