Hi All,
I have some devices with Swan boards that get battery and signal status information from their notecards every 10 seconds in regular loop. Each loop they instantiate local J variables to hold the notecard results. Every minute they check the notecard for new messages.
The problem is that they go unresponsive after about 40 hours. They won’t respond to messages. The only thing I can do is update the host firmware and they come up again.
I have gone over the code, and left logging running on a local device for days, and can’t find any errors that might cause it to freeze or crash. I am accustomed to writing code that stays up for years, and I am confounded.
One of my few ideas is that the J structures are not being garbage collected. If new structures are declared every loop, and not disposed of properly, then could the memory eventually run out? I suppose I could test that by declaring them globally and re-using them each loop. I suppose I’ll give that a go.
Any ideas would be very welcome.
Thanks in advance,
Rob
Hi @rlkeith,
Unfortunately this is difficult to diagnose without seeing your code. Could you maybe post an example of one of your “typical” API calls here and we can see if there are any issues?
Rob
I tried to declare some global J variables and reuse them, setting them to Null after each use. That does not work. The Swan still freezes after about 40 hours.
I’ll put a mini project together to demonstrate what I am trying to do,
Regards,
Rob
Hi Rob.
I have just found Jdelete(). I will experiment with that.
Is there a complete reference for Notecard.h?
Regards,
Rob
I just found the Class Reference. It is not written in terms I find easy to follow, but that is just me.
Here is an example:
Previously the two cleanup lines were missing. I don’t know where Jdelete() is documented. I just found it.
String getHexTime()
{
J *req = notecard.newRequest("card.time");
J *rsp = notecard.requestAndResponse(req);
uint32_t tStamp = JGetInt(rsp, "time");
String HexStr = String(tStamp, 16U);
HexStr.toUpperCase();
notecard.deleteResponse(rsp); //new line
JDelete(req); //new line
return HexStr;
}
Does that look like it might work?
Regards,
Rob
Hi @rlkeith,
This looks good. I might also add a null check on the rsp
object…something like this but cleaned up
String getHexTime()
{
J *req = notecard.newRequest("card.time");
J *rsp = notecard.requestAndResponse(req);
if (rsp) {
uint32_t tStamp = JGetInt(rsp, "time");
String HexStr = String(tStamp, 16U);
HexStr.toUpperCase();
notecard.deleteResponse(rsp); //new line
JDelete(req); //new line
return HexStr;
} else {
return "";
}
}
Good thinking.
My first attempt has stood on its appendage. Back to the drawing board.