It always takes at least 5 seconds for my linux laptop to connect to the pi with the standard bluetooth config. If I add `FastConnectable = true` to the pi it always connects <1s. Perhaps worth adding to your script?