Skip to content

Commit 89f4a59

Browse files
committed
samples: add Wi-SUN Get Started Guide sample
https://onedigi.atlassian.net/browse/MPIDE-426 Signed-off-by: Hector Gonzalez <hector.gonzalez@digi.com>
1 parent 3ef1f80 commit 89f4a59

File tree

2 files changed

+130
-0
lines changed

2 files changed

+130
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
Wi-SUN Get Started Sample Application
2+
=====================================
3+
4+
This example is part of the Digi's Wi-SUN Get Started. It demonstrates
5+
how to use the XBee Hive Wi-SUN and the XBee Wi-SUN modules to exchange
6+
data using the socket IPv6 API.
7+
8+
This application is executed in the XBee Wi-SUN module and performs the
9+
following actions:
10+
* Listens for incoming IPv6 messages on port 0x2616 (9750).
11+
* Converts the payload to uppercase.
12+
* Sends the modified message back to the sender’s address.
13+
14+
Read the [demo documentation][doc] for more information.
15+
16+
Requirements
17+
------------
18+
19+
To run this example you need:
20+
21+
* An XBee Wi-SUN radio module with MicroPython support.
22+
* One carrier board for the radio module (XBIB-C board).
23+
* An XBee Hive Wi-SUN device running the corresponding Python application of the
24+
Get Started.
25+
26+
Setup
27+
-----
28+
29+
Make sure the hardware is set up correctly:
30+
31+
1. Plug the XBee 3 radio module into the XBee adapter and connect it to your
32+
computer's USB port.
33+
34+
Run
35+
---
36+
37+
The example is already configured, so all you need to do is build and launch
38+
the project. Then, read the demo documentation for more information about how
39+
to test the demo.
40+
41+
Supported platforms
42+
-------------------
43+
44+
* Digi XBee Wi-SUN - minimum firmware version: A000A1
45+
46+
License
47+
-------
48+
49+
Copyright (c) 2025, Digi International, Inc.
50+
51+
Permission is hereby granted, free of charge, to any person obtaining a copy
52+
of this software and associated documentation files (the "Software"), to deal
53+
in the Software without restriction, including without limitation the rights
54+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
55+
copies of the Software, and to permit persons to whom the Software is
56+
furnished to do so, subject to the following conditions:
57+
58+
The above copyright notice and this permission notice shall be included in all
59+
copies or substantial portions of the Software.
60+
61+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
62+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
63+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
64+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
65+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
66+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
67+
SOFTWARE.
68+
69+
[doc]: https://docs.digi.com/resources/documentation/digidocs/rf-docs/wisun/wisun-gs_c.html
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Copyright (c) 2025, Digi International, Inc.
2+
#
3+
# Permission is hereby granted, free of charge, to any person obtaining a copy
4+
# of this software and associated documentation files (the "Software"), to deal
5+
# in the Software without restriction, including without limitation the rights
6+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
# copies of the Software, and to permit persons to whom the Software is
8+
# furnished to do so, subject to the following conditions:
9+
#
10+
# The above copyright notice and this permission notice shall be included in
11+
# all copies or substantial portions of the Software.
12+
#
13+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
# SOFTWARE.
20+
import socket
21+
import time
22+
import xbee
23+
24+
25+
PORT = 0x2616
26+
27+
28+
print(" +--------------------------------------------+")
29+
print(" | XBee MicroPython Wi-SUN Get Started Sample |")
30+
print(" +--------------------------------------------+\n")
31+
32+
print("Waiting for the module to be connected to the network...")
33+
34+
ai = xbee.atcmd("AI")
35+
while ai != 0:
36+
time.sleep(1)
37+
ai = xbee.atcmd("AI")
38+
39+
local_addr = xbee.atcmd("MY")
40+
41+
# Create the socket and listen for incoming data.
42+
s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
43+
s.bind((local_addr, PORT))
44+
45+
print("Waiting for incoming data...\n")
46+
47+
try:
48+
while True:
49+
# Receive messages.
50+
data, address = s.recvfrom(1024)
51+
dataString = data.decode()
52+
print("Received from [%s]:%s >> %s" % (address[0], address[1],
53+
dataString))
54+
55+
# Echo the message to the sender module.
56+
dataToEcho = dataString.upper()
57+
s.sendto(dataToEcho.encode(), (address[0], address[1]))
58+
print("Echoed to [%s]:%s >> %s" % (address[0], address[1],
59+
dataToEcho))
60+
finally:
61+
s.close()

0 commit comments

Comments
 (0)