BufferFiller.print resets my device


hi!

i'm using ethercard library display simple website.
now 've decided not let arduino handle site, provide data site.
so want arduino send data json, string contains more 9-10 json-items, device resets when calling bufferfiller.print

this code (just making random json string testing)

code: [select]
void listjson() {
   serial.println("enter");
  string data = "{\"list\":[";
  int index = 1;

  while (index < 15) {
    if (index != 1) data = data + ",";
    int tempc = random(30);
    string hash = "test"; //md5::make_digest(md5::make_hash( (char *) random(300)), 16);
    data = data + "{\"id\":\"";
    data = data + hash + "\",\"name\":\"sensor ";
    data = data + index + "\",\"val\":";
    data = data + tempc;
    data = data + "}";
   
   // bfill.emit_p(pstr("{\"id\":\"$h\",\"name\":\"sensor $d\",\"val\":$t}")
   //   , hash , index, tempc);
    index++;
    serial.println(freeram());
  }
  data = data +  "]}";
  bfill.print(data);
  serial.println("done");
}


as can see, i'm checking ram. goes down 4471 right before device resets.

the device i'm using, arduino mega2560

when producing 9-10 json-items, result looks this:
code: [select]
{"list":[{"id":"test","name":"sensor 1","val":7},{"id":"test","name":"sensor 2","val":19},{"id":"test","name":"sensor 3","val":23},{"id":"test","name":"sensor 4","val":8},{"id":"test","name":"sensor 5","val":10},{"id":"test","name":"sensor 6","val":2},{"id":"test","name":"sensor 7","val":24},{"id":"test","name":"sensor 8","val":8},{"id":"test","name":"sensor 9","val":23}]}

hope me, able produce ~25 json-items

thanks in advance

quote
hope me

get rid of strings.

allocate fixed length char array hold longest string (lower case s) send, , use string functions populate array.

all constructing , destructing doing fragmenting hell out of memory. while may have plenty of memory still available, it's in little tiny (unusable) pieces.


Arduino Forum > Using Arduino > Programming Questions > BufferFiller.print resets my device


arduino

Comments

Popular posts from this blog

Connecting Raspberry Pi 2 to P10(1R)-V706 LED Dot Matrix - Raspberry Pi Forums

TypeError: <unknown> is not a numpy array - Raspberry Pi Forums

datso and removing imagetitle - Joomla! Forum - community, help and support