Skip to content

Commit 2a044c3

Browse files
committed
doc: add documentation about sending and receiving User Data Relay messages
Signed-off-by: Diego Escalona <diego.escalona@digi.com>
1 parent 2932367 commit 2a044c3

File tree

4 files changed

+165
-2
lines changed

4 files changed

+165
-2
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
digi\.xbee\.packets\.relay module
2+
===================================
3+
4+
.. automodule:: digi.xbee.packets.relay
5+
:members:
6+
:inherited-members:
7+
:show-inheritance:

doc/examples.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,19 @@ You can find the example at the following path:
276276
:ref:`communicateSendIPData`.
277277

278278

279+
Send User Data Relay
280+
````````````````````
281+
282+
This sample application shows how to send data to other XBee interface.
283+
284+
You can find the example at the following path:
285+
**examples/communication/relay/SendUserDataRelaySample**
286+
287+
.. note::
288+
For more information about sending User Data Relay messages, see
289+
:ref:`communicateSendRelayData`.
290+
291+
279292
Receive data
280293
````````````
281294

@@ -370,6 +383,19 @@ You can find the example at the following path:
370383
:ref:`communicateReceiveSMS`.
371384

372385

386+
Receive User Data Relay messages
387+
````````````````````````````````
388+
389+
This sample application shows how to receive data from other XBee interface.
390+
391+
You can find the example at the following path:
392+
**examples/communication/relay/ReceiveUserDataRelaySample**
393+
394+
.. note::
395+
For more information about receiving User Data Relay messages, see
396+
:ref:`communicateReceiveRelayData`.
397+
398+
373399
Receive modem status
374400
````````````````````
375401

doc/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ Python Library includes the following features:
2626
* Ability to transmit and receive data from any XBee device on the network.
2727
* Ability to manage the General Purpose Input and Output lines of all your XBee
2828
devices.
29+
* Ability to send and receive data from other XBee interfaces (Serial,
30+
Bluetooth Low Energy and MicroPython).
2931

3032
This portal provides the following documentation to help you with the different
3133
development stages of your Python applications using the XBee Python Library.

doc/user_doc/communicating_with_xbee_devices.rst

Lines changed: 130 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ Communicate with XBee devices
22
=============================
33

44
The XBee Python Library provides the ability to communicate with remote nodes in
5-
the network. The communication between XBee devices in a network involves the
6-
transmission and reception of data.
5+
the network, IoT devices and other interfaces of the local device. The
6+
communication between XBee devices in a network involves the transmission and
7+
reception of data.
78

89
.. warning::
910
Communication features described in this topic and sub-topics are only
@@ -745,6 +746,66 @@ The ``send_sms_async`` method may fail for the following reasons:
745746
generic ``XBeeException``.
746747

747748

