Device goes offline after several hours of service and does not reconnect

This should be before all the code. It needs to be global

look at this information on timers. It is excelent

Timer FAQ