On-board memory not enough

I have an application where the imp sits and collects data from a sensor every 5 minutes and then goes to sleep. After an hour it gets on the WiFi and sends the collected data to my server. This way I am able to collect 48 data points with each cycle. All works just fine, until I try to go over 4 hours of collection cycle. Then it only sends 1 reading and no more every cycle.

I am suspecting that it is running out of memory (4K nvram). My code only uses 6% of the program storage, so it’s definitely not the 64K user code area that is limiting the collected data. My data point is 38 characters. I want to go as long as 24 hours between transmits to my server.

The reason I don’t want to be sending the collected data every 4 hours is because I want to prolong the battery life to the maximum. Is there a way to extend this time?

Consider how you are storing the info. Are you storing it as a an array or a table? It might be more efficient to store a single string or blob with the data in it.

Also, to confirm that it is indeed a nvram issue, try storing a short dummy record instead of the 38 characters and see if it works for longer than 4 hours.

Thanks coverdriven. I don’t think that user data can be stored in the code area (size 64K). The only place to store the data points is the nvram (size 4K). Someone can correct me if my understanding is wrong.

Just a small edit to correct a mistake in my original post.

The imp collects 12 readings per hour (once every 5 minutes). 48 per 4 hours. But that seems to be the limit. It won’t go over 4 hours meaning it won’t store more than 48 readings.

Here is a previous thread which may offer some guidance on checking size of data in nv_table

This is exactly what I was looking for gerriko! Thanks a bunch. I will experiment with this.

Code area is 128kB and as the name implies, it stores only code.

Thanks Hugo. However out of that 128K only about 64K is available for user code.

? No, all 128k is available to user code. Why do you believe only 64kB is available?

Hmmm… I was just going by what it says in the FAQ here:

How much memory does the imp have?
The total internal RAM is about 128KB, of which over 64KB is available to user code.


I just discovered external serial flash - wow! That’s a lot of storage and even if writing over the same sectors once per day that’s 100,000 days so no need for wear leveling.

@faiz; yes, that’s RAM (ie workspace) not flash (code space), which is 128kB.

Actually, that FAQ is out of date; it’s over 80kB these days on imp001/002 and over 130kB on imp003) - Peter keeps optimizing the space we use for our OS!