Sending ZigBee Trasmit Request Frame from PC over CPX4 to ZigBee


I wrote a java programm which works with the XStick. I’ve implemented a lot of functions and i want them to work with the Connectport X4.

I want to send a whole Zigbee Transmit Request Frame from my Java Programm over UDP to the ConnectPort X4.
Furthermore I want to use a Python programm which sends this packet as it is (with all frame fields set, i.e. Frame Type, Frame ID … RF Data Checksum) as bytestream to my ZigBee Network.

(this is how it works with the Xstick in Java but ofc over serial)

It seems that on the CPX4 does the frame handling (correct me if i am wrong), when i create a socket.
This is something i do not want. I dont want to send simply the payload/rfdata. Vice versa i want that the zigBee Response frame is sent back from python to my java program as it is and not only the payload. My Java program will do the packet analyze thing.

What i am doing now is:

addr = “00:13:a2:00:40:76:7d:5c!”
data = 'GET

zig_sock = socket.socket(socket.AF_ZIGBEE, socket.SOCK_DGRAM, socket.ZBS_PROT_TRANSPORT)
sent = zig_sock.sendto(data[:segment], 0, addr)
data = data[sent:]

What i get:
print “Receiving Data from zig_sock”
data, addr = zig_sock.recvfrom(255)

I get only the payload.

What i want is:

data = ‘7E 00 12 10 01 00 13 A2 00 40 76 7d 5c FF FE 00 00 47 45 54 0a C3’
zig_sock = socket.socket(socket.AF_ZIGBEE, socket.SOCK_DGRAM, socket.ZBS_PROT_TRANSPORT)
sent = zig_sock.sendto(data[:segment])
data = data[sent:]

Receive data as bytes.

Is there a possibility to do so. Did i missed something. Does anybody did something like that?

The (or is not a Python script, as the function is built into the firmware. So there is no code to help you there.

At present the only way to do that is to disable the X4’s management of the Xbee, which means the Xbee becomes a serial device and all of the ‘Xbee Display’ (etc) web pages dissappear. So try the ‘set Xbee state=off’ and reboot. At that point you might be able to create a script which opens the 2nd (or is the fourth?) serial port and send your API frames directly.

The X2D (the metal-shell one, not the plastic cheap one) is better at this, because it would allow you to just send data to UDP port 2101 with no Python running.

Well here I am again.
Thanks again for the advice to use the digi esp samples.

I tried the serial echo programm for the listening part on the serial interface, so i had a clear functional version, which should at least read something on the serial interface.

Well I spend the whole day trying to read any data on the serial interface…

I tried to do it on the Xstick plugged in the USB port on the CPX4, as well as open COM2 (for the internal XBee) and listen on that one.

I triggered some messages by pushing the button on my smart energy meters, but did’nt got any data which would be close to that what i’m expecting to get.

I’m really frustrated right now.
Gonna try some other Energy Meters tomorrow.


Thanks for the fast answer, i will do some research on this.

What i have at the moment is the ConnectPort X4 ZB Ethernet.
By X2D you mean a ConnectPort X2 Gateway? Do you have a productlink for me, so i could consider if i switch to that one.
I’m not that good at Python programing and if i can spare the time i’ll do ;).

Thanks a lot!

Hi, i wrote my UDP-Tunneling program (PythonServer and Java Client)
and everything is working so far on my computer.

For the Serial interfacing i used pyserial. Now i encountered some problems getting the right archives on the ConnectPortX4.

It always stops with:

Traceback (most recent call last):
  File "WEB/python/", line 14, in ?
    execfile(os.path.join(os.path.abspath('.'), ''))
  File "WEB/python/", line 9, in ?
    import serial
ImportError: No module named serial

On the ConnectPort X4 i’ve got the following files: 38066 bytes 601 bytes 2227 bytes 144321 bytes

The path for the is set in

import sys, os 

sys.path.insert(0, os.path.join(os.path.abspath('.'), ''))
print "Launching Python application '%s' ...
" %''
if not os.path.isdir('C:/Temp/MyUDPTunneling/src'):
    execfile(os.path.join(os.path.abspath('.'), ''))

In this are all necessary files (serial + ctypes) generated by DigiESP for Python (i have tried as well). None combination seems to work… :frowning:

I have no idea what i’m doing wrong. Does someone has some experience with PySerial on Digi devices?

Thanks a lot


I suggest you to use the Python serial library included with some Digi ESP for Python examples as part of the projects. That library was written to work in the ConnectPort X devices using the pyserial template, so it should have the same methods than pyserial.

You will find it in some serial (RS232) examples such as Serial Echo, Serial Loopback, Non blocking serial echo, etc.


Hi again!

Well i got rid of the import serial stuff from the PySerial. And used as suggested the built in serial port access i found here:

I’m stucked now at the point, where i read from serial.
I’m receiving the UDP data, write them to serial and everytime i read from serial there is no Data to read (and/or simply an empty String is sent back to UDP) :frowning:

I’ve tried several com-ports COM0 - COM4. It seems that COM2 is for the XBee, because it is in use when: set xbee state=on.

But i don’t get any data. I tried COM11 aswell, which should address the USB port on the CPX4, and plugged an XSTICK to it.
But there wasn’t any data either.

There is a small possibility i did something wrong creating the data packets (wrong bytes wrong zigbee adresses or checksum). But i am pretty sure i did everything right there…

I’m attaching my python file, maybe someone sees something.
It’s only for testing purposes at the moment.

Thanks so far!
Martin J.

I’m sorry to be so persistent, but why don’t you use the samples provided with the Digi ESP for Python? They can be used as base for your projects or simply to copy&paste certain code that you can use in your application.

There are some Serial (RS232) examples that could be useful for you. I have attached a couple of screenshots with the location of the examples and some code of one of them.


Ok thank you Diegoe, i will give it a try tomorrow…

Kind Regads.

Finally got it :wink:
I had luck to find out what the problem is:

When i deactivate the internal xbee module on the CPX4 via telnet –> set xbee state=off

I am able to receive correct data on the serial COM2 (yes it’s COM2! :)).

After i reboot the CPX4 once or power it off (reboot could be necessary if an exception occurs and the COM2 is not closed correctly) i still get data but not what i am expecting.

I’ve attached two screenshots, which shows what happens after a reboot. Maybe anyone has an idea.

When i have to reboot the CPX4 the procedure is as followed:

  1. Reboot the CPX4 - over webinterface
  2. telnet set xbee state=on
  3. Reboot the CPX4 again - over webinterface
  4. telnet set xbee state=off –> DONT REBOOT after that
  5. start python on the CPX4 –> everything works fine

But this is a pain. I have to look if there is a possibility to do this procedure over some UDP packets.

Is there a telnet command for rebooting the CPX4?



If you are using a ConnectPort X4 you can import the digicli Python module. It allows you to send cli commands to the device from your Python application.

In your case, to reboot the device you should issue this code:

import digicli

digicli.digicli("boot action=reset")


PS: You can also try executing the “set xbee state=off” from your Python app and see if it works.

Thank you Diegoe you helped me a lot!


digicli.digicli("set xbee state=off")
digicli.digicli("set xbee state=on")

this worked also.


Ok, I can change the xbee state =0n/off but i am not able to get my python code to work.
I cant open the com port
Can you help me with this?