Skip to content

Commit 1790c31

Browse files
committed
samples: add samples to demonstrate IPv6 communication for Wi-SUN devices
- Transmit Data IPv6 - Transmit Multicast Data IPv6 - Receive Data IPv6 Signed-off-by: Ruben Moral <ruben.moral@digi.com>
1 parent c7562ce commit 1790c31

File tree

6 files changed

+462
-0
lines changed

6 files changed

+462
-0
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
Receive Data IPv6 Sample Application
2+
====================================
3+
4+
This example demonstrates the usage of the socket IPv6 API by giving an example
5+
of how to receive data from other XBee device in the same Wi-SUN network.
6+
7+
Requirements
8+
------------
9+
10+
To run this example you need:
11+
12+
* Two XBee Wi-SUN module.
13+
* Two carrier board for the radio module (XBIB-U-DEV or XBIB-C board).
14+
* One Wi-SUN border router.
15+
* Digi XBee Studio v1.2.0 or higher (available at www.digi.com/xbee-studio).
16+
17+
Setup
18+
-----
19+
20+
The XBee module that runs this sample will act as receiver, while the other
21+
one will act as sender.
22+
23+
Make sure the hardware is set up correctly:
24+
25+
1. Plug the XBee3 radio modules into the XBee adapters and connect them to your
26+
computer's USB ports.
27+
2. Ensure that the sender module is in API mode and both modules are on the
28+
same Wi-SUN network.
29+
30+
Run
31+
---
32+
33+
The example is already configured, so all you need to do is to compile and
34+
launch the application.
35+
36+
Then, you need to send a data frame to the receiver module from the sender one.
37+
Follow these steps to do so:
38+
39+
1. Open XBee Studio and wait until the sender XBee module is discovered.
40+
2. In the left menu, go to the **XBee Console** page and open the connection.
41+
3. Create and add an API frame to the **Send data** list with the following
42+
parameters:
43+
44+
- Frame type: 0x40 - Socket Create
45+
- Frame ID: 01
46+
- Protocol: UDP [00]
47+
48+
4. Send this packet by selecting it and clicking the **Send selected packet**
49+
button. Click the received *Socket Create Response* packet and look for the
50+
assigned *Socket ID*.
51+
5. Create another API frame with the following parameters:
52+
53+
- Frame type: 0x47 - Socket SendTo
54+
- Frame ID: 02
55+
- Socket ID: Use the ID received in the previous packet
56+
- Dest. address: Use the IPv6 address printed in the REPL console
57+
- Dest. port: 12 34
58+
- Transmit options: 00
59+
- Payload: Hello, Wi-SUN module!
60+
61+
6. Send this packet by selecting it and clicking the **Send selected packet**
62+
button.
63+
64+
When the data frame is sent, verify that a line with the sender address and the
65+
data included in the **Payload** field is printed out in the REPL console:
66+
67+
Data received from XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX >> Hello, Wi-SUN module!
68+
69+
Where *XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX* is the IPv6 address of the
70+
sender module.
71+
72+
Supported platforms
73+
-------------------
74+
75+
* Digi XBee Wi-SUN - minimum firmware version: B000
76+
77+
License
78+
-------
79+
80+
Copyright (c) 2025, Digi International, Inc.
81+
82+
Permission is hereby granted, free of charge, to any person obtaining a copy
83+
of this software and associated documentation files (the "Software"), to deal
84+
in the Software without restriction, including without limitation the rights
85+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
86+
copies of the Software, and to permit persons to whom the Software is
87+
furnished to do so, subject to the following conditions:
88+
89+
The above copyright notice and this permission notice shall be included in all
90+
copies or substantial portions of the Software.
91+
92+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
93+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
94+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
95+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
96+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
97+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
98+
SOFTWARE.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
21+
import socket
22+
import time
23+
import xbee
24+
25+
26+
PORT = 0x1234
27+
28+
29+
print(" +-------------------------------------------+")
30+
print(" | XBee MicroPython Receive Data IPv6 Sample |")
31+
print(" +-------------------------------------------+\n")
32+
33+
print("Waiting for the module to be connected to the network...")
34+
35+
ai = xbee.atcmd("AI")
36+
while ai != 0:
37+
time.sleep(1)
38+
ai = xbee.atcmd("AI")
39+
40+
local_addr = xbee.atcmd("MY")
41+
print("Receiver IPv6 address: %s" % local_addr)
42+
43+
# Create the socket.
44+
s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
45+
s.bind((local_addr, PORT))
46+
47+
print("Waiting for data...\n")
48+
49+
try:
50+
while True:
51+
# Receive messages.
52+
data, address = s.recvfrom(1024)
53+
print("Data received from %s >> %s" % (address, data.decode))
54+
finally:
55+
s.close()
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
Transmit Data IPv6 Sample Application
2+
=====================================
3+
4+
This example demonstrates the usage of the socket IPv6 API by giving an example
5+
of how to transmit data to other XBee device in the same Wi-SUN network.
6+
7+
Requirements
8+
------------
9+
10+
To run this example you need:
11+
12+
* Two XBee Wi-SUN module.
13+
* Two carrier board for the radio module (XBIB-U-DEV or XBIB-C board).
14+
* One Wi-SUN border router.
15+
* Digi XBee Studio v1.2.0 or higher (available at www.digi.com/xbee-studio).
16+
17+
Setup
18+
-----
19+
20+
The XBee module that runs this sample will act as sender, while the other
21+
one will act as receiver.
22+
23+
Make sure the hardware is set up correctly:
24+
25+
1. Plug the XBee radio module into the XBee adapter and connect it to your
26+
computer's USB port.
27+
2. Ensure that the receiver module is in API mode and both modules are on the
28+
same Wi-SUN network.
29+
3. Find the IPv6 address of the receiver module in XBee Studio. It will be used
30+
later in the example.
31+
32+
Run
33+
---
34+
35+
Before launching the application, you need to set up XBee Studio to see the data
36+
received by the receiver module. Follow these steps to do so:
37+
38+
1. Launch XBee Studio.
39+
2. Wait until the receiver XBee module is discovered and click on it.
40+
3. In the left menu, go to the **XBee Console** page and open the connection.
41+
4. Create and add an API frame to the **Send data** list with the following
42+
parameters:
43+
44+
- Frame type: 0x40 - Socket Create
45+
- Frame ID: 01
46+
- Protocol: UDP [00]
47+
48+
5. Send this packet by selecting it and clicking the **Send selected packet**
49+
button. Click the received *Socket Create Response* packet and look for the
50+
assigned *Socket ID*.
51+
6. Create another API frame with the following parameters:
52+
53+
- Frame type: 0x46 - Socket Bind/Listen
54+
- Frame ID: 02
55+
- Socket ID: Use the ID received in the previous packet
56+
- Source port: 12 34
57+
58+
7. Send this packet by selecting it and clicking the **Send selected packet**
59+
button.
60+
61+
Fill the **TARGET_IPV6_ADDR** constant in the MicroPython application with the
62+
IPv6 address of the receiver module. Finally, compile and launch the MicroPython
63+
application. It prints out the status of the operation in the console:
64+
65+
Sending data to XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX >> Hello, Wi-SUN module!
66+
Data sent successfully
67+
68+
Verify that a new **Socket Receive From: IPv6** packet has been received in the
69+
XBee Studio console. Select it and review the details, some of them similar to:
70+
71+
- Frame type: CB (Socket Receive From: IPv6)
72+
- Source address: The XBee sender's IPv6 address
73+
- Payload data (ASCII): Hello, Wi-SUN module!
74+
75+
Supported platforms
76+
-------------------
77+
78+
* Digi XBee Wi-SUN - minimum firmware version: B000
79+
80+
License
81+
-------
82+
83+
Copyright (c) 2025, Digi International, Inc.
84+
85+
Permission is hereby granted, free of charge, to any person obtaining a copy
86+
of this software and associated documentation files (the "Software"), to deal
87+
in the Software without restriction, including without limitation the rights
88+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
89+
copies of the Software, and to permit persons to whom the Software is
90+
furnished to do so, subject to the following conditions:
91+
92+
The above copyright notice and this permission notice shall be included in all
93+
copies or substantial portions of the Software.
94+
95+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
96+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
97+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
98+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
99+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
100+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
101+
SOFTWARE.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
21+
import socket
22+
import time
23+
import xbee
24+
25+
26+
# TODO: replace with the IPv6 address of the other Wi-SUN module.
27+
TARGET_IPV6_ADDR = "0000:0000:0000:0000:0000:0000:0000:0000"
28+
PORT = 0x1234
29+
MESSAGE = b"Hello, Wi-SUN module!"
30+
31+
32+
print(" +--------------------------------------------+")
33+
print(" | XBee MicroPython Transmit Data IPv6 Sample |")
34+
print(" +--------------------------------------------+\n")
35+
36+
print("Waiting for the module to be connected to the network...")
37+
38+
ai = xbee.atcmd("AI")
39+
while ai != 0:
40+
time.sleep(1)
41+
ai = xbee.atcmd("AI")
42+
43+
# Create the socket.
44+
s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
45+
46+
print("Sending data to %s >> %s" % (TARGET_IPV6_ADDR, str(MESSAGE, "utf8")))
47+
48+
try:
49+
# Send the message to the module.
50+
s.sendto(MESSAGE, (TARGET_IPV6_ADDR, PORT))
51+
print("Data sent successfully")
52+
except Exception as e:
53+
print("Transmit failure: %s" % str(e))
54+
finally:
55+
s.close()

0 commit comments

Comments
 (0)