Home/Support/Support Forum/Python xbee node to_socket_addr() method returning too many/zero-value fields
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

Python xbee node to_socket_addr() method returning too many/zero-value fields

0 votes
Hi,

Trying to make some sense of why I'm not able to communicate with devices.

(This is after disabling xbgw_main.py so I can muck around in the REPL.)

>>> n
<node type=router addr_extended=[00:13:a2:00:41:b4:c8:e0]!>
>>> n.profile_id
49413
>>> n.to_socket_addr()
('[00:13:a2:00:41:b4:c8:e0]!', 0, 0, 0, 0, 0, 0)

When I try to use this address tuple in sendto, socket complains that there are too many args (there are 7 instead of 6).

But more visibly, none of the endpoint/profile/whatever fields are populated-- yet they exist as attributes on the node object itself.

Is this method completely broken? Or am I doing something wrong?

Thanks!
asked Dec 14, 2020 in 3rd Party Python and API development in other Languages by starfish New to the Community (11 points)

Please log in or register to answer this question.

2 Answers

+1 vote
 
Best answer
You look to be doing this wrong.
It should be more like:

xbee_sd.sendto("Hello, World!", 0, ('[00:13:a2:00:40:0a:07:a5]!', 0xe8, 0xc105, 0x11, 0, 0x42))
answered Dec 14, 2020 by mvut Veteran of the Digi Community (14,574 points)
selected Feb 27 by starfish
0 votes
Turns out I was doing it wrong after all.

That method requires additional args but does not complain if they are not provided.

```
endpoint=0xe8
profile_id=49413
cluster_id=0x11
nodes = xbee.get_node_list()
node = n = nodes[1]

# --- here's where i went wrong ---
addr = n.to_socket_addr(endpoint, profile_id, cluster_id)[:-1]
# --- end of incompetence ---

sd = socket(AF_XBEE, SOCK_DGRAM, XBS_PROT_TRANSPORT)
sd.bind(('', endpoint, profile_id, cluster_id))
cmd = <bytestring>
sd.sendto(cmd, 0, addr)
```
answered Dec 21, 2020 by starfish New to the Community (11 points)
...