Skip to content

Commit 02fe879

Browse files
committed
samples: add Wi-SUN Get Started Guide sample
https://onedigi.atlassian.net/browse/MPIDE-426 Signed-off-by: Hector Gonzalez <[email protected]>
1 parent 6d07c72 commit 02fe879

File tree

2 files changed

+169
-0
lines changed

2 files changed

+169
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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 Hive Wi-SUN and performs the
9+
following actions:
10+
* Allows the user to input messages to send to the target XBee.
11+
* Listens for incoming IPv6 messages from the XBee network.
12+
13+
Read the [demo documentation][doc] for more information.
14+
15+
16+
Requirements
17+
------------
18+
19+
To run this example you need:
20+
21+
* An XBee Hive Wi-SUN device.
22+
* An XBee Wi-SUN radio module running the corresponding MicroPython
23+
application of the Get Started and its corresponding carrier board
24+
(XBIB-C board).
25+
* XBee Studio (available at www.digi.com/digi-xbee-studio)
26+
27+
28+
Setup
29+
-----
30+
31+
1. Ensure the XBee Wi-SUN module is in the same network as the Digi XBee Hive Wi-SUN device.
32+
33+
Run
34+
---
35+
36+
The example expects the IPv6 address of the remote XBee device as a parameter to
37+
launch. To obtain that value:
38+
39+
1. Launch the XBee Studio application.
40+
2. Plug the remote XBee device to the PC. XBee Studio automatically discovers it.
41+
3. Open the device tab associated to the XBee module by clicking on it.
42+
4. Click **Settings** in the left sidebar to open the settings page. This reads
43+
all the settings automatically.
44+
5. Search the **MY** setting. This is the value you have to pass as parameter
45+
to the Python application of the Digi XBee Hive Wi-SUN device.
46+
47+
Ensure to pass the XBee Device's IPv6 address as parameter to the example application. To do so from PyCharm:
48+
49+
1. Click on the **Run/debug Configurations** button in the toolbar of your IDE.
50+
It is a combo-box with the name of your project.
51+
2. On the contextual menu that appears, click on **Edit Configurations**.
52+
3. In the new window, there is a **Parameters** field. It allows to input the
53+
parameters of the application. Input **-a <destination_ipv6>** where
54+
<destination_ipv6> is the IPv6 address of the device that you copied
55+
in the previous section.
56+
57+
At this point you only need to build and launch the project. Then, read the Get
58+
started section of the documentation for more information about the exercise.
59+
60+
Supported platforms
61+
-------------------
62+
63+
* Digi XBee Hive Wi-SUN - minimum firmware version: 25.6.110.1
64+
65+
License
66+
-------
67+
68+
Copyright (c) 2025, Digi International, Inc.
69+
70+
Permission is hereby granted, free of charge, to any person obtaining a copy
71+
of this software and associated documentation files (the "Software"), to deal
72+
in the Software without restriction, including without limitation the rights
73+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
74+
copies of the Software, and to permit persons to whom the Software is
75+
furnished to do so, subject to the following conditions:
76+
77+
The above copyright notice and this permission notice shall be included in all
78+
copies or substantial portions of the Software.
79+
80+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
81+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
82+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
83+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
84+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
85+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
86+
SOFTWARE.
87+
88+
[doc]: https://docs.digi.com/resources/documentation/digidocs/rf-docs/wisun/wisun-gs_c.html
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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 argparse
22+
import threading
23+
24+
25+
PORT = 9750
26+
27+
print("---------------------------------------+")
28+
print(" | XBee Hive Wi-SUN Get Started Sample |")
29+
print(" +-------------------------------------+\n")
30+
31+
def receiver(sock):
32+
"""
33+
Background thread: receive and print incoming UDP datagrams.
34+
"""
35+
while True:
36+
try:
37+
data, address = sock.recvfrom(1024)
38+
print("Received from [%s]:%s >> %s\n> " % (
39+
address[0], address[1], data.decode().rstrip()),
40+
end='', flush=True)
41+
except OSError as e:
42+
print("Receive error: %s" % e)
43+
44+
def main():
45+
parser = argparse.ArgumentParser(
46+
description='Simple IPv6 UDP socket client')
47+
parser.add_argument('-a', '--address', required=True,
48+
help='IPv6 address of the server')
49+
args = parser.parse_args()
50+
51+
# Create an IPv6 UDP socket.
52+
server = (args.address, PORT)
53+
s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
54+
s.bind(('::', PORT))
55+
56+
# Start receiver thread.
57+
thread = threading.Thread(target=receiver, args=(s,), daemon=True)
58+
thread.start()
59+
60+
print("\nType a message and hit Enter to send it to [%s]:%s." % (
61+
args.address, PORT))
62+
try:
63+
while True:
64+
# Read a line from stdin and send it as a UDP datagram.
65+
line = input("> ")
66+
if not line:
67+
print("Please, enter some data to send to [%s]:%s." % (
68+
args.address, PORT))
69+
continue
70+
71+
try:
72+
s.sendto(line.encode(), server)
73+
except OSError as e:
74+
print("Error sending data: %s" % e)
75+
except KeyboardInterrupt:
76+
print('\nInterrupted by user, closing...')
77+
finally:
78+
s.close()
79+
80+
if __name__ == '__main__':
81+
main()

0 commit comments

Comments
 (0)