Loopback in Python?

Is it possible to do a loopback type of communication with python? I wanted to make sure that my code worked up to this point.

I tried:
sd.sendto(“stuff”, 0, node0)
payload, src_addr = sd.recvfrom(72)

where node0 is the device itself, but this just blocks itself.

Can you provide a more complete code snapshot? What does your network look like? What devices do you have deployed?

The hardware I’m using is a Connectport X8 and a singular Xbee module in one of the dev boards.

I’m having trouble communicating across them so I wanted to test out just the simple communication snippets of code to make sure I was implementing them properly.

Its just a basic extension of zb_ex2_rw.py just in reverse. Where I do the following:


sd.bind((“”,0,0,0)) //using 0xe8 fails always

sd.sendto(“stuff”, 0, node0) //node0 is the Connectport X

payload, src_addr = sd.recvfrom(72)

print payload
print src_addr

The only explicit change from the example code is in sd.bind((“”,0xe8,0,0)) to sd.bind((“”,0,0,0)) as the code always fails using 0xe8.

As bind problems have come up once or twice before, I’ll pose the common question: are any python scripts set to run at startup?

One can not bind to the same endpoint twice, so an existing, running script could cause a bind to fail.

The “who” command at the CLI can help determine whether there are running scripts.

The “set python” command can be consulted to determine whether any scripts are enabled to run at startup.

If you’ve already checked all of these things, and the bind continues to fail, it would be useful to start with the actual failure returned by the bind. That might indicate the necessary direction to be taken.

Message was edited by: 52637p

If you are using ZNet 2.5 or ZB modules you will have to bind to endpoint e8 or change the DE parameter of your remote modules to 0.

I am guessing that your bind to e8 is failing because you have another Python application running concurrently when you are trying to bind to 0xe8. If you go to “Connections” on the Web UI do you see other Python threads running?

If you go to Python->Auto Start Settings is there a checkbox next to one or more script in that configuration area?


It was odd in that the example code would work as long as it didn’t block and force me to hard reset the router. You were correct in that there was a script set to run at start up. I canceled that and now bind no longer fails at all.

I had read about some bind problems, but they all seemed to be related to Linux and what version of python you were using.

As someone unfamiliar with Python, and especially the TCP/socket stuff. I don’t completely understand what 0xe8 stands for. I read that it is the Maxstream serial data endpoint. So if I had to explain what I think is happening it would be: socket( … ) creates a sd class with all the socket methods, bind is a method that ties a specific data path to it, and then I just send/wait for data. Is that about correct?

Message was edited by: MikeB

Yup, that is why it was failing. I fixed that.

Unfortunately the program still blocks. So I guess that is not the way to do it?