Hello
I admit that I didn’t start comprehensive squirrel learning, and it might be an easy question. I’m running this code (only device code - no agent code) and it stops every 20th UART reading or so, stating that its out of memory. I’m used to dealing with memory in c++, but I really can’t figure out where the leak is in this code - could anyone help?
I might add that the Arduino is sending 8 newline terminated strings every 2 seconds.
`arduino <- hardware.uart57;
local recieveString = “”;
local humidity = 0;
local air_temp = 0;
local ds181 = 0;
local ds182 = 0;
local ds183 = 0;
local ds184 = 0;
local ec_tds = 0;
local ec_us = 0;
local ec_sal = 0;
function arduinoData() {
//server.log("reading...");
// read from arduino on UART57
local c = arduino.read();
// if bytes are recieved loop them until -1 flag (no more relavant data)
while(c != -1) {
// add the recieved byte converted to char into the string
recieveString += c.tochar();
// if new line occurs in recieved, save the data (new line stop defined in arduino)
if (c == '\
') {
// debug
server.log(recieveString);
local data = split(recieveString,":");
// assign global variables for agent to catch later according to string recieved
if(data[0] == "hum") {
humidity = data[1];
} else if (data[0] == "temp") {
air_temp = data[1];
} else if (data[0] == "ds181") {
ds181 = data[1];
} else if (data[0] == "ds182") {
ds182 = data[1];
} else if (data[0] == "ds183") {
ds183 = data[1];
} else if (data[0] == "ds184") {
ds184 = data[1];
} else if (data[0] == "ec") {
local ec_data = split(data[1],",");
ec_tds = ec_data[0];
ec_us = ec_data[1];
if(ec_data[2] != null) {
ec_sal = ec_data[2];
}
}
// better safe than sorry :D
recieveString = "";
}
// read again
c = arduino.read();
}
imp.wakeup(10, arduinoData);
}
arduino.configure(38400, 8, PARITY_NONE, 1, NO_CTSRTS, arduinoData);
`
Thanks for your help