As long as you are confident that this is OK. That payload and length are passed to you. Modifying one past the end of the payload may be corrupting memory.
As far as I understand the MQTT format, the content of the payload variable is not defined (by MQTT) but can be anything. You seem to opt for an ASCII based protocol which is easy to debug and easily portable but not as efficient as a binary format would be.If you choose an ASCII format, I would still strongly suggest to define standard structure of such a string, like "TYPE:POSITION:VALUE", so in your example it would not be "PUMP:ON" but "PUMP:1:1" or "VALVE:1:0" instead of "VALVE:1:OPEN". This makes it much easier to parse the incoming message and organise the call distribution. You can use strtok() then to split the message into the type, position and value. Position and value can be fed to atoi immediately after the split up and you already have integers.The conversion from a byte array to a character array is simply a type cast:Code: [Select]char *cstring = (char *) payload;
char *cstring = (char *) payload;