Assuming you are talking about the function
bool painlessMesh::sendBroadcast( String &msg, bool includeSelf = false)
Then you'll see that ultimately, the library passes msg
into the function buildMeshPackage
where it constructs a JSON message (see here)
String ICACHE_FLASH_ATTR painlessMesh::buildMeshPackage(uint32_t destId, uint32_t fromId, meshPackageType type, String &msg) {
debugMsg(GENERAL, "In buildMeshPackage(): msg=%s\n", msg.c_str());
DynamicJsonBuffer jsonBuffer;
JsonObject& root = jsonBuffer.createObject();
root["dest"] = destId;
//root["from"] = _nodeId;
root["from"] = fromId;
root["type"] = (uint8_t)type;
switch (type) {
case NODE_SYNC_REQUEST:
case NODE_SYNC_REPLY:
{
JsonArray& subs = jsonBuffer.parseArray(msg);
if (!subs.success()) {
debugMsg(GENERAL, "buildMeshPackage(): subs = jsonBuffer.parseArray( msg ) failed!");
}
root["subs"] = subs;
break;
}
case TIME_SYNC:
root["msg"] = jsonBuffer.parseObject(msg);
break;
default:
root["msg"] = msg;
}
String ret;
root.printTo(ret);
return ret;
}
Even if you did construct a String
with null terminators in it, the moment it gets put into the JSON string it destroys everything. JSON by default doesn't support binary data strings (reference).
So, the library is a problem because it happily passes data as JSON messages, and that's bad if you want binary data transported. You could use Base64 or the more efficient http://base91.sourceforge.net/ encoding though to mitigate this a little bit, or search for a different lib.