Avoid timeout of API session

The API session times out after some time. Added an API call to mainloop() to be called every 10 or so minutes to avoid this.