749+
.. _communicateSendRelayData:
750+
751+
Send data to other interfaces
752+
-----------------------------
753+
754+
XBee3 modules have the ability to send and receive data to/from other XBee
755+
interfaces through User Data Relay frames. The supported interfaces are: Serial
756+
port (SPI, or UART when in API mode), Bluetooth Low Energy and MicroPython.
757+
This can be useful if your application wants to transmit data to a MicroPython
758+
program running on the module or a cellphone connected to it over BLE.
759+
760+
The ``XBeeDevice`` class and its subclasses provide the following method to
761+
send data to any XBee interface:
762+
763+
+-------------------------------------------------------------+-----------------------------------------------------------------+
764+
| Method | Description |
765+
+=============================================================+=================================================================+
766+
| **send_user_data_relay(UserDataRelayInterface, Bytearray)** | Specifies the destination relay interface and the data to send. |
767+
+-------------------------------------------------------------+-----------------------------------------------------------------+
768+
769+
This method is asynchronous, which means that your application does not block during the transmit process.
770+
771+
**Send user data relay message**
772+
773+
.. code:: python
774+
775+
[...]
776+
777+
# Instantiate an XBee device object.
778+
device = XBeeDevice("COM1", 9600)
779+
device.open()
780+
781+
destInterface = UserDataRelayInterface.MICROPYTHON
782+
message = "MicroPython, are you there?"
783+
784+
# Send the message to the MicroPython interface.
785+
device.send_user_data_relay(destInterface, message.encode("utf8"))
786+
787+
[...]
788+
789+
The ``send_user_data_relay`` method may fail for the following reasons:
790+
791+
* If the relay interface or data is ``None``, the method throws a
792+
``ValueError``.
793+
* Errors register as ``XBeeException``:
794+
* If the operating mode of the device is not ``API`` or
795+
``ESCAPED_API_MODE``, the method throws an
796+
``InvalidOperatingModeException``.
797+
* If there is an error writing to the XBee interface, the method throws a
798+
generic ``XBeeException``.
799+
800+
+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
801+
| Example: Send User Data Relay |
802+
+==================================================================================================================================================================+
803+
| The XBee Python Library includes a sample application that demonstrates how to send a User Data Relay message. You can locate the example in the following path: |
804+
| |
805+
| **examples/communication/relay/SendUserDataRelaySample** |
806+
+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
807+
808+
748809
Receive data
749810
------------
750811

@@ -1504,6 +1565,73 @@ unsubscribe the already-registered listener.
15041565
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
15051566

15061567

1568+
.. _communicateReceiveRelayData:
1569+
1570+
Receive data from other interfaces
1571+
----------------------------------
1572+
1573+
You can be notified when a new User Data Relay message has been received if you
1574+
are subscribed or registered to the User Data Relay reception service by using
1575+
the ``add_user_data_relay_received_callback`` method.
1576+
1577+
**User Data Relay reception registration**
1578+
1579+
.. code:: python
1580+
1581+
[...]
1582+
1583+
# Instantiate an XBee device object.
1584+
device = XBeeDevice("COM1", 9600)
1585+
device.open()
1586+
1587+
# Define the callback.
1588+
def my_data_relay_callback(relay_message):
1589+
print("Relay data received from %s >> '%s'" %
1590+
(relay_message.relay_interface.description,
1591+
relay_message.data.decode("utf-8")))
1592+
1593+
# Add the callback.
1594+
device.add_user_data_relay_received_callback(my_data_relay_callback)
1595+
1596+
[...]
1597+
1598+
When a new User Data Relay message is received, your callback is executed
1599+
providing a ``UserDataRelayMessage`` object as parameter. This object contains
1600+
the source interface that sent the data and the data itself.
1601+
1602+
To stop listening to new User Data Relay messages, use the
1603+
``del_user_data_relay_received_callback`` method to unsubscribe the
1604+
already-registered listener.
1605+
1606+
**Deregister User Data Relay reception**
1607+
1608+
.. code:: python
1609+
1610+
[...]
1611+
1612+
device = [...]
1613+
1614+
def my_data_relay_callback(relay_message):
1615+
[...]
1616+
1617+
device.add_user_data_relay_received_callback(my_data_relay_callback)
1618+
1619+
[...]
1620+
1621+
# Delete the User Data Relay callback.
1622+
device.del_user_data_relay_received_callback(my_data_relay_callback)
1623+
1624+
[...]
1625+
1626+
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1627+
| Example: Receive User Data Relay messages |
1628+
+==============================================================================================================================================================================================================================================+
1629+
| The XBee Python Library includes a sample application that demonstrates how to subscribe to the User Data Relay reception service in order to receive messages from other XBee interfaces. You can locate the example in the following path: |
1630+
| |
1631+
| **examples/communication/relay/ReceiveUserDataRelaySample** |
1632+
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1633+
1634+
15071635
.. _communicateReceiveModemStatus:
15081636

15091637
Receive modem status events

0 commit comments

Comments
 (0)