Updated the algorythm to detect and keep devices online:
  1. Insert new devices in the Database
  2. Update old devices that are in $devices - set their online_last to current time
  3. Delete devices that expired - their online_last is to old