Local AT commands from Python?

Is there is way to send AT commands to the local XBee radio via Python? I would have thought so but I can’t find any documentation on how to do it. If not, how do you change the PAN ID (ATID command) and channel (ATCH command)?

I’m not sure what you mean by “Local AT commands”, but a couple ways I normally send commands to an XBee are via XCTU, or from the WebUI or CLI of a ConnectPort X where the module is associated to. Neither of those methods require python.

Also, I moved this topic to the python forum, since the questions seemed more appropriate to that than the 802.15.4 forum.

If you’re looking to use the PC serial port to drive the XBee, check out the pySerial module. This reference:
http://pyserial.wiki.sourceforge.net/pySerial
is one place to start. The first piece of example code given on that page should work fine in sending an AT command to an XBee with default settings: just replace the ‘hello’ string in the example with the AT command and line terminator. You’ll then only need to add code to read the response.

Ok, I lied. Your program will also have to:

  1. Pause for one second
  2. Send “+++” (no line terminators)
  3. Pause for a further second
    before sending the first command.

If you explore the pyserial stuff, you’ll find links to example code which includes a miniterm implementation. Depending on what you want to do, that code may give you a few ideas.

There’s also the USPP package:
http://pypi.python.org/pypi/USPP%20(Universal%20Serial%20Port%20Python)%20Library/1.0
That package doesn’t seem to have been updated recently, though.

And as admin has already said, you’ll find a few hints in the Python forums. Just note that most of the traffic there concerns writing Python code to run on an XBee, not driver code to run on a PC.

Sorry, I should have said that I meant sending AT commands from Python on an X4 gateway. I found my answer here: http://www.digi.com/wiki/developer/index.php/Utility_script_to_get/set_AT_commands_on_local/remote_zigbee_nodes .

That’s what the zigbee (aka xbee) object module ddo_set and ddo_get commands are for. The ‘id’ parameter is the AT command. For example ddo_get_param(src_addr, ‘PL’) gets the XBee device Power Level and is equvalent to sending ATPL to the XBIB board using X-CTU terminal.