The XBee Hive for Wi-SUN Border Router can send and receive Wi-SUN data using standard IPv6 sockets. This topic focuses on how to communicate from the Border Router itself, both to Wi-SUN nodes and to external IP networks.

For an overview of communication paths (direct-to-server versus local aggregation), see See how devices communicate.

Supported communication options on the Border Router

  • Python socket library: The primary supported method. Use Python to open TCP or UDP sockets and exchange data with nodes or remote servers.

  • Command-line socket tools: Useful for quick tests or debugging. Use socat for IPv6 UDP and TCP sessions.

Use Python sockets

Python on the XBee Hive for Wi-SUN supports IPv6 sockets for both TCP and UDP. The example below listens for UDP data sent from Wi-SUN nodes:

import socket

sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
sock.bind(("::", 5000))
while True:
    data, addr = sock.recvfrom(1024)
    print("rx from", addr, data)
    sock.sendto(b"ack", addr)

The example below starts a simple TCP server that accepts one client at a time:

import socket

server = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
server.bind(("::", 5000))
server.listen(1)
while True:
    print("Waiting for connection")
    conn, addr = server.accept()
    print("client", addr)
    while True:
        data = conn.recv(1024)
        if not data:
            break
        print("rx", data)
        conn.sendall(b"ack")
    print("Connection closed")
    conn.close()

To connect to an external server, create a TCP or UDP socket and send data using the server’s IPv6 address and port. If you need TLS, use Python’s ssl library to wrap a TCP socket.

For details on accessing the interpreter, see Interact with the Python Interpreter.

Use command-line socket tools

You can use socat to validate connectivity quickly. For a bidirectional UDP session with the first node that sends a datagram to port 5000, run:

socat UDP6-LISTEN:5000,reuseaddr STDIO

For an incoming TCP connection session on port 5000 with a node, run:

socat TCP6-LISTEN:5000,reuseaddr STDIO

Next steps

For supported communication methods on the nodes, see Send and receive data. For a broader overview of how communication flows across the Wi-SUN network, see Communicate on the network.