I am looking for documentation or assistance to help debug the following problem.
I am in the process of improving the resilience of my Photon code by (amongst other things) minimising the use of strings.
One such string variable is a MQTT client ID which is a concatenation of the location of the sensor, the string “_client” and a random number converted to a string. This code works but makes heavy use of strings.
. String location = "bedroom"; String client_id = location + "_client" + String(random(1000,9999)); // TODO Convert away from strings. .
The following code is my failing attempt to use memory locations.
. const char location = "bedroom"; // This works char client_id[(sizeof(location)+10)]; // Size of location -1 for terminating character + 7 for "_client" + 4 for random number char * client_id_pointer; // a pointer (curently blank) that will point to client_id client_id_pointer = &client_id; // Assign client_id_pointer to the start of client_id *client_id_pointer = String(location); // Write location (e.g. 'bedroom') to the start of client_id client_id_pointer = &client_id[(sizeof(location)-1))]; // move pointer to the end of 'location' *client_id_pointer = "_client"; // Write '_client' client_id_pointer = &client_id[(sizeof(location)+6)]; *client_id_pointer = String(random(1000,9999)); .
This fails with “client_id_pointer does not name a type” and “expected constructor, destructor, or type conversion before ‘=’ token”
Grateful for any assistance.