Sending big amount of data to Exosite portal

Hi, I have build a project with Arduino mega, collecting data from multiple sensors and part of all functionalities is sending data to Exosite portal.

The problem that I face is that Arduino is resetting itself once per day, I was investigating what is happening and I am almost sure that using Strings in function that sends data to Exosite is causing the problem.

Just to make it clear. This code works, I send data to Exosite successfully, the problem is that Arduino is restarting periodically and i believe this function is to blame because if i disable sending then Arduino does not reset.

This is a part of code that sends data to Exosite. I use GSM shield, sending data every 1,5 minutes.

char t1[3] = "t1";
  char h1[3] = "h1";
  char t2[3] = "t2";
  char h2[3] = "h2";
  char rt[3] = "rt";
  char rs[3] = "rs";
  char ro[3] = "ro";
  char st[3] = "st";
  char ac[3] = "ac";
  char am[3] = "am";
  char aw[3] = "aw";
  char aa[3] = "aa";
  char sv[3] = "sv";
  char sd[3] = "sd";
  char si[3] = "si";
  char l1[3] = "l1";
  char je[2] = "=";
  char in[2] = "&";

  String sendDataString;

  sendDataString = (sendDataString + t1 + je + temp + in + h1 + je + hum + in + t2 + je + remoteTemp + in + h2 + je + remoteHum + in + rt + je + setTemp  + in + ro + je + tempRegulOn + in + rs + je + regUsedSensor + in + st + je + swOneHigh + in + ac + je + acON + in + am + je + acMode + in + aa + je + acModuleAvailable + in + sv + je + remoteWaterSensorAttached + in + sd + je + remoteSmokeSensorAttached + in + si + je + signalStrenght + in + l1 + je + ligh + in + aw + je + acWorkMode);

  gsm.println(F("AT+CIPSTART = \"TCP\",\"\",\"80\""));
  gsm.println(F("POST /onep:v1/stack/alias?switch1 HTTP/1.1"));
  gsm.println(F("User-Agent: Exosite-Activator/2.3.1 Arduino/106"));
  gsm.println(F("X-Exosite-CIK: c2cac4ff70a9cab3af7c0xxxxxxxxxxa4a34a305"));
  gsm.println(F("Accept: application/x-www-form-urlencoded; charset=utf-8"));
  gsm.println(F("Content-Type: application/x-www-form-urlencoded; charset=utf-8"));
  gsm.print(F("Content-Length: "));

  sendDataString = "";

Please advise me how to change this function to still send correct form of data to Exosite but not damage memory so much as Strings do. I know that i should use char array but I don't know how. Not in my case it is too complex for my current knowledge. Maybe it would be better to use Exosite library? How to modify my code to use it?

Thank you very much!

I think what you need is sprintf if you really want to put all of that into one long string.

However it might just be easier to break that up into multiple lines and print them all one at a time. There's not really any need to assemble them all into one string first.

Thank you for answering. I will check sprintf and see what i can do.

I was also considering breaking into multiple lines but as far as I know, you must send one string to Exosite at time along with actual string length. Maybe i will divide string into three strings and send them partially: in first run of function first part, in second run, second part and then third part. Instead of sending one big string at once in one run of function.

Post the whole code. What sort of object is gsm? If it’s a serial object then it’s buffered and there’s no difference. The data all goes into the buffer and the receiver has no way to know how many print statements it took to put it there. It all goes out as one continuous stream.

The whole code is too big (1700 lines) the code that i have posted is function for sending data to exosite and it is calling every defined period of time, using millis.

gsm is defined as SoftwareSerial:

#include <SoftwareSerial.h>
SoftwareSerial gsm(50, 51);

If gsm is a software serial instance then there’s no need to assemble the string before you send it. Just send it in chunks with multiple gsm.print lines.

Ok I will try that. This approach should dramatically reduce memory problems. Thank you!

It works. Thank you very much!