Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions samples/xbee/communication/ws_get_started/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
Wi-SUN Get Started Sample Application
=====================================

This example is part of the Digi's Wi-SUN Get Started. It demonstrates
how to use the XBee Hive Wi-SUN and the XBee Wi-SUN modules to exchange
data using the socket IPv6 API.

This application is executed in the XBee Wi-SUN module and performs the
following actions:
* Listens for incoming IPv6 messages on port 0x2616 (9750).
* Converts the payload to uppercase.
* Sends the modified message back to the sender’s address.

Read the [demo documentation][doc] for more information.

Requirements
------------

To run this example you need:

* An XBee Wi-SUN radio module with MicroPython support.
* One carrier board for the radio module (XBIB-C board).
* An XBee Hive Wi-SUN device running the corresponding Python application of the
Get Started.

Setup
-----

Make sure the hardware is set up correctly:

1. Plug the XBee 3 radio module into the XBee adapter and connect it to your
computer's USB port.

Run
---

The example is already configured, so all you need to do is build and launch
the project. Then, read the demo documentation for more information about how
to test the demo.

Supported platforms
-------------------

* Digi XBee Wi-SUN - minimum firmware version: A000A1

License
-------

Copyright (c) 2025, Digi International, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

[doc]: https://docs.digi.com/resources/documentation/digidocs/rf-docs/wisun/wisun-gs_c.html
61 changes: 61 additions & 0 deletions samples/xbee/communication/ws_get_started/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Copyright (c) 2025, Digi International, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import socket
import time
import xbee


PORT = 0x2616


print(" +--------------------------------------------+")
print(" | XBee MicroPython Wi-SUN Get Started Sample |")
print(" +--------------------------------------------+\n")

print("Waiting for the module to be connected to the network...")

ai = xbee.atcmd("AI")
while ai != 0:
time.sleep(1)
ai = xbee.atcmd("AI")

local_addr = xbee.atcmd("MY")

# Create the socket and listen for incoming data.
s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
s.bind((local_addr, PORT))

print("Waiting for incoming data...\n")

try:
while True:
# Receive messages.
data, address = s.recvfrom(1024)
dataString = data.decode()
print("Received from [%s]:%s >> %s" % (address[0], address[1],
dataString))

# Echo the message to the sender module.
dataToEcho = dataString.upper()
s.sendto(dataToEcho.encode(), (address[0], address[1]))
print("Echoed to [%s]:%s >> %s" % (address[0], address[1],
dataToEcho))
finally:
s.close()