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

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
>>> 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?

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 (15,355 points)
selected Feb 27, 2021 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.

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.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)