I am trying to write python client which obtains regular readings from the device connected to the XBee RS-232 Adapter. Or even sending some AT commands (in ASCII) to the device over the RS232.
I want to run the client on the ConnectPort X4 gateway and communicate using this gateway (and client application on the gateway) and API. However, I find difficulties to send AT commands to the XBee node and get any information from the device connected to this node.
Could anybody point me into some source examples or documentation?
Before I posted my topic I was looking on these two places but didn’t come up with something fruitful.
Still not sure how can I connect to the node using gateway. What I was using are two commands: ddo_set_param and ddo_get_param. But don’t know how can I switch to the AT commands mode using Zigbee module.
You cannot use AT commands to the X4’s XBee, as it is forced to always be in API-mode. Remember, your program does not own the mesh - it must share it with other gateway functions.
Lynn, thanks very much for your response. I finally managed to talk to the device connected to XBee RS232. I used the socket-like functions, and it work perfectly fine.
The only problem I was facing was proper configuration of XBee RS232, mainly the baud rate, parity, data bits etc. The only problem I found was that I couldn’t configure it through the Web UI, I had to literally go to python code and do it using xbee module. The reason for that is that the RS232 is in sleeping mode, don’t know yet how to turn off the sleeping mode.
I think you want to avoid the term “API” unless you mean the Digi API or you just confuse people.
So assume the remote serial device has a simple protocol with “request-A” and “response-A”, and perhaps a few other responses. If they are actual “AT” commands, that is irrelevant as the CPX4 will just send as data and the fact ATxx is involved is transparent.
At this point, if you send the string “Hello” or “ATDT” or “x23d\r” into that UDP/ZB Socket with the correct MAC extended address, then the remote XBee would just send that string out the serial port. Very simple and easy (I do this all the time with Modbus protocol).
Since the remote serial device cannot “command” the XBee, it just sends a serial response. What happens inside the XBee depends on which hardware it is.
Worst case you need to MANUALLY have preloaded the CPX4’s 8-byte MAC as the DH/DL settings in the remote XBee - this causes the XBee to always send any serial data back to the MAC (which is your CPX4) and you would see the data returned in the recvfrom()
In the Zigbee XBee, it naturally returns unknown serial traffic to the “coordinator” or MAC 00:00:00:00:00:00:00:00. But in summary, I would suggest these steps:
Follow the advice on the above wiki page - confirm the RS-232 adapter shows up correctly in the XBee List of the CPX4.
confirm the serial settings are correct (today the XBee won’t support 2-stop bits or 7 data bits, but 8-data bits and parity can be set.)
set the CPX4’s MAC address as the DH/DL in the Advanced Settings Page for the XBee RS-232 Adapter (just to be safe).
At this point the Python use of UDP/ZB Socket should work. If not, try putting a PC running Hyperterminal out there, see if you can talk to yourself via CPX4+Python -> Xbee -> RS-232 -> Hyperterminal.
Appologies for using term ‘API’, and thanks for pointing this out.
Before I get your response, I managed to configure XBee RS-232 following the wiki page you sent. However, as per my previous msg, I wasn’t able to configure the XBee using Web UI, although I can see CPX4, XBee RS-232 and Xbee Analog I/O. So I had to configure it using python and ddo_set_param().
I also tested the hyperterminal before you suggested
Thanks again for your help and advices.
I undestand now that to use WEB UI for configuring Serial I need to use ‘Route AT-mode’ firmware. Thanks.
I am glad the problem was solved by “easier” instead of “more complex/harder”.
There is nothing wrong with using set_ddo/get_ddo.
In fact, all of my own Python code starts with a list of settings like [ (‘BD’, 3), (‘D7’, 1) ], then during startup I have a simple loop to do a GET_DDO. If the parameter is NOT set as I wish, then I add it to a second list of things to change.
Then if I am lucky, the second “to_set” list is empty when I am done, otherwise I must do the set_ddo, plus save the setting and reset the XBee.
This is the robust way to do this because it allows you to add a new device without preconfiguring it.