I have the following code that is bring am mqtt code to manipiulate, but the last parameter is empty
void mqttMessageReceived(String &topic, String &payload) {
DPRINT("Received Topic: ["); DPRINT(topic); DPRINT("] Payload: "); DPRINTLN(payload);
DPRINTLN(topic);
// char buf[32];
char buf[sizeof(topic)];
topic.toCharArray(buf, sizeof(buf));
DPRINT("273 ");DPRINTLN(topic);
char *p = strtok(buf, "/");
DPRINT("276 ");DPRINTLN(buf);
p = strtok(0, "/");
if (p == NULL)
return;
strcpy(&destinationDeviceAddress[0], p);
DPRINT("282 ");DPRINTLN(destinationDeviceAddress);
p = strtok(0, "/");
DPRINT("285 ");DPRINTLN(p);
if (p == NULL)
return;
strcpy(&destinationDevicePropery[0], p);
DPRINT("288 ");DPRINTLN(destinationDevicePropery);
payload.toCharArray(destinationValue, sizeof(payload));
routeOutgoingMessage = true;
}
The monitor shows this
Received Topic: [TheShop/ab/heat] Payload: 1
TheShop/ab/heat
273 TheShop/ab/heat
276 TheShop
282 ab
285
If i change char buf[sizeof(topic)]; to char buf[32]; the result becomes
TheShop/ab/heat
273 TheShop/ab/heat
276 TheShop
282 ab
285 heat
288 heat
Any suggestions?