Copy-paste from Bluegiga scan demo