How to empty char array ? Memory issue with atmega328
hello everyone,
i have issues in project, arduino makes request server every 10 seconds sending curent temperature,humidity, etc, after each request server responds json string only if setings have been changed on server (new temperature limit, or turn on/off relay) .
after many issues finaly managed json part , parse using ajson library, problem every time arduino receives json string has less , less free memory, bellow code generating issue, have commented parsejson function sure issue not in function.
at end empty the jsonresponse = ""; and jsonstring = ""; variables can't empty inchar one, error:
error: 'inchar' not declared in scope
after code bellow shown serial monitor, when free.memory constant means have not changed on sever, afteri change json code appears in serial monitor , can see free memory less before
any appreciated!
i'm not sure if issue related inchar variable, left arduino on last night sure
a. memory issue not caused ethernet part of code
b. it's not related parsejson function (i commented it)
code executed when json response sent server 1 bellow
thank you.
serial monitor response
i have issues in project, arduino makes request server every 10 seconds sending curent temperature,humidity, etc, after each request server responds json string only if setings have been changed on server (new temperature limit, or turn on/off relay) .
after many issues finaly managed json part , parse using ajson library, problem every time arduino receives json string has less , less free memory, bellow code generating issue, have commented parsejson function sure issue not in function.
at end empty the jsonresponse = ""; and jsonstring = ""; variables can't empty inchar one, error:
error: 'inchar' not declared in scope
after code bellow shown serial monitor, when free.memory constant means have not changed on sever, afteri change json code appears in serial monitor , can see free memory less before
any appreciated!
i'm not sure if issue related inchar variable, left arduino on last night sure
a. memory issue not caused ethernet part of code
b. it's not related parsejson function (i commented it)
code executed when json response sent server 1 bellow
thank you.
code: [select]
if (client.connected()) {
// store state of connection next time through
// loop:
lastconnected = client.connected();
if (client.available()) {
// read incoming bytes:
char inchar = client.read();
// extract json part of response
if (!jsonstarted && inchar == '{') {
jsonstarted = true;
//serial.println("found json start");
jsonresponse = ""; // empty json response
}
if (inchar == '{') {
bracescount++;
}
if (inchar == '}') {
bracescount--;
serial.println(jsonresponse);
}
if (jsonstarted ) {
jsonresponse += inchar;
}
if (bracescount == 0) {
jsonstarted = false;
}
}
}
else
{
client.stop();
}
if(jsonresponse!="" && bracescount == 0)
{
// serial.println(jsonresponse);
printfreememory("free.mem before parsing");
jsonresponse.trim();
char* jsonstring = (char*) malloc(sizeof(char)*(jsonresponse.length()+1));
jsonresponse.tochararray(jsonstring, jsonresponse.length() + 1);
//serial.println(jsonstring);
//serial.println(inchar);
//parsejson(jsonstring); // commented make sure memory issue not function
serial.println("empty next");
serial.println(jsonstring);
jsonresponse = "";
jsonstring = "";
//inchar = "";
client.stop();
}
serial monitor response
quote
making http request...
free.mem every 10 seconds: 526
temp rising t=20.12 dt=0.00 stop heater
connecting server...
making http request...
free.mem every 10 seconds: 526
temp rising t=20.12 dt=0.00 stop heater
connecting server...
making http request...
free.mem every 10 seconds: 526
temp rising t=20.12 dt=0.00 stop heater
connecting server...
making http request...
{"max_temperature":"24","main_heater":"0"
free.mem before parsing: 526
empty next
free.mem every 10 seconds: 481
temp rising t=20.12 dt=0.00 stop heater
connecting server...
making http request...
{"max_temperature":"32"
free.mem before parsing: 481
empty next
free.mem every 10 seconds: 454
temp rising t=20.12 dt=0.00 stop heater
connecting server...
making http request...
free.mem every 10 seconds: 454
temp rising t=20.12 dt=0.00 stop heater
connecting server...
making http request...
free.mem every 10 seconds: 454
temp rising t=20.12 dt=0.00 stop heater
connecting server...
making http request...
free.mem every 10 seconds: 454
temp rising t=20.12 dt=0.00 stop heater
connecting server...
making http request...
{"max_temperature":"23"
free.mem before parsing: 454
empty next
free.mem every 10 seconds: 427
temp rising t=20.12 dt=0.00 stop heater
connecting server...
making http request...
the thread subject asks how empty char array there no arrays in program snippet posted.
your inchar simple char variable not array, cannot 'empty' @ same place set jsonresponse , jsonstring "" because out of scope @ point having been declared inside different block of code . happens if make inchar global variable , don't declare when client.available() true ?
as matter of interest type of variables jsonresponse , jsonstring ? nots problematical string suppose ....
your inchar simple char variable not array, cannot 'empty' @ same place set jsonresponse , jsonstring "" because out of scope @ point having been declared inside different block of code . happens if make inchar global variable , don't declare when client.available() true ?
as matter of interest type of variables jsonresponse , jsonstring ? nots problematical string suppose ....
Arduino Forum > Using Arduino > Programming Questions > How to empty char array ? Memory issue with atmega328
arduino
Comments
Post a Comment