Agent Stoppage: How to reinitialize?

I’m having an issue where the agent seems to stop. Specifically, variables that are initialized by the agent cease to exist after my code has been running for some time. I don’t get any error messages, other than “the index ‘variable’ does not exist”. Also, any repeating functions using imp.wakeup stop working as the functions are not initialized. It’s like the agent is losing it’s state and not restarting. The agent continues to operate, and can receive and send http requests.

I’ve tried triggering my initialization routine with device.onconnect but it doesn’t get called when the issue occurs. Clicking build and run in the IDE gets it up and running again.

You sure the agent hasn’t restarted, and the missing variables aren’t ones which are initialized in code paths that may not have run yet? Agents can be restarted (especially on the development server) at any point for service updates, bug fixes, etc. We recommend you save state you want persisted with server.save() and reload at agent boot with server.load().

onconnect() isn’t working correctly right now. It’s on the list.

If variables really are going missing and have a repeatable case we’d like to see your code to investigate further…

I had this happen to me today. I don’t know if the agent restarted or not but a
value of the root table suddenly, apparently ceased to exist.

I will keep an eye on it to see if anything similar happens again. So for in the last ~6 hours it has not occurred again.

We did an agent reboot today; if your code was restarted, could that explain the behavior?

Hi Hugo,

You’re right. I was actually calling my agent initialization routine when the device starts. So when the device stayed running, but agent restarted, it wasn’t being called.

Thanks