I have a function which is being passed a byte and I want to add the byte t the end of a character string and to pass to another function (from the MQTT library). This second function is looking for the first item to be a const char[].
void loop() {
byte i;
for( i = 0; i < 48; i++) {
buttonTest (i);
}
}
void buttonTest( byte buttonId ){
char mTopic[10] = "garage/l";
strcat(mTopic, buttonId);
//strcpy(mTopic, buttonId);
client.publish(mTopic, "1");
digitalWrite(statusLEDArray[buttonId], HIGH);
}
I tried a few other things as well but can' wrap my head around getting the byte added to the end. For the above example the compiler gives me this error: invalid conversion from 'byte {aka unsigned char}' to 'const char' [-fpermissive]*
The ultimate goal is to add the buttonID to the end of the string found in mTopic, but I also need to use this to retrieve items from arrays, as shown in the last line in the sample.
EDIT Changing to the code below works, but I keep seeing suggestions that one should avoid String myVar = "My text." for memory reasons so I was trying to do so. I know I need to look at pointers more and get a better handle on them. Once I do I can probably remove the use of String, which I believe should be my ultimate goal as I have seen memory issues with sketches in the past which I believe are the result of poor String/memory management.
void loop() {
byte i;
for( i = 0; i < 48; i++) {
buttonTest (i);
}
}
void buttonTest( byte buttonId ){
String mTopic[10] = "garage/l";
mTopic = mTopic + buttonId);
//strcat(mTopic, buttonId);
client.publish(mTopic.c_str(), "1");
digitalWrite(statusLEDArray[buttonId], HIGH);
}