Maintaining nv table following a software update

We all know that the nv table persists so long as device is powered up.

This is fine but what is catching me out now is when I do a “Build and Run” following software mods. This overrides / deletes my nv table and I am now trying to think of an elegant way to deal with this scenario. Any suggestions… my nv table has to grab data from the agent.

As I was too hasty this morning (as in the caffeine had not kicked in yet) in posting a question I have now found one method that works following more searching through imp documentation… Hopefully this could help others…

This method / example given seems to be elegant enough for me…
http://electricimp.com/docs/api/hardware/wakereason/

I then use the agent “ping” method by adding in these lines of code in the example for the device:

server.log("Updating nv table"); agent.send("devicePing", hardware.millis());

and agent then responds be returning device data for nv table.

device.on("devicePing", function (startuptime) {//... grab data and place in object to be returned back to device.... updateTable = {"pingTime": startuptime, "nvTableData": {.....} }; device.send("nvTableUpdate", updateTable); });

etc.

Or you can package up your data, send it to the agent and get the agent to server.save() it. When the device comes back online, the first thing it does is request the data back from the agent, which uses server.load() to retrieve it.

Thanks @smittytone. That will certainly ensure that my data is maintained no matter what. I will update my agent code.