Time Allocation and Mode Selection for Secure Communications in Internet of Things