I'm using the SPISlave library, and I have the following code snippet:
String arg;
SPISlave.onData([arg](uint8_t *data, size_t len) {
data[len] = 0;
arg += String((char *)data);
// ...
}
The compiler doesn't like my string concatenation, though:
/home/lars/sketch_apr01a/sketch_apr01a.ino: In lambda function: sketch_apr01a:65:12: error: passing 'const String' as 'this' argument of 'String& String::operator+=(const String&)' discards qualifiers [-fpermissive] arg += String((char *)data);
I've tried other versions as well, with similar results:
arg.concat((char *)data)
arg = arg + String((char *)data)
arg += String((const char *)data)
So how exactly do I write this unusual operation?