# How are you setting the API  mode to APT1?

**URL:** <https://forums.digi.com/t/how-are-you-setting-the-api-mode-to-apt1/21532>\
**Category:** XBee - 802.15.4\
**Tags:** help, please, python, xbee\
**Created:** [July 7, 2020, 1:27pm UTC](https://forums.digi.com/t/how-are-you-setting-the-api-mode-to-apt1/21532 "2020-07-07T13:27:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dpatel](https://avatars.discourse-cdn.com/v4/letter/d/e5b9ba/32.png) [@dpatel](https://forums.digi.com/u/dpatel)\
**Post date:** [July 7, 2020, 1:27pm UTC](https://forums.digi.com/t/how-are-you-setting-the-api-mode-to-apt1/21532/1 "2020-07-07T13:27:26Z")

</div>

I am also getting the error “InvalidOperatingModeException: Could not determine operating mode” when I try to open the device.

I am entering API mode by writing “ATAP1\r” to serial.

---

<div class="post-metadata">

**Author:** ![mvut](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.digi.com/mvut/32/31_2.png) [@mvut](https://forums.digi.com/u/mvut)\
**Post date:** [July 7, 2020, 2:11pm UTC](https://forums.digi.com/t/how-are-you-setting-the-api-mode-to-apt1/21532/2 "2020-07-07T14:11:18Z")

</div>

You need to enter command mode first by sending the command mode sequence.

---

<div class="post-metadata">

**Author:** ![dpatel](https://avatars.discourse-cdn.com/v4/letter/d/e5b9ba/32.png) [@dpatel](https://forums.digi.com/u/dpatel)\
**Post date:** [July 9, 2020, 10:00am UTC](https://forums.digi.com/t/how-are-you-setting-the-api-mode-to-apt1/21532/3 "2020-07-09T10:00:36Z")

</div>

First, I send the command mode sequence “+++” and wait for “OK” which I don’t seem to be receiving and thus never enter the if statement that is suppose to send the command.

def command\_mode(command):  
for \_ in range(10): # Limit retry count  
time.sleep(0.1)  
ser.write(“+”.encode(“ascii”))  
time.sleep(0.1)  
ser.write(“+”.encode(“ascii”))  
time.sleep(0.1)  
ser.write(“+”.encode(“ascii”))  
print(“+++”)  
receive = ser.read(ser.in\_waiting)  
print(str(receive).find(“OK”))  
if str(receive).find(“OK”) != -1:  
ser.write((command + “\r”).encode(“ascii”))  
break

---

<div class="post-metadata">

**Author:** ![mvut](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.digi.com/mvut/32/31_2.png) [@mvut](https://forums.digi.com/u/mvut)\
**Post date:** [July 9, 2020, 10:16am UTC](https://forums.digi.com/t/how-are-you-setting-the-api-mode-to-apt1/21532/4 "2020-07-09T10:16:26Z")

</div>

Don’t wait between each + you send. That is probably why you are not entering command mode.
