Open marcelwinter04 opened 2 years ago
Update:
I'm now using the .print() function to send data. First that seemed to fix the problem but then i recognized that this function is extremly slow (~5 Seconds to send the data).
Now I'm using a combination of both approaches. But i'm not really happy with that. Maybe anyone could help me?
void sendDeviceData()
{
int sendLength = 0;
String publishTopic = "";
String socketString = "{\"deviceID\":\"";
socketString += macString;
socketString += "\",\"data\": {";
socketString += " }}";
sendLength = socketString.length();
for (int i = 0; i < 1200; i++)
{
socketString = "\"";
socketString += i;
socketString += "\":";
socketString += getValue(i);
if (i < 1199)
{
socketString += ",";
}
sendLength += socketString.length();
}
Serial.println(sendLength);
publishTopic = "device/";
publishTopic += macString;
publishTopic += "/data";
mqttClient.beginPublish(publishTopic.c_str(), (sendLength-1), false);
mqttClient.print("{\"deviceID\":\"");
mqttClient.print(macString);
mqttClient.print("\",\"data\": {");
for(int j = 0; j < 6; j++) {
socketString = "";
for (int i = 0; i < 200; i++)
{
socketString += "\"";
socketString += i+(j*200);
socketString += "\":";
socketString += getValue(i+(j*200));
if (i+(j*200) < 1199)
{
socketString += ",";
}
}
mqttClient.print(socketString);
}
mqttClient.print("}}");
mqttClient.endPublish();
//mqttClient.publish(publishTopic.c_str(), socketString.c_str());
Serial.println("send mqtt");
}
Hi , I would place the callback into one string (8192 quite much for this little mc, i hope you have enough heap free during operation esp. when you are using tls with no buffersize limitation..... Next I would reserve enough space for the string by using reserve(): String socketString; socketString.reserve(4098), because frequent socketString += without reserve() first copies the string every time >> heap fragmentation.
@fsommer1968 thanks for your help, i will try this.
Hello,
I'm currently facing the issue that I'm getting the error "Socket error on client xxxxxx, disconnecting" from my broker. But this is only the case when i publish data that is bigger than 4096 Bytes.
I have already set the buffer size a little bit bigger, but that does not seem to be the problem.
Funny thing is the broker gets this message. Until 432 everything is correct, but then the message starts again.
This looks like my string has an overflow.
Edit: I'm using Arduino as Component