Older Imp001 Out of Memory

I have two imps involved here. One of them checks things in the field and writes some data to a website (such as timestamps and sensor data). The other imp, an older Imp001, has a timer to request the agent to access an API every 3 minutes. It then turns the WS2812 LED a different color depending on the status returned by the API.

Very randomly, the Imp001 faults with an Out of Memory and restarts. This happens randomly and for no apparent reason? I’m wondering if there might be some sort of memory leak with the WS2812.class.nut:2.0.1 ??

Has anyone else experienced this? Is the issue with the WS2812 class?

I should also mention that I’m using the WS2812 “tail” that connects to the Imp001.

Here is a section of the server log:

|2019-12-04T15:15:54.864 -06:00 |[Device] |Stat: 2 Diff: 218|
|2019-12-04T15:15:54.870 -06:00 |[Device] |20,0,0|
|2019-12-04T15:18:59.886 -06:00 |[Device] |memory: 60316|
|2019-12-04T15:18:59.888 -06:00 |[Device] |Stat: 1 Diff: 99|
|2019-12-04T15:18:59.893 -06:00 |[Device] |0,10,0|
|2019-12-04T15:22:04.907 -06:00 |[Device] |memory: 60316|
|2019-12-04T15:22:04.907 -06:00 |[Device] |Stat: 1 Diff: 283|
|2019-12-04T15:22:04.914 -06:00 |[Device] |0,10,0|
|2019-12-04T15:25:09.924 -06:00 |[Device] |memory: 60316|
|2019-12-04T15:25:09.925 -06:00 |[Device] |Stat: 1 Diff: 165|
|2019-12-04T15:25:09.931 -06:00 |[Device] |0,10,0|
|2019-12-04T15:26:33.003 -06:00 |[Status] |Device disconnected|
|2019-12-04T15:26:33.006 -06:00 |[Exit Code] |imp restarted, reason: out of memory|
|2019-12-04T15:26:33.012 -06:00 |[Status] |Device connected|
|2019-12-04T15:26:33.213 -06:00 |[Device] |0,10,0|
|2019-12-04T15:26:35.421 -06:00 |[Status] |Device disconnected|
|2019-12-04T15:26:35.424 -06:00 |[Exit Code] |imp restarted, reason: out of memory|
|2019-12-04T15:26:35.431 -06:00 |[Status] |Device connected|
|2019-12-04T15:26:35.630 -06:00 |[Device] |0,10,0|
|2019-12-04T15:26:38.366 -06:00 |[Status] |Device disconnected|
|2019-12-04T15:26:38.369 -06:00 |[Exit Code] |imp restarted, reason: out of memory|
|2019-12-04T15:26:38.377 -06:00 |[Status] |Device connected|
|2019-12-04T15:26:38.576 -06:00 |[Device] |0,10,0|
|2019-12-04T15:26:43.582 -06:00 |[Device] |memory: 59600|
|2019-12-04T15:26:43.583 -06:00 |[Device] |Stat: 1 Diff: 257|
|2019-12-04T15:26:43.589 -06:00 |[Device] |0,10,0|
|2019-12-04T15:29:48.599 -06:00 |[Device] |memory: 60316|
|2019-12-04T15:29:48.600 -06:00 |[Device] |Stat: 1 Diff: 135|
|2019-12-04T15:29:48.607 -06:00 |[Device] |0,10,0|

Here is the device code:

// Device Code
#require “WS2812.class.nut:2.0.1”

// CONSTANTS
const NUMPIXELS = 5;
const DELAY = 0.1;
const COLORDELTA = 8;

// Instantiate the WS2812s
spi <- hardware.spi257;
spi.configure(MSB_FIRST, 7500);
pixels <- WS2812(spi, NUMPIXELS);

function setColor(color) {
pixels.fill([0,0,0]);
local colors = split(color, “,”);
local red = colors[0].tointeger();
local green = colors[1].tointeger();
local blue = colors[2].tointeger();

if(red==999){
for (local i = 0 ; i < NUMPIXELS ; i++) {
pixels.set(i, [0, 50, 0]);
}
pixels.draw();
imp.sleep(1.0);
for (local r = 0 ; r < NUMPIXELS ; r++) {
pixels.set(r, [0, 0, 0]);
}
}
else{
for (local i = 0 ; i < NUMPIXELS ; i++) {
pixels.set(i, [red, green, blue]);
}
}

pixels.draw();
server.log(red+","+green+","+blue);
}

// Alias the GPIO pin as ‘button’
button <- hardware.pin8;

function buttonPress() {
local state = button.read();
if (state == 1) {
// The button is released
server.log(“Release”);
} else {
// The button is pressed
server.log(“Press”);
setColor(“0,0,30”);
agent.send(“button8”, 0);
imp.sleep(2.0); // debounce a bit!
setColor(“0,10,0”);
}
}

function poll(){
// Read the pin and log its value
agent.send(“mailb”, 0);
imp.sleep(5.0);
local timer = imp.wakeup(180, poll);
}

function mailcolor(stat){
server.log(“memory: " + imp.getmemoryfree());
local substrings = split(stat, “,”);
local status = substrings[0];
local diff = substrings[1];
diff = diff.tointeger();
server.log(“Stat: " + status + " Diff: “+ diff);
local red = 0;
local green = 10;
local blue = 0;
if(status == “2” && diff < 700){
red = 20;
green = 0;
blue = 0;
}
if(diff > 699){
red = 0;
green = 0;
blue = 20;
}
// in deep sleep overnight
if(diff < 0){
red = 20;
green = 0;
blue = 20;
}
local color = red+”,”+green+”,"+blue;
setColor(color);
}

agent.on(“stat”, mailcolor);

// Start with green color
setColor(“0,10,0”);
// Configure the button to call buttonPress() when the pin’s state changes
button.configure(DIGITAL_IN_PULLUP, buttonPress);

poll();

I’m using the same config – imp001, LED Tail – for a different application (outdoor temperature readings for the next 12 hours) and, looking back over my logs, I see occasional OOM errors too. The only appreciable difference I can see is that I’m running version 3.0.0 of the WS2812 library.

Thanks for the reply. I might try the newer library.
This OOM doesn’t hurt anything, it’s just a bit annoying not knowing why it happens.

Particulary annoying when it seems there should be plenty of memory free!

That is strange, given that the pixel array is allocated at instantiation… and it’s only 5 pixels.