├── .gitignore ├── .readthedocs.yaml ├── CHANGELOG.rst ├── CONTRIBUTING.rst ├── LICENSE.txt ├── MANIFEST.in ├── README.rst ├── digi └── xbee │ ├── __init__.py │ ├── ble.py │ ├── comm_interface.py │ ├── devices.py │ ├── exception.py │ ├── filesystem.py │ ├── firmware.py │ ├── io.py │ ├── models │ ├── __init__.py │ ├── accesspoint.py │ ├── address.py │ ├── atcomm.py │ ├── filesystem.py │ ├── hw.py │ ├── info.py │ ├── message.py │ ├── mode.py │ ├── options.py │ ├── protocol.py │ ├── statistics.py │ ├── status.py │ └── zdo.py │ ├── packets │ ├── __init__.py │ ├── aft.py │ ├── base.py │ ├── bluetooth.py │ ├── cellular.py │ ├── common.py │ ├── devicecloud.py │ ├── digimesh.py │ ├── factory.py │ ├── filesystem.py │ ├── network.py │ ├── raw.py │ ├── relay.py │ ├── socket.py │ ├── wifi.py │ └── zigbee.py │ ├── profile.py │ ├── reader.py │ ├── recovery.py │ ├── sender.py │ ├── serial.py │ ├── util │ ├── __init__.py │ ├── exportutils.py │ ├── srp.py │ ├── utils.py │ └── xmodem.py │ └── xsocket.py ├── doc ├── Makefile ├── _static │ └── theme_overrides.css ├── api │ ├── digi.rst │ ├── digi.xbee.ble.rst │ ├── digi.xbee.comm_interface.rst │ ├── digi.xbee.devices.rst │ ├── digi.xbee.exception.rst │ ├── digi.xbee.filesystem.rst │ ├── digi.xbee.firmware.rst │ ├── digi.xbee.io.rst │ ├── digi.xbee.models.accesspoint.rst │ ├── digi.xbee.models.address.rst │ ├── digi.xbee.models.atcomm.rst │ ├── digi.xbee.models.filesystem.rst │ ├── digi.xbee.models.hw.rst │ ├── digi.xbee.models.info.rst │ ├── digi.xbee.models.message.rst │ ├── digi.xbee.models.mode.rst │ ├── digi.xbee.models.options.rst │ ├── digi.xbee.models.protocol.rst │ ├── digi.xbee.models.rst │ ├── digi.xbee.models.statistics.rst │ ├── digi.xbee.models.status.rst │ ├── digi.xbee.models.zdo.rst │ ├── digi.xbee.packets.aft.rst │ ├── digi.xbee.packets.base.rst │ ├── digi.xbee.packets.bluetooth.rst │ ├── digi.xbee.packets.cellular.rst │ ├── digi.xbee.packets.common.rst │ ├── digi.xbee.packets.devicecloud.rst │ ├── digi.xbee.packets.digimesh.rst │ ├── digi.xbee.packets.factory.rst │ ├── digi.xbee.packets.filesystem.rst │ ├── digi.xbee.packets.network.rst │ ├── digi.xbee.packets.raw.rst │ ├── digi.xbee.packets.relay.rst │ ├── digi.xbee.packets.rst │ ├── digi.xbee.packets.socket.rst │ ├── digi.xbee.packets.wifi.rst │ ├── digi.xbee.packets.zigbee.rst │ ├── digi.xbee.profile.rst │ ├── digi.xbee.reader.rst │ ├── digi.xbee.recovery.rst │ ├── digi.xbee.rst │ ├── digi.xbee.sender.rst │ ├── digi.xbee.serial.rst │ ├── digi.xbee.util.exportutils.rst │ ├── digi.xbee.util.rst │ ├── digi.xbee.util.srp.rst │ ├── digi.xbee.util.utils.rst │ ├── digi.xbee.util.xmodem.rst │ ├── digi.xbee.xsocket.rst │ └── modules.rst ├── changelog.rst ├── conf.py ├── examples.rst ├── faq.rst ├── getting_started_with_xbee_python_library.rst ├── images │ ├── concepts_api_frame.jpg │ ├── concepts_api_frame_explained.jpg │ ├── concepts_form_factor.jpg │ ├── concepts_protocol.png │ ├── faq_port_bd.png │ ├── xbplib_class_hierarchy.png │ └── xbplib_diagram_network.png ├── index.rst ├── make.bat ├── requirements.txt └── user_doc │ ├── communicating_with_xbee_devices.rst │ ├── configuring_the_xbee_device.rst │ ├── discovering_the_xbee_network.rst │ ├── handling_analog_and_digital_io_lines.rst │ ├── logging_events.rst │ ├── update_the_xbee.rst │ ├── working_with_xbee_classes.rst │ └── xbee_terminology.rst ├── examples ├── LICENSE.txt ├── communication │ ├── ReceiveDataPollingSample │ │ ├── ReceiveDataPollingSample.py │ │ └── readme.txt │ ├── ReceiveDataSample │ │ ├── ReceiveDataSample.py │ │ └── readme.txt │ ├── ReceiveModemStatusSample │ │ ├── ReceiveModemStatusSample.py │ │ └── readme.txt │ ├── SendBroadcastDataSample │ │ ├── SendBroadcastDataSample.py │ │ └── readme.txt │ ├── SendDataAsyncSample │ │ ├── SendDataAsyncSample.py │ │ └── readme.txt │ ├── SendDataSample │ │ ├── SendDataSample.py │ │ └── readme.txt │ ├── bluetooth │ │ ├── GapScanCursesDemo │ │ │ ├── GapScanCursesDemo.py │ │ │ └── readme.txt │ │ ├── GapScanExample │ │ │ ├── GapScanExample.py │ │ │ └── readme.txt │ │ ├── ReceiveBluetoothDataSample │ │ │ ├── ReceiveBluetoothDataSample.py │ │ │ └── readme.txt │ │ ├── ReceiveBluetoothFileSample │ │ │ ├── ReceiveBluetoothFileSample.py │ │ │ └── readme.txt │ │ └── SendBluetoothDataSample │ │ │ ├── SendBluetoothDataSample.py │ │ │ └── readme.txt │ ├── cellular │ │ ├── ReceiveSMSSample │ │ │ ├── ReceiveSMSSample.py │ │ │ └── readme.txt │ │ └── SendSMSSample │ │ │ ├── SendSMSSample.py │ │ │ └── readme.txt │ ├── explicit │ │ ├── ReceiveExplicitDataPollingSample │ │ │ ├── ReceiveExplicitDataPollingSample.py │ │ │ └── readme.txt │ │ ├── ReceiveExplicitDataSample │ │ │ ├── ReceiveExplicitDataSample.py │ │ │ └── readme.txt │ │ ├── SendBroadcastExplicitDataSample │ │ │ ├── SendBroadcastExplicitDataSample.py │ │ │ └── readme.txt │ │ ├── SendExplicitDataAsyncSample │ │ │ ├── SendExplicitDataAsyncSample.py │ │ │ └── readme.txt │ │ └── SendExplicitDataSample │ │ │ ├── SendExplicitDataSample.py │ │ │ └── readme.txt │ ├── ip │ │ ├── ConnectToEchoServerSample │ │ │ ├── ConnectToEchoServerSample.py │ │ │ └── readme.txt │ │ ├── ReceiveIPDataSample │ │ │ ├── ReceiveIPDataSample.py │ │ │ └── readme.txt │ │ ├── SendIPDataSample │ │ │ ├── SendIPDataSample.py │ │ │ └── readme.txt │ │ └── SendUDPDataSample │ │ │ ├── SendUDPDataSample.py │ │ │ └── readme.txt │ ├── micropython │ │ ├── ReceiveMicroPythonDataSample │ │ │ ├── ReceiveMicroPythonDataSample.py │ │ │ └── readme.txt │ │ └── SendMicroPythonDataSample │ │ │ ├── SendMicroPythonDataSample.py │ │ │ └── readme.txt │ ├── relay │ │ ├── ReceiveUserDataRelaySample │ │ │ ├── ReceiveUserDataRelaySample.py │ │ │ └── readme.txt │ │ └── SendUserDataRelaySample │ │ │ ├── SendUserDataRelaySample.py │ │ │ └── readme.txt │ └── socket │ │ ├── SocketTCPClientSample │ │ ├── SocketTCPClientSample.py │ │ └── readme.txt │ │ ├── SocketTCPServerSample │ │ ├── PCClient.py │ │ ├── SocketTCPServerSample.py │ │ └── readme.txt │ │ └── SocketUDPServerClientSample │ │ ├── SocketUDPServerSample.py │ │ └── readme.txt ├── configuration │ ├── ConnectToAccessPointSample │ │ ├── ConnectToAccessPointSample.py │ │ └── readme.txt │ ├── ManageCommonParametersSample │ │ ├── ManageCommonParametersSample.py │ │ └── readme.txt │ ├── RecoverSerialConnection │ │ ├── RecoverSerialConnection.py │ │ └── readme.txt │ ├── ResetModuleSample │ │ ├── ResetModuleSample.py │ │ └── readme.txt │ └── SetAndGetParametersSample │ │ ├── SetAndGetParametersSample.py │ │ └── readme.txt ├── filesystem │ ├── FormatFilesystemSample │ │ ├── FormatFilesystemSample.py │ │ └── readme.txt │ ├── ListDirectorySample │ │ ├── ListDirectorySample.py │ │ └── readme.txt │ ├── UploadDownloadFileSample │ │ ├── UploadDownloadFileSample.py │ │ └── readme.txt │ └── legacy │ │ ├── FormatFilesystemSample │ │ ├── FormatFilesystemSample.py │ │ └── readme.txt │ │ ├── ListDirectorySample │ │ ├── ListDirectorySample.py │ │ └── readme.txt │ │ ├── RemoteFilesystemUpdateSample │ │ ├── RemoteFilesystemUpdateSample.py │ │ └── readme.txt │ │ └── UploadDownloadFileSample │ │ ├── UploadDownloadFileSample.py │ │ └── readme.txt ├── firmware │ ├── LocalFirmwareUpdateSample │ │ ├── LocalFirmwareUpdateSample.py │ │ └── readme.txt │ └── RemoteFirmwareUpdateSample │ │ ├── RemoteFirmwareUpdateSample.py │ │ └── readme.txt ├── io │ ├── IOSamplingSample │ │ ├── IOSamplingSample.py │ │ └── readme.txt │ ├── LocalADCSample │ │ ├── LocalADCSample.py │ │ └── readme.txt │ ├── LocalDIOSample │ │ ├── LocalDIOSample.py │ │ └── readme.txt │ ├── RemoteADCSample │ │ ├── RemoteADCSample.py │ │ └── readme.txt │ └── RemoteDIOSample │ │ ├── RemoteDIOSample.py │ │ └── readme.txt ├── network │ ├── DiscoverDevicesSample │ │ ├── DiscoverDevicesSample.py │ │ └── readme.txt │ └── NetworkModificationsSample │ │ ├── NetworkModificationsSample.py │ │ └── readme.txt ├── profile │ ├── ApplyXBeeProfileRemoteSample │ │ ├── ApplyXBeeProfileRemoteSample.py │ │ └── readme.txt │ ├── ApplyXBeeProfileSample │ │ ├── ApplyXBeeProfileSample.py │ │ └── readme.txt │ └── ReadXBeeProfileSample │ │ ├── ReadXBeeProfileSample.py │ │ └── readme.txt └── statistics │ └── GetXBeeStatisticsSample │ ├── GetXBeeStatisticsSample.py │ └── readme.txt ├── functional_tests ├── Bluetooth │ ├── device_info.py │ └── test_gap_scan.py ├── comunication │ ├── read_data_timeout.py │ └── send_data_16.py ├── configuration │ ├── get_set_api_output_mode.py │ ├── get_set_params_local_remote.py │ └── reset.py ├── filesystem │ ├── fs_test.py │ └── resources │ │ ├── f_10K.txt │ │ ├── f_1K.txt │ │ ├── f_2K.txt │ │ ├── f_3K.txt │ │ └── f_5K.txt ├── io │ ├── pwm_duty_cycle.py │ └── read_io_sample.py ├── long_test.py ├── network │ ├── add_devices_to_network.py │ ├── add_remote_device_reader.py │ ├── discover_network.py │ └── discover_specific_devices.py └── test.py ├── requirements.txt ├── setup.py └── tox.ini /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | /doc/_build 3 | .idea 4 | venv/ 5 | /dist/ 6 | -------------------------------------------------------------------------------- /.readthedocs.yaml: -------------------------------------------------------------------------------- 1 | # Read the Docs configuration file for Sphinx projects 2 | # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details 3 | 4 | # Required 5 | version: 2 6 | 7 | # Set the OS, Python version and other tools you might need 8 | build: 9 | os: ubuntu-22.04 10 | tools: 11 | python: "3.12" 12 | # You can also specify other tool versions: 13 | # nodejs: "20" 14 | # rust: "1.70" 15 | # golang: "1.20" 16 | 17 | # Build documentation in the "doc/" directory with Sphinx 18 | sphinx: 19 | configuration: doc/conf.py 20 | # Configure Sphinx to use a different builder, for instance use the dirhtml builder for simpler URLs 21 | # builder: "dirhtml" 22 | # Fail on all warnings to avoid broken references 23 | # fail_on_warning: true 24 | 25 | # Optionally build your docs in additional formats such as PDF and ePub 26 | # formats: 27 | # - pdf 28 | # - epub 29 | 30 | # Declare the Python requirements required to build your documentation 31 | # See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html 32 | python: 33 | install: 34 | - requirements: doc/requirements.txt 35 | -------------------------------------------------------------------------------- /CONTRIBUTING.rst: -------------------------------------------------------------------------------- 1 | How to Contribute 2 | ================= 3 | 4 | 5 | Getting help 6 | ------------ 7 | 8 | To ask questions about the XBee Python library go to the 9 | `Digi Forum `_. 10 | 11 | 12 | Reporting a bug 13 | --------------- 14 | 15 | The way to report bugs is to use the 16 | `GitHub issue tracker `_. 17 | Before reporting a bug, please read the following points: 18 | 19 | #. Make sure that what you are seeing is really a bug by checking the 20 | `documentation `_ and consulting 21 | the `FAQs `_ section. 22 | #. If you still think you have found a bug, make sure someone has not already 23 | reported it. See the list of 24 | `known issues `_. 25 | #. If it has not been reported yet, create a new issue. Make sure to add enough 26 | detail so that the bug can be reproduced. 27 | 28 | .. Note:: 29 | The issue tracker is for bugs, not requests for help. Questions 30 | should be asked on the `Digi Forum `_ 31 | instead. 32 | 33 | 34 | Suggesting a new feature 35 | ------------------------ 36 | 37 | #. Consult the `FAQs `_ 38 | section to ensure that the behavior you would like the library to have is 39 | not excluded. 40 | #. Make sure someone has not already requested it. See the list of 41 | `known issues `_. 42 | #. Submit your request in the issue tracker. 43 | 44 | 45 | Contributing code 46 | ----------------- 47 | 48 | #. Fork the `XBee Python library `_ 49 | repository (`how to fork a repo 50 | `_). 51 | #. Create a branch for your contribution. Use a name that defines the purpose 52 | of the additions/modifications. 53 | #. Make your changes following the code style used in the library. 54 | #. Submit a pull request (`how to create a pull request 55 | `_). A project 56 | developer will review your work and then merge your request into the 57 | project, or come back to you with comments and/or questions. 58 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | # Example files 2 | recursive-include examples * 3 | 4 | # Misc 5 | include CHANGELOG.rst 6 | include LICENSE.txt 7 | include README.rst 8 | include requirements.txt -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | Digi XBee Python library |pypiversion| |pythonversion| 2 | ====================================================== 3 | 4 | This project contains the source code of the XBee Python library, an 5 | easy-to-use API developed in Python that allows you to interact with Digi 6 | International's `XBee `_ radio frequency (RF) 7 | modules. 8 | 9 | This source has been contributed by Digi International. 10 | 11 | 12 | Installation 13 | ------------ 14 | 15 | You can install XBee Python library using `pip 16 | `_:: 17 | 18 | $ pip install digi-xbee 19 | 20 | 21 | Install from Source 22 | ------------------- 23 | 24 | You can install XBee Python library directly from sources. To do so, extract 25 | the source code to your computer and execute the following command:: 26 | 27 | $ pip install 28 | 29 | 30 | Documentation 31 | ------------- 32 | 33 | XBee Python library has user guide and API reference documentation hosted on 34 | Read the Docs. You can find the latest, most up to date, documentation at 35 | `latest docs `_. To see only those 36 | features which have been released, check out the 37 | `stable docs `_. 38 | 39 | 40 | How to contribute 41 | ----------------- 42 | 43 | The contributing guidelines are in the `CONTRIBUTING.rst document 44 | `_. 45 | 46 | 47 | License 48 | ------- 49 | 50 | Copyright 2017-2024, Digi International Inc. 51 | 52 | The `MPL 2.0 license `_ 53 | covers the majority of this project with the following exceptions: 54 | 55 | * The `ISC license `_ 56 | covers the contents of the examples directory. 57 | 58 | .. |pypiversion| image:: https://badge.fury.io/py/digi-xbee.svg 59 | :target: https://pypi.org/project/digi-xbee/ 60 | .. |pythonversion| image:: https://img.shields.io/pypi/pyversions/digi-xbee.svg 61 | :alt: PyPI - Python Version 62 | -------------------------------------------------------------------------------- /digi/xbee/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017-2024, Digi International Inc. 2 | # 3 | # This Source Code Form is subject to the terms of the Mozilla Public 4 | # License, v. 2.0. If a copy of the MPL was not distributed with this 5 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | __version__ = '1.5.0' 16 | __title__ = 'digi-xbee' 17 | __description__ = 'Digi XBee Python library' 18 | __url__ = 'https://github.com/digidotcom/xbee-python' 19 | __author__ = 'Digi International Inc.' 20 | __author_email__ = 'tech.support@digi.com' 21 | __license__ = 'Mozilla Public License 2.0 (MPL 2.0)' 22 | __copyright__ = '2017-2024, Digi International Inc.' 23 | -------------------------------------------------------------------------------- /digi/xbee/models/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017, Digi International Inc. 2 | # 3 | # This Source Code Form is subject to the terms of the Mozilla Public 4 | # License, v. 2.0. If a copy of the MPL was not distributed with this 5 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | -------------------------------------------------------------------------------- /digi/xbee/packets/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017, Digi International Inc. 2 | # 3 | # This Source Code Form is subject to the terms of the Mozilla Public 4 | # License, v. 2.0. If a copy of the MPL was not distributed with this 5 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | -------------------------------------------------------------------------------- /digi/xbee/util/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017, Digi International Inc. 2 | # 3 | # This Source Code Form is subject to the terms of the Mozilla Public 4 | # License, v. 2.0. If a copy of the MPL was not distributed with this 5 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | -------------------------------------------------------------------------------- /doc/_static/theme_overrides.css: -------------------------------------------------------------------------------- 1 | /* override table width restrictions */ 2 | @media screen and (min-width: 767px) { 3 | 4 | .wy-table-responsive table td { 5 | /* !important prevents the common CSS stylesheets from overriding 6 | this as on RTD they are loaded after this stylesheet */ 7 | white-space: normal !important; 8 | } 9 | 10 | .wy-table-responsive { 11 | overflow: visible !important; 12 | } 13 | } -------------------------------------------------------------------------------- /doc/api/digi.rst: -------------------------------------------------------------------------------- 1 | digi package 2 | ============ 3 | 4 | .. automodule:: digi 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | 9 | Subpackages 10 | ----------- 11 | 12 | .. toctree:: 13 | 14 | digi.xbee 15 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.ble.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.ble module 2 | ============================= 3 | 4 | .. automodule:: digi.xbee.ble 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.comm_interface.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.comm_interface module 2 | ================================= 3 | 4 | .. automodule:: digi.xbee.comm_interface 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.devices.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.devices module 2 | ========================== 3 | 4 | .. automodule:: digi.xbee.devices 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.exception.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.exception module 2 | ============================ 3 | 4 | .. automodule:: digi.xbee.exception 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.filesystem.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.filesystem module 2 | ============================= 3 | 4 | .. automodule:: digi.xbee.filesystem 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.firmware.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.firmware module 2 | =========================== 3 | 4 | .. automodule:: digi.xbee.firmware 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.io.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.io module 2 | ===================== 3 | 4 | .. automodule:: digi.xbee.io 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.models.accesspoint.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.models\.accesspoint module 2 | ====================================== 3 | 4 | .. automodule:: digi.xbee.models.accesspoint 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.models.address.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.models\.address module 2 | ================================== 3 | 4 | .. automodule:: digi.xbee.models.address 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.models.atcomm.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.models\.atcomm module 2 | ================================= 3 | 4 | .. automodule:: digi.xbee.models.atcomm 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.models.filesystem.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.models\.filesystem module 2 | ===================================== 3 | 4 | .. automodule:: digi.xbee.models.filesystem 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.models.hw.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.models\.hw module 2 | ============================= 3 | 4 | .. automodule:: digi.xbee.models.hw 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.models.info.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.models\.info module 2 | =============================== 3 | 4 | .. automodule:: digi.xbee.models.info 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.models.message.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.models\.message module 2 | ================================== 3 | 4 | .. automodule:: digi.xbee.models.message 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.models.mode.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.models\.mode module 2 | =============================== 3 | 4 | .. automodule:: digi.xbee.models.mode 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.models.options.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.models\.options module 2 | ================================== 3 | 4 | .. automodule:: digi.xbee.models.options 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.models.protocol.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.models\.protocol module 2 | =================================== 3 | 4 | .. automodule:: digi.xbee.models.protocol 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.models.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.models package 2 | ========================== 3 | 4 | .. automodule:: digi.xbee.models 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | .. toctree:: 13 | 14 | digi.xbee.models.accesspoint 15 | digi.xbee.models.atcomm 16 | digi.xbee.models.filesystem 17 | digi.xbee.models.hw 18 | digi.xbee.models.info 19 | digi.xbee.models.mode 20 | digi.xbee.models.address 21 | digi.xbee.models.message 22 | digi.xbee.models.options 23 | digi.xbee.models.protocol 24 | digi.xbee.models.statistics 25 | digi.xbee.models.status 26 | digi.xbee.models.zdo 27 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.models.statistics.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.models\.statistics module 2 | ===================================== 3 | 4 | .. automodule:: digi.xbee.models.statistics 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.models.status.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.models\.status module 2 | ================================= 3 | 4 | .. automodule:: digi.xbee.models.status 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.models.zdo.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.models.zdo package 2 | ============================== 3 | 4 | .. automodule:: digi.xbee.models.zdo 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.packets.aft.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.packets\.aft module 2 | =============================== 3 | 4 | .. automodule:: digi.xbee.packets.aft 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.packets.base.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.packets\.base module 2 | ================================ 3 | 4 | .. automodule:: digi.xbee.packets.base 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.packets.bluetooth.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.packets\.bluetooth module 2 | ===================================== 3 | 4 | .. automodule:: digi.xbee.packets.bluetooth 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.packets.cellular.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.packets\.cellular module 2 | ==================================== 3 | 4 | .. automodule:: digi.xbee.packets.cellular 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.packets.common.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.packets\.common module 2 | ================================== 3 | 4 | .. automodule:: digi.xbee.packets.common 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.packets.devicecloud.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.packets\.devicecloud module 2 | ======================================= 3 | 4 | .. automodule:: digi.xbee.packets.devicecloud 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.packets.digimesh.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.packets\.digimesh module 2 | ==================================== 3 | 4 | .. automodule:: digi.xbee.packets.digimesh 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.packets.factory.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.packets\.factory module 2 | =================================== 3 | 4 | .. automodule:: digi.xbee.packets.factory 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.packets.filesystem.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.packets\.filesystem module 2 | ====================================== 3 | 4 | .. automodule:: digi.xbee.packets.filesystem 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.packets.network.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.packets\.network module 2 | =================================== 3 | 4 | .. automodule:: digi.xbee.packets.network 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.packets.raw.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.packets\.raw module 2 | =============================== 3 | 4 | .. automodule:: digi.xbee.packets.raw 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.packets.relay.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.packets\.relay module 2 | =================================== 3 | 4 | .. automodule:: digi.xbee.packets.relay 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.packets.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.packets package 2 | =========================== 3 | 4 | .. automodule:: digi.xbee.packets 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | .. toctree:: 13 | 14 | digi.xbee.packets.aft 15 | digi.xbee.packets.base 16 | digi.xbee.packets.bluetooth 17 | digi.xbee.packets.cellular 18 | digi.xbee.packets.common 19 | digi.xbee.packets.devicecloud 20 | digi.xbee.packets.digimesh 21 | digi.xbee.packets.filesystem 22 | digi.xbee.packets.network 23 | digi.xbee.packets.raw 24 | digi.xbee.packets.relay 25 | digi.xbee.packets.socket 26 | digi.xbee.packets.wifi 27 | digi.xbee.packets.zigbee 28 | digi.xbee.packets.factory 29 | 30 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.packets.socket.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.packets\.socket module 2 | =================================== 3 | 4 | .. automodule:: digi.xbee.packets.socket 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.packets.wifi.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.packets\.wifi module 2 | ================================ 3 | 4 | .. automodule:: digi.xbee.packets.wifi 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.packets.zigbee.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.packets\.zigbee module 2 | =================================== 3 | 4 | .. automodule:: digi.xbee.packets.zigbee 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.profile.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.profile module 2 | ========================== 3 | 4 | .. automodule:: digi.xbee.profile 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.reader.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.reader module 2 | ========================== 3 | 4 | .. automodule:: digi.xbee.reader 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.recovery.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.recovery module 2 | =========================== 3 | 4 | .. automodule:: digi.xbee.recovery 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee package 2 | ================== 3 | 4 | .. automodule:: digi.xbee 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | 9 | Subpackages 10 | ----------- 11 | 12 | .. toctree:: 13 | 14 | digi.xbee.models 15 | digi.xbee.packets 16 | digi.xbee.util 17 | 18 | Submodules 19 | ---------- 20 | 21 | .. toctree:: 22 | 23 | digi.xbee.ble 24 | digi.xbee.comm_interface 25 | digi.xbee.devices 26 | digi.xbee.exception 27 | digi.xbee.filesystem 28 | digi.xbee.firmware 29 | digi.xbee.io 30 | digi.xbee.profile 31 | digi.xbee.reader 32 | digi.xbee.recovery 33 | digi.xbee.sender 34 | digi.xbee.serial 35 | digi.xbee.xsocket 36 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.sender.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.sender module 2 | ========================== 3 | 4 | .. automodule:: digi.xbee.sender 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.serial.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.serial module 2 | ========================= 3 | 4 | .. automodule:: digi.xbee.serial 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.util.exportutils.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.util\.exportutils module 2 | ==================================== 3 | 4 | .. automodule:: digi.xbee.util.exportutils 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.util.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.util package 2 | ======================== 3 | 4 | .. automodule:: digi.xbee.util 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | .. toctree:: 13 | 14 | digi.xbee.util.exportutils 15 | digi.xbee.util.srp 16 | digi.xbee.util.utils 17 | digi.xbee.util.xmodem 18 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.util.srp.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.util\.srp module 2 | =============================== 3 | 4 | .. automodule:: digi.xbee.util.srp 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.util.utils.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.util\.utils module 2 | ============================== 3 | 4 | .. automodule:: digi.xbee.util.utils 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.util.xmodem.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.util\.xmodem module 2 | =============================== 3 | 4 | .. automodule:: digi.xbee.util.xmodem 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/api/digi.xbee.xsocket.rst: -------------------------------------------------------------------------------- 1 | digi\.xbee\.xsocket module 2 | ========================== 3 | 4 | .. automodule:: digi.xbee.xsocket 5 | :members: 6 | :inherited-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/api/modules.rst: -------------------------------------------------------------------------------- 1 | API reference 2 | ============= 3 | 4 | Following is API reference material on major parts of XBee Python library. 5 | 6 | .. toctree:: 7 | :maxdepth: 5 8 | 9 | digi 10 | -------------------------------------------------------------------------------- /doc/changelog.rst: -------------------------------------------------------------------------------- 1 | .. _changelog: 2 | 3 | .. include:: ../CHANGELOG.rst -------------------------------------------------------------------------------- /doc/faq.rst: -------------------------------------------------------------------------------- 1 | Frequently Asked Questions (FAQs) 2 | ================================= 3 | 4 | The FAQ section contains answers to general questions related to the XBee 5 | Python Library. 6 | 7 | 8 | What is XCTU and how do I download it? 9 | -------------------------------------- 10 | 11 | XCTU is a free multi-platform application designed to enable developers to 12 | interact with Digi RF modules through a simple-to-use graphical interface. You 13 | can download it at `www.digi.com/xctu `_. 14 | 15 | 16 | How do I find the serial port and baud rate of my module? 17 | --------------------------------------------------------- 18 | 19 | Open the XCTU application, and click the **Discover radio modules connected to your 20 | machine** button. 21 | 22 | Select all ports to be scanned, click **Next** and then **Finish**. Once the 23 | discovery process has finished, a new window notifies you how many devices have 24 | been found and their details. The serial port and the baud rate are shown in 25 | the **Port** label. 26 | 27 | .. image:: images/faq_port_bd.png 28 | :align: center 29 | :alt: Get port and baudrate 30 | 31 | .. note:: 32 | Note In UNIX systems, the complete name of the serial port contains the 33 | **/dev/ prefix**. 34 | 35 | 36 | Can I use the XBee Python Library with modules in AT operating mode? 37 | -------------------------------------------------------------------- 38 | 39 | The XBee Python Library only supports **API** and **API Escaped** operating 40 | modes. 41 | 42 | If your devices are using a different operating mode, or even a different 43 | serial communication configuration (baud rate, stop bits, etc.), use 44 | `force_settings=True` in the `open()` method. This parameter tells the library 45 | to establish the provided serial settings and change the operating mode to 46 | **API** to be able to work with connected XBee devices. 47 | See :ref:`openXBeeConnection`. 48 | 49 | 50 | I get the Python error ``ImportError: No module named 'serial'`` 51 | ---------------------------------------------------------------- 52 | 53 | This error means that Python cannot find the ``serial`` module, which is used by 54 | the library for the serial communication with the XBee devices. 55 | 56 | You can install PySerial running this command in your terminal application: 57 | 58 | .. code:: 59 | 60 | $ pip install pyserial 61 | 62 | For further information about the installation of PySerial, refer to the 63 | `PySerial installation guide 64 | `_. 65 | -------------------------------------------------------------------------------- /doc/images/concepts_api_frame.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/digidotcom/xbee-python/f90bd78be0da2d77b009516a7c285b28ac5a02ad/doc/images/concepts_api_frame.jpg -------------------------------------------------------------------------------- /doc/images/concepts_api_frame_explained.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/digidotcom/xbee-python/f90bd78be0da2d77b009516a7c285b28ac5a02ad/doc/images/concepts_api_frame_explained.jpg -------------------------------------------------------------------------------- /doc/images/concepts_form_factor.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/digidotcom/xbee-python/f90bd78be0da2d77b009516a7c285b28ac5a02ad/doc/images/concepts_form_factor.jpg -------------------------------------------------------------------------------- /doc/images/concepts_protocol.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/digidotcom/xbee-python/f90bd78be0da2d77b009516a7c285b28ac5a02ad/doc/images/concepts_protocol.png -------------------------------------------------------------------------------- /doc/images/faq_port_bd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/digidotcom/xbee-python/f90bd78be0da2d77b009516a7c285b28ac5a02ad/doc/images/faq_port_bd.png -------------------------------------------------------------------------------- /doc/images/xbplib_class_hierarchy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/digidotcom/xbee-python/f90bd78be0da2d77b009516a7c285b28ac5a02ad/doc/images/xbplib_class_hierarchy.png -------------------------------------------------------------------------------- /doc/images/xbplib_diagram_network.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/digidotcom/xbee-python/f90bd78be0da2d77b009516a7c285b28ac5a02ad/doc/images/xbplib_diagram_network.png -------------------------------------------------------------------------------- /doc/requirements.txt: -------------------------------------------------------------------------------- 1 | sphinx_rtd_theme -------------------------------------------------------------------------------- /examples/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright 2017, Digi International Inc. 2 | 3 | Note that this license pertains to the contents of this directory 4 | (examples) and its subdirectories ONLY. The top-level LICENSE.txt 5 | file covers the remaining repository contents. 6 | 7 | Permission to use, copy, modify, and/or distribute this software for any 8 | purpose with or without fee is hereby granted, provided that the above 9 | copyright notice and this permission notice appear in all copies. 10 | 11 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 | -------------------------------------------------------------------------------- /examples/communication/ReceiveDataPollingSample/ReceiveDataPollingSample.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017, Digi International Inc. 2 | # 3 | # Permission to use, copy, modify, and/or distribute this software for any 4 | # purpose with or without fee is hereby granted, provided that the above 5 | # copyright notice and this permission notice appear in all copies. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | from digi.xbee.devices import XBeeDevice 16 | 17 | # TODO: Replace with the serial port where your local module is connected to. 18 | PORT = "COM1" 19 | # TODO: Replace with the baud rate of your local module. 20 | BAUD_RATE = 9600 21 | 22 | 23 | def main(): 24 | print(" +-------------------------------------------------+") 25 | print(" | XBee Python Library Receive Data Polling Sample |") 26 | print(" +-------------------------------------------------+\n") 27 | 28 | device = XBeeDevice(PORT, BAUD_RATE) 29 | 30 | try: 31 | device.open() 32 | 33 | device.flush_queues() 34 | 35 | print("Waiting for data...\n") 36 | 37 | while True: 38 | xbee_message = device.read_data() 39 | if xbee_message is not None: 40 | print("From %s >> %s" % (xbee_message.remote_device.get_64bit_addr(), 41 | xbee_message.data.decode())) 42 | 43 | finally: 44 | if device is not None and device.is_open(): 45 | device.close() 46 | 47 | 48 | if __name__ == '__main__': 49 | main() 50 | -------------------------------------------------------------------------------- /examples/communication/ReceiveDataSample/ReceiveDataSample.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017, Digi International Inc. 2 | # 3 | # Permission to use, copy, modify, and/or distribute this software for any 4 | # purpose with or without fee is hereby granted, provided that the above 5 | # copyright notice and this permission notice appear in all copies. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | from digi.xbee.devices import XBeeDevice 16 | 17 | # TODO: Replace with the serial port where your local module is connected to. 18 | PORT = "COM1" 19 | # TODO: Replace with the baud rate of your local module. 20 | BAUD_RATE = 9600 21 | 22 | 23 | def main(): 24 | print(" +-----------------------------------------+") 25 | print(" | XBee Python Library Receive Data Sample |") 26 | print(" +-----------------------------------------+\n") 27 | 28 | device = XBeeDevice(PORT, BAUD_RATE) 29 | 30 | try: 31 | device.open() 32 | 33 | def data_receive_callback(xbee_message): 34 | print("From %s >> %s" % (xbee_message.remote_device.get_64bit_addr(), 35 | xbee_message.data.decode())) 36 | 37 | device.add_data_received_callback(data_receive_callback) 38 | 39 | print("Waiting for data...\n") 40 | input() 41 | 42 | finally: 43 | if device is not None and device.is_open(): 44 | device.close() 45 | 46 | 47 | if __name__ == '__main__': 48 | main() 49 | -------------------------------------------------------------------------------- /examples/communication/ReceiveModemStatusSample/ReceiveModemStatusSample.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017, Digi International Inc. 2 | # 3 | # Permission to use, copy, modify, and/or distribute this software for any 4 | # purpose with or without fee is hereby granted, provided that the above 5 | # copyright notice and this permission notice appear in all copies. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | from digi.xbee.devices import XBeeDevice 16 | from digi.xbee.util import utils 17 | 18 | # TODO: Replace with the serial port where your local module is connected to. 19 | PORT = "COM1" 20 | # TODO: Replace with the baud rate of your local module. 21 | BAUD_RATE = 9600 22 | 23 | 24 | def main(): 25 | print(" +-------------------------------------------------+") 26 | print(" | XBee Python Library Receive Modem Status Sample |") 27 | print(" +-------------------------------------------------+\n") 28 | 29 | device = XBeeDevice(PORT, BAUD_RATE) 30 | 31 | try: 32 | device.open() 33 | 34 | def modem_status_receive_callback(modem_status): 35 | print("Modem Status event received: %s: %s" % (utils.hex_to_string(utils.int_to_bytes(modem_status.code, 36 | 1)), 37 | modem_status.description)) 38 | 39 | device.add_modem_status_received_callback(modem_status_receive_callback) 40 | 41 | print("Waiting for Modem Status events...\n") 42 | input() 43 | 44 | finally: 45 | if device is not None and device.is_open(): 46 | device.close() 47 | 48 | 49 | if __name__ == '__main__': 50 | main() 51 | -------------------------------------------------------------------------------- /examples/communication/ReceiveModemStatusSample/readme.txt: -------------------------------------------------------------------------------- 1 | Introduction 2 | ------------ 3 | This sample Python application shows how modem status packets (events related 4 | to the device and the network) are handled using the API. 5 | 6 | The application prints the modem status events to the standard output when 7 | received. 8 | 9 | NOTE: This example uses the generic XBee device (XBeeDevice) class, 10 | but it can be applied to any other local XBee device class. 11 | 12 | 13 | Requirements 14 | ------------ 15 | To run this example you will need: 16 | 17 | * One XBee radio in API mode and its corresponding carrier board (XBIB 18 | or XBee Development Board). 19 | * The XCTU application (available at www.digi.com/xctu). 20 | 21 | 22 | Compatible protocols 23 | -------------------- 24 | * 802.15.4 25 | * Cellular 26 | * Cellular NB-IoT 27 | * DigiMesh 28 | * Point-to-Multipoint 29 | * Wi-Fi 30 | * Zigbee 31 | 32 | 33 | Example setup 34 | ------------- 35 | 1) Plug the XBee radio into the XBee adapter and connect it to your 36 | computer's USB or serial ports. 37 | 38 | 2) Ensure that the module is in API mode. 39 | For further information on how to perform this task, read the 40 | 'Configuring Your XBee Modules' topic of the Getting Started guide. 41 | 42 | 3) Set the port and baud rate of the XBee radio in the sample file. 43 | If you configured the module in the previous step with the XCTU, you 44 | will see the port number and baud rate in the 'Port' label of the device 45 | on the left view. 46 | 47 | 48 | Running the example 49 | ------------------- 50 | First, build and launch the application. When the application is executed, 51 | it will print the following message in the output console: 52 | 53 | "Waiting for Modem Status events..." 54 | 55 | Now you have to generate a Modem Status event. The easiest way to do so is 56 | by resetting the XBee device. So, press the Reset button of the carrier board 57 | the XBee device is attached to. 58 | 59 | As soon as the module is reset, the application will display a line 60 | containing a Reset Modem Status event: 61 | 62 | "Modem Status event received: 00: Device was reset" 63 | 64 | If the device joins a network you will also see a Joined Network Modem 65 | Status event in the output console: 66 | 67 | "Modem Status event received: 02: Device joined to network" 68 | -------------------------------------------------------------------------------- /examples/communication/SendBroadcastDataSample/SendBroadcastDataSample.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017, Digi International Inc. 2 | # 3 | # Permission to use, copy, modify, and/or distribute this software for any 4 | # purpose with or without fee is hereby granted, provided that the above 5 | # copyright notice and this permission notice appear in all copies. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | from digi.xbee.devices import XBeeDevice 16 | 17 | # TODO: Replace with the serial port where your local module is connected to. 18 | PORT = "COM1" 19 | # TODO: Replace with the baud rate of your local module. 20 | BAUD_RATE = 9600 21 | 22 | DATA_TO_SEND = "Hello XBee!" 23 | 24 | 25 | def main(): 26 | print(" +------------------------------------------------+") 27 | print(" | XBee Python Library Send Broadcast Data Sample |") 28 | print(" +------------------------------------------------+\n") 29 | 30 | device = XBeeDevice(PORT, BAUD_RATE) 31 | 32 | try: 33 | device.open() 34 | 35 | print("Sending broadcast data: %s..." % DATA_TO_SEND) 36 | 37 | device.send_data_broadcast(DATA_TO_SEND) 38 | 39 | print("Success") 40 | 41 | finally: 42 | if device is not None and device.is_open(): 43 | device.close() 44 | 45 | 46 | if __name__ == '__main__': 47 | main() 48 | -------------------------------------------------------------------------------- /examples/communication/SendDataAsyncSample/SendDataAsyncSample.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017, Digi International Inc. 2 | # 3 | # Permission to use, copy, modify, and/or distribute this software for any 4 | # purpose with or without fee is hereby granted, provided that the above 5 | # copyright notice and this permission notice appear in all copies. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | from digi.xbee.devices import XBeeDevice 16 | 17 | # TODO: Replace with the serial port where your local module is connected to. 18 | PORT = "COM1" 19 | # TODO: Replace with the baud rate of your local module. 20 | BAUD_RATE = 9600 21 | 22 | DATA_TO_SEND = "Hello XBee!" 23 | REMOTE_NODE_ID = "REMOTE" 24 | 25 | 26 | def main(): 27 | print(" +-----------------------------------------------------+") 28 | print(" | XBee Python Library Send Data Asynchronously Sample |") 29 | print(" +-----------------------------------------------------+\n") 30 | 31 | device = XBeeDevice(PORT, BAUD_RATE) 32 | 33 | try: 34 | device.open() 35 | 36 | # Obtain the remote XBee device from the XBee network. 37 | xbee_network = device.get_network() 38 | remote_device = xbee_network.discover_device(REMOTE_NODE_ID) 39 | if remote_device is None: 40 | print("Could not find the remote device") 41 | exit(1) 42 | 43 | print("Sending data asynchronously to %s >> %s..." % (remote_device.get_64bit_addr(), DATA_TO_SEND)) 44 | 45 | device.send_data_async(remote_device, DATA_TO_SEND) 46 | 47 | print("Success") 48 | 49 | finally: 50 | if device is not None and device.is_open(): 51 | device.close() 52 | 53 | 54 | if __name__ == '__main__': 55 | main() 56 | -------------------------------------------------------------------------------- /examples/communication/SendDataSample/SendDataSample.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017, Digi International Inc. 2 | # 3 | # Permission to use, copy, modify, and/or distribute this software for any 4 | # purpose with or without fee is hereby granted, provided that the above 5 | # copyright notice and this permission notice appear in all copies. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | from digi.xbee.devices import XBeeDevice 16 | 17 | # TODO: Replace with the serial port where your local module is connected to. 18 | PORT = "COM1" 19 | # TODO: Replace with the baud rate of your local module. 20 | BAUD_RATE = 9600 21 | 22 | DATA_TO_SEND = "Hello XBee!" 23 | REMOTE_NODE_ID = "REMOTE" 24 | 25 | 26 | def main(): 27 | print(" +--------------------------------------+") 28 | print(" | XBee Python Library Send Data Sample |") 29 | print(" +--------------------------------------+\n") 30 | 31 | device = XBeeDevice(PORT, BAUD_RATE) 32 | 33 | try: 34 | device.open() 35 | 36 | # Obtain the remote XBee device from the XBee network. 37 | xbee_network = device.get_network() 38 | remote_device = xbee_network.discover_device(REMOTE_NODE_ID) 39 | if remote_device is None: 40 | print("Could not find the remote device") 41 | exit(1) 42 | 43 | print("Sending data to %s >> %s..." % (remote_device.get_64bit_addr(), DATA_TO_SEND)) 44 | 45 | device.send_data(remote_device, DATA_TO_SEND) 46 | 47 | print("Success") 48 | 49 | finally: 50 | if device is not None and device.is_open(): 51 | device.close() 52 | 53 | 54 | if __name__ == '__main__': 55 | main() 56 | -------------------------------------------------------------------------------- /examples/communication/bluetooth/GapScanExample/GapScanExample.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024, Digi International Inc. 2 | # 3 | # Permission to use, copy, modify, and/or distribute this software for any 4 | # purpose with or without fee is hereby granted, provided that the above 5 | # copyright notice and this permission notice appear in all copies. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | import time 16 | from digi.xbee.devices import BluDevice 17 | from digi.xbee.models.message import ( 18 | BLEGAPScanLegacyAdvertisementMessage, 19 | BLEGAPScanExtendedAdvertisementMessage, 20 | ) 21 | 22 | 23 | # TODO: Replace with the serial port where your local module is connected to. 24 | PORT = "COM1" 25 | # TODO: Replace with the baud rate of your local module. 26 | BAUD_RATE = 9600 27 | 28 | # Time for the BLE GAP scan to run for 29 | TIME_TO_SCAN = 10 30 | 31 | 32 | def main(): 33 | print(" +---------------------------------------------------+") 34 | print(" | XBee Python Library Receive Bluetooth Data Sample |") 35 | print(" +---------------------------------------------------+\n") 36 | 37 | device = BluDevice(PORT, BAUD_RATE) 38 | 39 | try: 40 | ble_manager = device.get_ble_manager() 41 | device.open() 42 | 43 | def scan_callback(data): 44 | """ 45 | BLE GAP scan Callback 46 | 47 | This function will get called whenever 48 | a new GAP scan entry has been received. 49 | """ 50 | if isinstance( 51 | data, 52 | (BLEGAPScanLegacyAdvertisementMessage, BLEGAPScanExtendedAdvertisementMessage) 53 | ): 54 | print(data.to_dict()) 55 | 56 | ble_manager.add_ble_gap_advertisement_received_callback(scan_callback) 57 | 58 | print("Starting BLE GAP scan...\n") 59 | ble_manager.start_ble_gap_scan(TIME_TO_SCAN, 10000, 10000, False, "") 60 | 61 | # Wait for a moment to allow the radio to start the scan 62 | time.sleep(.5) 63 | 64 | # Wait until the scan finishes. 65 | while ble_manager.is_scan_running(): 66 | time.sleep(1) 67 | 68 | finally: 69 | if device is not None and device.is_open(): 70 | ble_manager.del_ble_gap_advertisement_received_callback(scan_callback) 71 | device.close() 72 | 73 | 74 | if __name__ == '__main__': 75 | main() 76 | -------------------------------------------------------------------------------- /examples/communication/bluetooth/GapScanExample/readme.txt: -------------------------------------------------------------------------------- 1 | Introduction 2 | ------------ 3 | This Python example shows how to set up a BLE GAP scan, start it, 4 | receive and process the scan results and scan status coming from 5 | the scan on the XBee device. 6 | 7 | The application registers a callback to be notified when new GAP scan data 8 | coming from Bluetooth BLE is received and displays it on the screen, 9 | and also registers a callback to be notified when the GAP scan status 10 | changes. 11 | 12 | NOTE: This example is currently only supported on the XBee 3 BLU device 13 | which uses 'XBeeBLU' device class. 14 | 15 | 16 | Requirements 17 | ------------ 18 | To run this example you will need: 19 | 20 | * One XBee 3 BLU module in API mode and its corresponding carrier board 21 | (XBIB or equivalent). 22 | * The XCTU application (available at www.digi.com/xctu). 23 | 24 | 25 | Compatible protocols 26 | -------------------- 27 | * Bluetooth/BLE 28 | 29 | 30 | Example setup 31 | ------------- 32 | 1) Plug the XBee 3 BLU radio into the XBee adapter and connect it to your 33 | computer's USB or serial port. 34 | 35 | 2) Ensure that the module is in API mode. 36 | For further information on how to perform this task, read the 37 | 'Configuring Your XBee Modules' topic of the Getting Started guide. 38 | 39 | 3) Enable the Bluetooth interface of the XBee 3 BLU device using XCTU. 40 | For further information on how to perform this task, refer to the 41 | XCTU user manual. 42 | 43 | 4) Set the port and baud rate of the XBee 3 BLU radio in the example file. 44 | If you configured the module in the previous step with XCTU, you will 45 | see the port number and baud rate in the 'Port' label of the device 46 | on the left view. 47 | 48 | 49 | Running the example 50 | ------------------- 51 | Launch the application by running it: 52 | python3 GapScanExample.py 53 | 54 | As devices are discovered by the scan, the scan data 55 | will be displayed. 56 | -------------------------------------------------------------------------------- /examples/communication/bluetooth/ReceiveBluetoothDataSample/ReceiveBluetoothDataSample.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019, Digi International Inc. 2 | # 3 | # Permission to use, copy, modify, and/or distribute this software for any 4 | # purpose with or without fee is hereby granted, provided that the above 5 | # copyright notice and this permission notice appear in all copies. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | from digi.xbee.devices import XBeeDevice 16 | 17 | # TODO: Replace with the serial port where your local module is connected to. 18 | PORT = "COM1" 19 | # TODO: Replace with the baud rate of your local module. 20 | BAUD_RATE = 9600 21 | 22 | 23 | def main(): 24 | print(" +---------------------------------------------------+") 25 | print(" | XBee Python Library Receive Bluetooth Data Sample |") 26 | print(" +---------------------------------------------------+\n") 27 | 28 | device = XBeeDevice(PORT, BAUD_RATE) 29 | 30 | try: 31 | device.open() 32 | 33 | def bluetooth_data_callback(data): 34 | print("Data received from Bluetooth >> '%s'" % data.decode("utf-8")) 35 | 36 | device.add_bluetooth_data_received_callback(bluetooth_data_callback) 37 | 38 | print("Waiting for data from the Bluetooth interface...\n") 39 | input() 40 | 41 | finally: 42 | if device is not None and device.is_open(): 43 | device.close() 44 | 45 | 46 | if __name__ == '__main__': 47 | main() 48 | -------------------------------------------------------------------------------- /examples/communication/bluetooth/ReceiveBluetoothDataSample/readme.txt: -------------------------------------------------------------------------------- 1 | Introduction 2 | ------------ 3 | This sample Python application shows how to receive and process data coming 4 | from the Bluetooth interface of the XBee device. 5 | 6 | The application registers a callback to be notified when new data coming from 7 | Bluetooth is received and prints it to the standard output. 8 | 9 | NOTE: This example uses the generic XBee device (XBeeDevice) class, but it 10 | can be applied to any other local XBee device class. 11 | 12 | 13 | Requirements 14 | ------------ 15 | To run this example you will need: 16 | 17 | * One XBee3 module in API mode and its corresponding carrier board (XBIB 18 | or equivalent). 19 | * The XCTU application (available at www.digi.com/xctu). 20 | * An Android or iOS device with the Digi XBee Mobile application installed 21 | (available at Google Play and App Store). 22 | 23 | 24 | Compatible protocols 25 | -------------------- 26 | * 802.15.4 27 | * Cellular 28 | * DigiMesh 29 | * Zigbee 30 | 31 | 32 | Example setup 33 | ------------- 34 | 1) Plug the XBee radio into the XBee adapter and connect it to your 35 | computer's USB or serial port. 36 | 37 | 2) Ensure that the module is in API mode. 38 | For further information on how to perform this task, read the 39 | 'Configuring Your XBee Modules' topic of the Getting Started guide. 40 | 41 | 3) Enable the Bluetooth interface of the XBee device and configure the 42 | Bluetooth authentication using XCTU. 43 | For further information on how to perform this task, refer to the 44 | XCTU user manual. 45 | 46 | 4) Set the port and baud rate of the XBee radio in the sample file. 47 | If you configured the module in the previous step with XCTU, you will 48 | see the port number and baud rate in the 'Port' label of the device 49 | on the left view. 50 | 51 | 52 | Running the example 53 | ------------------- 54 | First, build and launch the application. Then, you need to send a User Data 55 | Relay message from the XBee Mobile application to the serial interface. 56 | Follow the steps below to do so: 57 | 58 | 1) Launch the XBee Mobile application on your mobile device. 59 | 60 | 2) Wait until your XBee device is discovered and connect to it with the 61 | password you configured during the setup. 62 | 63 | 3) Open the Relay Console from the Options menu. 64 | 65 | 4) Tap on the Add (+) button to create a new frame. Select 'SERIAL' as 66 | Relay interface and enter 'Hello XBee!' as data. Then, tap on 'Add'. 67 | 68 | 5) Send this frame by selecting it and taping on 'Send selected frame'. 69 | 70 | When the User Data Relay frame is sent, verify that a line with the data is 71 | printed out in the console of the launched application: 72 | 73 | Data received from Bluetooth >> 'Hello XBee!' 74 | -------------------------------------------------------------------------------- /examples/communication/bluetooth/ReceiveBluetoothFileSample/readme.txt: -------------------------------------------------------------------------------- 1 | Introduction 2 | ------------ 3 | This sample Python application shows how to receive and process data coming 4 | from the Bluetooth interface of the XBee device. 5 | 6 | The application registers a callback to be notified when new data coming from 7 | Bluetooth is received and and stores it in a file. 8 | 9 | NOTE: This example uses the generic XBee device (XBeeDevice) class, but it 10 | can be applied to any other local XBee device class. 11 | 12 | 13 | Requirements 14 | ------------ 15 | To run this example you will need: 16 | 17 | * One XBee3 module in API mode and its corresponding carrier board (XBIB 18 | or equivalent). 19 | * The XCTU application (available at www.digi.com/xctu). 20 | * An Android or iOS device with the 'XBee BLE Microcontroller' sample 21 | installed. 22 | 23 | 24 | Compatible protocols 25 | -------------------- 26 | * 802.15.4 27 | * Cellular 28 | * DigiMesh 29 | * Zigbee 30 | 31 | 32 | Example setup 33 | ------------- 34 | 1) Plug the XBee radio into the XBee adapter and connect it to your 35 | computer's USB or serial port. 36 | 37 | 2) Ensure that the module is in API mode. 38 | For further information on how to perform this task, read the 39 | 'Configuring Your XBee Modules' topic of the Getting Started guide. 40 | 41 | 3) Enable the Bluetooth interface of the XBee device and configure the 42 | Bluetooth authentication using XCTU. 43 | For further information on how to perform this task, refer to the 44 | XCTU user manual. 45 | 46 | 4) Set the port and baud rate of the XBee radio in the sample file. 47 | If you configured the module in the previous step with XCTU, you will 48 | see the port number and baud rate in the 'Port' label of the device 49 | on the left view. 50 | 51 | 52 | Running the example 53 | ------------------- 54 | First, build and launch the application. Then, launch the 'XBee BLE 55 | Microcontroller' sample of the Digi Mobile SDK and follow the instructions 56 | explained in that sample's README file. 57 | 58 | When you load and send a file in your mobile device, the sample prints out 59 | the following messages in the console at the beginning and at the end of the 60 | process: 61 | 62 | >> START message received, saving data to file... 63 | >> END message received, file '' 64 | 65 | Verify that the received file is created successfully and is the same as the 66 | one you sent with the mobile application. 67 | -------------------------------------------------------------------------------- /examples/communication/bluetooth/SendBluetoothDataSample/SendBluetoothDataSample.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019, Digi International Inc. 2 | # 3 | # Permission to use, copy, modify, and/or distribute this software for any 4 | # purpose with or without fee is hereby granted, provided that the above 5 | # copyright notice and this permission notice appear in all copies. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | from digi.xbee.devices import XBeeDevice 16 | from digi.xbee.models.options import XBeeLocalInterface 17 | import time 18 | 19 | # TODO: Replace with the serial port where your local module is connected to. 20 | PORT = "COM1" 21 | # TODO: Replace with the baud rate of your local module. 22 | BAUD_RATE = 9600 23 | # TODO: Optionally, replace with the text of the message. 24 | DATA_TO_SEND = "Hello from the serial interface (#%s)" 25 | 26 | 27 | def main(): 28 | print(" +------------------------------------------------+") 29 | print(" | XBee Python Library Send Bluetooth Data Sample |") 30 | print(" +------------------------------------------------+\n") 31 | 32 | device = XBeeDevice(PORT, BAUD_RATE) 33 | 34 | try: 35 | device.open() 36 | 37 | for i in range(10): 38 | data = (DATA_TO_SEND % (i + 1)) 39 | 40 | print("Sending data to Bluetooth interface >> '%s'... " % data, end="") 41 | 42 | device.send_bluetooth_data(data.encode("utf-8")) 43 | 44 | print("Success") 45 | 46 | time.sleep(1) 47 | finally: 48 | if device is not None and device.is_open(): 49 | device.close() 50 | 51 | 52 | if __name__ == '__main__': 53 | main() 54 | -------------------------------------------------------------------------------- /examples/communication/cellular/ReceiveSMSSample/ReceiveSMSSample.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017, Digi International Inc. 2 | # 3 | # Permission to use, copy, modify, and/or distribute this software for any 4 | # purpose with or without fee is hereby granted, provided that the above 5 | # copyright notice and this permission notice appear in all copies. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | from digi.xbee.devices import CellularDevice 16 | 17 | # TODO: Replace with the serial port where your local module is connected to. 18 | PORT = "COM1" 19 | # TODO: Replace with the baud rate of your local module. 20 | BAUD_RATE = 9600 21 | 22 | 23 | def main(): 24 | print(" +----------------------------------------+") 25 | print(" | XBee Python Library Receive SMS Sample |") 26 | print(" +----------------------------------------+\n") 27 | 28 | device = CellularDevice(PORT, BAUD_RATE) 29 | 30 | try: 31 | device.open() 32 | 33 | def sms_received_callback(sms_message): 34 | print("From %s >> '%s'" % (sms_message.phone_number, 35 | sms_message.data)) 36 | 37 | device.add_sms_callback(sms_received_callback) 38 | 39 | print("Waiting for SMS...\n") 40 | input() 41 | 42 | finally: 43 | if device is not None and device.is_open(): 44 | device.close() 45 | 46 | 47 | if __name__ == '__main__': 48 | main() 49 | -------------------------------------------------------------------------------- /examples/communication/cellular/ReceiveSMSSample/readme.txt: -------------------------------------------------------------------------------- 1 | Introduction 2 | ------------ 3 | This sample Python application shows how SMS messages are received by a 4 | Cellular device using a callback executed every time a new SMS is received. 5 | 6 | The application prints the phone that sent the message and the text of the 7 | SMS itself. 8 | 9 | NOTE: This example uses the Cellular device (CellularDevice) class as it is 10 | the only device able to receive SMS messages. 11 | 12 | 13 | Requirements 14 | ------------ 15 | To run this example you will need: 16 | 17 | * One Cellular radio with a micro SIM card inserted and its corresponding 18 | carrier board (XBIB or equivalent). The Cellular module must be working 19 | in API mode and connected to the Internet. 20 | * The XCTU application (available at www.digi.com/xctu). 21 | * A mobile phone to send the SMS message. 22 | 23 | 24 | Compatible protocols 25 | -------------------- 26 | * Cellular 27 | 28 | 29 | Example setup 30 | ------------- 31 | 1) Plug the Cellular radio into the XBee adapter and connect it to your 32 | computer's USB or serial ports. 33 | 34 | 2) Ensure that the module is in API mode and connected to the Internet 35 | (associated to the cellular network). For further information on how to 36 | perform this task, read the 'Configuring Your XBee Modules' topic of 37 | the Getting Started guide. 38 | 39 | 3) Set the port and baud rate of the receiver Cellular radio in the sample 40 | file. 41 | If you configured the module in the previous step with XCTU, you will 42 | see the port number and baud rate in the 'Port' label of the device 43 | on the left view. 44 | 45 | 46 | Running the example 47 | ------------------- 48 | First, build and launch the application. Then, you need to send an SMS 49 | message from a mobile phone or from other Cellular device. 50 | 51 | When the SMS is sent, verify that the Cellular device has received it. The 52 | application prints out in the console of the launched application the 53 | following line: 54 | 55 | "Received SMS from XXXXXXXXXX >> ''" 56 | 57 | - Where XXXXXXXXXX is the phone number that send the SMS and is the 58 | text contained in the SMS message. 59 | -------------------------------------------------------------------------------- /examples/communication/cellular/SendSMSSample/SendSMSSample.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017, Digi International Inc. 2 | # 3 | # Permission to use, copy, modify, and/or distribute this software for any 4 | # purpose with or without fee is hereby granted, provided that the above 5 | # copyright notice and this permission notice appear in all copies. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | from digi.xbee.devices import CellularDevice 16 | 17 | # TODO: Replace with the serial port where your local module is connected to. 18 | PORT = "COM1" 19 | # TODO: Replace with the baud rate of your local module. 20 | BAUD_RATE = 9600 21 | # TODO: Replace with the phone number of the device to send the SMS to. 22 | PHONE = "" 23 | # TODO: Optionally, replace with the text of the SMS. 24 | SMS_TEXT = "Hello from XBee Cellular!" 25 | 26 | 27 | def main(): 28 | print(" +-------------------------------------+") 29 | print(" | XBee Python Library Send SMS Sample |") 30 | print(" +-------------------------------------+\n") 31 | 32 | device = CellularDevice(PORT, BAUD_RATE) 33 | 34 | try: 35 | device.open() 36 | 37 | print("Sending SMS to %s >> %s..." % (PHONE, SMS_TEXT)) 38 | 39 | device.send_sms(PHONE, SMS_TEXT) 40 | 41 | print("Success") 42 | 43 | finally: 44 | if device is not None and device.is_open(): 45 | device.close() 46 | 47 | 48 | if __name__ == '__main__': 49 | main() 50 | -------------------------------------------------------------------------------- /examples/communication/cellular/SendSMSSample/readme.txt: -------------------------------------------------------------------------------- 1 | Introduction 2 | ------------ 3 | This sample Python application shows how SMS messages are sent by a Cellular 4 | device. 5 | 6 | The application sends an SMS message to a mobile phone and prints the result 7 | of the operation. 8 | 9 | NOTE: This example uses the Cellular device (CellularDevice) class as it is 10 | the only device able to send SMS messages. 11 | 12 | 13 | Requirements 14 | ------------ 15 | To run this example you will need: 16 | 17 | * One Cellular radio with a micro SIM card inserted and its corresponding 18 | carrier board (XBIB or equivalent). The Cellular module must be working 19 | in API mode and connected to the Internet. 20 | * The XCTU application (available at www.digi.com/xctu). 21 | * A mobile phone to receive the SMS message. 22 | 23 | 24 | Compatible protocols 25 | -------------------- 26 | * Cellular 27 | 28 | 29 | Example setup 30 | ------------- 31 | 1) Plug the Cellular radio into the XBee adapter and connect it to your 32 | computer's USB or serial ports. 33 | 34 | 2) Ensure that the module is in API mode and connected to the Internet 35 | (associated to the cellular network). For further information on how to 36 | perform this task, read the 'Configuring Your XBee Modules' topic of 37 | the Getting Started guide. 38 | 39 | 3) Set the port and baud rate of the receiver Cellular radio in the sample 40 | file. 41 | If you configured the module in the previous step with XCTU, you 42 | will see the port number and baud rate in the 'Port' label of the device 43 | on the left view. 44 | 45 | 4) Set the phone number of the mobile phone to send the SMS to in the 46 | 'PHONE' variable of the sample file. Optionally, modify the text of 47 | the SMS changing the value of the 'SMS_TEXT' variable. 48 | 49 | 50 | Running the example 51 | ------------------- 52 | First, build and launch the application. Then, wait for the SMS reception in 53 | your mobile phone. 54 | 55 | When the SMS is sent, the following line is printed out in the console of 56 | the launched application: 57 | 58 | "Sending SMS to XXXXXXXXXX >> ''... Success" 59 | 60 | - Where XXXXXXXXXX is the phone number that send the SMS and is the 61 | text contained in the SMS message. 62 | -------------------------------------------------------------------------------- /examples/communication/explicit/SendBroadcastExplicitDataSample/SendBroadcastExplicitDataSample.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017, Digi International Inc. 2 | # 3 | # Permission to use, copy, modify, and/or distribute this software for any 4 | # purpose with or without fee is hereby granted, provided that the above 5 | # copyright notice and this permission notice appear in all copies. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | from digi.xbee.devices import ZigBeeDevice 16 | 17 | # TODO: Replace with the serial port where your local module is connected to. 18 | PORT = "COM1" 19 | # TODO: Replace with the baud rate of your local module. 20 | BAUD_RATE = 9600 21 | 22 | DATA_TO_SEND = "Hello XBee!" 23 | 24 | SOURCE_ENDPOINT = 0xA0 25 | DESTINATION_ENDPOINT = 0xA1 26 | CLUSTER_ID = 0x1554 27 | PROFILE_ID = 0x1234 28 | 29 | 30 | def main(): 31 | print(" +---------------------------------------------------------+") 32 | print(" | XBee Python Library Send Broadcast Explicit Data Sample |") 33 | print(" +---------------------------------------------------------+\n") 34 | 35 | device = ZigBeeDevice(PORT, BAUD_RATE) 36 | 37 | try: 38 | device.open() 39 | 40 | print("Sending explicit broadcast data: %s..." % DATA_TO_SEND) 41 | 42 | device.send_expl_data_broadcast(DATA_TO_SEND, SOURCE_ENDPOINT, 43 | DESTINATION_ENDPOINT, CLUSTER_ID, PROFILE_ID) 44 | 45 | print("Success") 46 | 47 | finally: 48 | if device is not None and device.is_open(): 49 | device.close() 50 | 51 | 52 | if __name__ == '__main__': 53 | main() 54 | -------------------------------------------------------------------------------- /examples/communication/explicit/SendExplicitDataAsyncSample/SendExplicitDataAsyncSample.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017, Digi International Inc. 2 | # 3 | # Permission to use, copy, modify, and/or distribute this software for any 4 | # purpose with or without fee is hereby granted, provided that the above 5 | # copyright notice and this permission notice appear in all copies. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | from digi.xbee.devices import ZigBeeDevice 16 | 17 | # TODO: Replace with the serial port where your local module is connected to. 18 | PORT = "COM1" 19 | # TODO: Replace with the baud rate of your local module. 20 | BAUD_RATE = 9600 21 | 22 | REMOTE_NODE_ID = "REMOTE" 23 | DATA_TO_SEND = "Hello XBee!" 24 | 25 | SOURCE_ENDPOINT = 0xA0 26 | DESTINATION_ENDPOINT = 0xA1 27 | CLUSTER_ID = 0x1554 28 | PROFILE_ID = 0x1234 29 | 30 | 31 | def main(): 32 | print(" +--------------------------------------------------------------+") 33 | print(" | XBee Python Library Send Explicit Data Asynchronously Sample |") 34 | print(" +--------------------------------------------------------------+\n") 35 | 36 | device = ZigBeeDevice(PORT, BAUD_RATE) 37 | 38 | try: 39 | device.open() 40 | 41 | # Obtain the remote XBee local_xbee from the XBee network. 42 | xbee_network = device.get_network() 43 | remote_device = xbee_network.discover_device(REMOTE_NODE_ID) 44 | if remote_device is None: 45 | print("Could not find the remote local_xbee") 46 | exit(1) 47 | 48 | print("Sending explicit data asynchronously to %s >> %s..." % (remote_device.get_64bit_addr(), DATA_TO_SEND)) 49 | 50 | device.send_expl_data_async(remote_device, DATA_TO_SEND, SOURCE_ENDPOINT, 51 | DESTINATION_ENDPOINT, CLUSTER_ID, PROFILE_ID) 52 | 53 | print("Success") 54 | 55 | finally: 56 | if device is not None and device.is_open(): 57 | device.close() 58 | 59 | 60 | if __name__ == '__main__': 61 | main() 62 | -------------------------------------------------------------------------------- /examples/communication/explicit/SendExplicitDataSample/SendExplicitDataSample.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017, Digi International Inc. 2 | # 3 | # Permission to use, copy, modify, and/or distribute this software for any 4 | # purpose with or without fee is hereby granted, provided that the above 5 | # copyright notice and this permission notice appear in all copies. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | from digi.xbee.devices import ZigBeeDevice 16 | 17 | # TODO: Replace with the serial port where your local module is connected to. 18 | PORT = "COM1" 19 | # TODO: Replace with the baud rate of your local module. 20 | BAUD_RATE = 9600 21 | 22 | REMOTE_NODE_ID = "REMOTE" 23 | DATA_TO_SEND = "Hello XBee!" 24 | 25 | SOURCE_ENDPOINT = 0xA0 26 | DESTINATION_ENDPOINT = 0xA1 27 | CLUSTER_ID = 0x1554 28 | PROFILE_ID = 0x1234 29 | 30 | 31 | def main(): 32 | print(" +-----------------------------------------------+") 33 | print(" | XBee Python Library Send Explicit Data Sample |") 34 | print(" +-----------------------------------------------+\n") 35 | 36 | device = ZigBeeDevice(PORT, BAUD_RATE) 37 | 38 | try: 39 | device.open() 40 | 41 | # Obtain the remote XBee local_xbee from the XBee network. 42 | xbee_network = device.get_network() 43 | remote_device = xbee_network.discover_device(REMOTE_NODE_ID) 44 | if remote_device is None: 45 | print("Could not find the remote local_xbee") 46 | exit(1) 47 | 48 | print("Sending explicit data to %s >> %s..." % (remote_device.get_64bit_addr(), DATA_TO_SEND)) 49 | 50 | device.send_expl_data(remote_device, DATA_TO_SEND, SOURCE_ENDPOINT, 51 | DESTINATION_ENDPOINT, CLUSTER_ID, PROFILE_ID) 52 | 53 | print("Success") 54 | 55 | finally: 56 | if device is not None and device.is_open(): 57 | device.close() 58 | 59 | 60 | if __name__ == '__main__': 61 | main() 62 | -------------------------------------------------------------------------------- /examples/communication/ip/ConnectToEchoServerSample/ConnectToEchoServerSample.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017, Digi International Inc. 2 | # 3 | # Permission to use, copy, modify, and/or distribute this software for any 4 | # purpose with or without fee is hereby granted, provided that the above 5 | # copyright notice and this permission notice appear in all copies. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | from ipaddress import IPv4Address 16 | from digi.xbee.devices import CellularDevice 17 | from digi.xbee.models.protocol import IPProtocol 18 | 19 | # TODO: Replace with the serial port where your local module is connected to. 20 | PORT = "COM1" 21 | # TODO: Replace with the baud rate of your local module. 22 | BAUD_RATE = 9600 23 | # TODO: Optionally, replace with the text you want to send to the server. 24 | TEXT = "Hello XBee!" 25 | 26 | ECHO_SERVER = "52.43.121.77" 27 | ECHO_SERVER_PORT = 11001 28 | PROTOCOL = IPProtocol.TCP 29 | 30 | 31 | def main(): 32 | print(" +---------------------------------------------------+") 33 | print(" | XBee Python Library Connect to Echo Server Sample |") 34 | print(" +---------------------------------------------------+\n") 35 | 36 | device = CellularDevice(PORT, BAUD_RATE) 37 | 38 | try: 39 | device.open() 40 | 41 | if not device.is_connected(): 42 | print(">> Error: the device is not connected to the network") 43 | return 44 | 45 | print("Sending text to %s:%d >> %s..." % (ECHO_SERVER, ECHO_SERVER_PORT, TEXT)) 46 | 47 | device.send_ip_data(IPv4Address(ECHO_SERVER), ECHO_SERVER_PORT, PROTOCOL, TEXT) 48 | 49 | print("Success") 50 | 51 | # Read the echoed data. 52 | ip_message = device.read_ip_data() 53 | if ip_message is None: 54 | print("Echo response was not received from the server.") 55 | return 56 | 57 | print("Echo response received from %s:%d >> '%s'" % (ip_message.ip_addr, ip_message.source_port, 58 | ip_message.data.decode("utf8"))) 59 | 60 | finally: 61 | if device is not None and device.is_open(): 62 | device.close() 63 | 64 | 65 | if __name__ == '__main__': 66 | main() 67 | -------------------------------------------------------------------------------- /examples/communication/ip/ConnectToEchoServerSample/readme.txt: -------------------------------------------------------------------------------- 1 | Introduction 2 | ------------ 3 | This sample Python application shows how to connect an Internet radio module 4 | to an echo server to send and receive data. In this example, data is sent to 5 | an echo server that echoes it back to be read by the module. The application 6 | will block during the transmission and read requests, but you will be 7 | notified if there is any error during the process. 8 | 9 | NOTE: This example uses the Cellular device (CellularDevice) class, but it 10 | can be applied to other Internet capable XBee device classes such as 11 | WiFiDevice. 12 | 13 | 14 | Requirements 15 | ------------ 16 | To run this example you will need: 17 | 18 | * One Internet capable XBee radio (for example a Cellular radio) in API 19 | mode and its corresponding carrier board (XBIB or equivalent). 20 | * The XCTU application (available at www.digi.com/xctu). 21 | 22 | 23 | Compatible protocols 24 | -------------------- 25 | * Cellular 26 | * Wi-Fi 27 | 28 | 29 | Example setup 30 | ------------- 31 | 1) Plug the Internet radio into the XBee adapter and connect it to your 32 | computer's USB or serial port. 33 | 34 | 2) Ensure that the module is in API mode and connected to the Internet. 35 | For further information on how to perform this task, read the 36 | 'Configuring Your XBee Modules' topic of the Getting Started guide. 37 | 38 | 3) Set the port and baud rate of the XBee radio in the sample file. 39 | If you configured the module in the previous step with the XCTU, you 40 | will see the port number and baud rate in the 'Port' label of the device 41 | on the left view. 42 | 43 | 4) Optionally, modify the text to be sent to the echo server changing the 44 | value of the 'TEXT' variable. 45 | 46 | 47 | Running the example 48 | ------------------- 49 | First, build and launch the application. When the application starts, it 50 | connects to the echo server and sends the "Hello XBee!" message. To test 51 | the functionality, check that the following message (among others) is 52 | printed out in the console of the launched application: 53 | 54 | "Echo response received from 52.43.121.77:11001 >> ''" 55 | 56 | - Where is the text sent to the server and echoed back. 57 | 58 | That message indicates that the echo server echoed back the text sent and it 59 | was read by the Internet radio successfully. 60 | -------------------------------------------------------------------------------- /examples/communication/ip/ReceiveIPDataSample/ReceiveIPDataSample.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017, Digi International Inc. 2 | # 3 | # Permission to use, copy, modify, and/or distribute this software for any 4 | # purpose with or without fee is hereby granted, provided that the above 5 | # copyright notice and this permission notice appear in all copies. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | from digi.xbee.devices import WiFiDevice 16 | 17 | # TODO: Replace with the serial port where your local module is connected to. 18 | PORT = "COM1" 19 | # TODO: Replace with the baud rate of your local module. 20 | BAUD_RATE = 9600 21 | 22 | 23 | def main(): 24 | print(" +--------------------------------------------+") 25 | print(" | XBee Python Library Receive IP Data Sample |") 26 | print(" +--------------------------------------------+\n") 27 | 28 | device = WiFiDevice(PORT, BAUD_RATE) 29 | 30 | try: 31 | device.open() 32 | 33 | if not device.is_connected(): 34 | print(">> Error: the device is not connected to the network") 35 | return 36 | 37 | def ip_data_received_callback(ip_message): 38 | print("From %s > %s" % (ip_message.ip_addr, 39 | ip_message.data.decode("utf8"))) 40 | 41 | device.add_ip_data_received_callback(ip_data_received_callback) 42 | 43 | print("Waiting for data...\n") 44 | input() 45 | 46 | finally: 47 | if device is not None and device.is_open(): 48 | device.close() 49 | 50 | 51 | if __name__ == '__main__': 52 | main() 53 | -------------------------------------------------------------------------------- /examples/communication/ip/SendIPDataSample/SendIPDataSample.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017, Digi International Inc. 2 | # 3 | # Permission to use, copy, modify, and/or distribute this software for any 4 | # purpose with or without fee is hereby granted, provided that the above 5 | # copyright notice and this permission notice appear in all copies. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | from ipaddress import IPv4Address 16 | from digi.xbee.devices import WiFiDevice 17 | from digi.xbee.models.protocol import IPProtocol 18 | 19 | # TODO: Replace with the serial port where your local module is connected to. 20 | PORT = "COM1" 21 | # TODO: Replace with the baud rate of your local module. 22 | BAUD_RATE = 9600 23 | # TODO: Replace with the destination IP address. 24 | DEST_IP_ADDRESS = "" 25 | # TODO: Replace with the destination port number (in decimal format). 26 | DEST_PORT = 9750 27 | 28 | PROTOCOL = IPProtocol.TCP 29 | DATA_TO_SEND = "Hello XBee!" 30 | 31 | 32 | def main(): 33 | print(" +-----------------------------------------+") 34 | print(" | XBee Python Library Send IP Data Sample |") 35 | print(" +-----------------------------------------+\n") 36 | 37 | device = WiFiDevice(PORT, BAUD_RATE) 38 | 39 | try: 40 | device.open() 41 | 42 | if not device.is_connected(): 43 | print(">> Error: the device is not connected to the network") 44 | return 45 | 46 | print("Sending data to %s:%d >> %s..." % (DEST_IP_ADDRESS, DEST_PORT, DATA_TO_SEND)) 47 | 48 | device.send_ip_data(IPv4Address(DEST_IP_ADDRESS), DEST_PORT, PROTOCOL, DATA_TO_SEND) 49 | 50 | print("Success") 51 | 52 | finally: 53 | if device is not None and device.is_open(): 54 | device.close() 55 | 56 | 57 | if __name__ == '__main__': 58 | main() 59 | -------------------------------------------------------------------------------- /examples/communication/ip/SendUDPDataSample/SendUDPDataSample.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017, Digi International Inc. 2 | # 3 | # Permission to use, copy, modify, and/or distribute this software for any 4 | # purpose with or without fee is hereby granted, provided that the above 5 | # copyright notice and this permission notice appear in all copies. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | from ipaddress import IPv4Address 16 | from digi.xbee.devices import NBIoTDevice 17 | from digi.xbee.models.protocol import IPProtocol 18 | 19 | # TODO: Replace with the serial port where your local module is connected to. 20 | PORT = "COM1" 21 | # TODO: Replace with the baud rate of your local module. 22 | BAUD_RATE = 9600 23 | # TODO: Replace with the destination IP address. 24 | DEST_IP_ADDRESS = "192.168.1.2" 25 | # TODO: Replace with the destination port number (in decimal format). 26 | DEST_PORT = 9750 27 | 28 | PROTOCOL = IPProtocol.UDP 29 | DATA_TO_SEND = "Hello XBee!" 30 | 31 | 32 | def main(): 33 | print(" +------------------------------------------+") 34 | print(" | XBee Python Library Send UDP Data Sample |") 35 | print(" +------------------------------------------+\n") 36 | 37 | device = NBIoTDevice(PORT, BAUD_RATE) 38 | 39 | try: 40 | device.open() 41 | 42 | if not device.is_connected(): 43 | print(">> Error: the device is not connected to the network") 44 | return 45 | 46 | print("Sending data to %s:%d >> %s..." % (DEST_IP_ADDRESS, DEST_PORT, DATA_TO_SEND)) 47 | 48 | device.send_ip_data(IPv4Address(DEST_IP_ADDRESS), DEST_PORT, PROTOCOL, DATA_TO_SEND) 49 | 50 | print("Success") 51 | 52 | finally: 53 | if device is not None and device.is_open(): 54 | device.close() 55 | 56 | 57 | if __name__ == '__main__': 58 | main() 59 | -------------------------------------------------------------------------------- /examples/communication/ip/SendUDPDataSample/readme.txt: -------------------------------------------------------------------------------- 1 | Introduction 2 | ------------ 3 | This sample Python application shows how to send UDP data from an IP device to 4 | another one connected to the Internet. 5 | 6 | The application sends UDP data to the specified IP address and port number. 7 | 8 | NOTE: This example uses the NB-IoT device (NBIoTDevice) class, but it can be 9 | applied to other Internet capable XBee device classes such as 10 | CellularDevice. 11 | 12 | 13 | Requirements 14 | ------------ 15 | To run this example you will need: 16 | 17 | * One XBee NB-IoT radio in API mode and its corresponding carrier board 18 | (XBIB or equivalent). 19 | * The XCTU application (available at www.digi.com/xctu). 20 | 21 | 22 | Compatible protocols 23 | -------------------- 24 | * Cellular 25 | * Cellular NB-IoT 26 | * Wi-Fi 27 | 28 | 29 | Example setup 30 | ------------- 31 | 1) Plug the XBee radio into the XBee adapter and connect it to your 32 | computer's USB or serial ports. 33 | 34 | 2) Ensure that the module is in API mode and connected to the Internet. 35 | For further information on how to perform this task, read the 36 | 'Configuring Your XBee Modules' topic of the Getting Started guide. 37 | 38 | 3) Set the port and baud rate of the XBee radio in the sample file. 39 | If you configured the module in the previous step with XCTU, you will 40 | see the port number and baud rate in the 'Port' label of the device 41 | on the left view. 42 | 43 | 4) Set the destination IP address and port number in the sample file. 44 | 45 | 46 | Running the example 47 | ------------------- 48 | First, build and launch the application. As soon as the application is 49 | executed, it will send the UDP packet to the specified IP address and port 50 | number. If the transmission was sent successfully, the following message 51 | will be printed out in the console: 52 | 53 | Sending data to 192.168.1.2:9750 >> Hello XBee!... Success 54 | -------------------------------------------------------------------------------- /examples/communication/micropython/ReceiveMicroPythonDataSample/ReceiveMicroPythonDataSample.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019, Digi International Inc. 2 | # 3 | # Permission to use, copy, modify, and/or distribute this software for any 4 | # purpose with or without fee is hereby granted, provided that the above 5 | # copyright notice and this permission notice appear in all copies. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | from digi.xbee.devices import XBeeDevice 16 | 17 | # TODO: Replace with the serial port where your local module is connected to. 18 | PORT = "COM1" 19 | # TODO: Replace with the baud rate of your local module. 20 | BAUD_RATE = 9600 21 | 22 | 23 | def main(): 24 | print(" +-----------------------------------------------------+") 25 | print(" | XBee Python Library Receive MicroPython Data Sample |") 26 | print(" +-----------------------------------------------------+\n") 27 | 28 | device = XBeeDevice(PORT, BAUD_RATE) 29 | 30 | try: 31 | device.open() 32 | 33 | def micropython_data_callback(data): 34 | print("Data received from MicroPython >> '%s'" % data.decode("utf-8")) 35 | 36 | device.add_micropython_data_received_callback(micropython_data_callback) 37 | 38 | print("Waiting for data from the MicroPython interface...\n") 39 | input() 40 | 41 | finally: 42 | if device is not None and device.is_open(): 43 | device.close() 44 | 45 | 46 | if __name__ == '__main__': 47 | main() 48 | -------------------------------------------------------------------------------- /examples/communication/micropython/ReceiveMicroPythonDataSample/readme.txt: -------------------------------------------------------------------------------- 1 | Introduction 2 | ------------ 3 | This sample Python application shows how to receive and process data coming 4 | from the MicroPython interface of the XBee device. 5 | 6 | The application registers a callback to be notified when new data coming from 7 | MicroPython is received and prints it to the standard output. 8 | 9 | NOTE: This example uses the generic XBee device (XBeeDevice) class, but it 10 | can be applied to any other local XBee device class. 11 | 12 | 13 | Requirements 14 | ------------ 15 | To run this example you will need: 16 | 17 | * One XBee3 module in API mode and its corresponding carrier board (XBIB 18 | or equivalent). 19 | * The XCTU application (available at www.digi.com/xctu). 20 | * The PyCharm IDE with the Digi XBee MicroPython plugin installed. 21 | 22 | 23 | Compatible protocols 24 | -------------------- 25 | * 802.15.4 26 | * Cellular 27 | * DigiMesh 28 | * Zigbee 29 | 30 | 31 | Example setup 32 | ------------- 33 | 1) Plug the XBee radio into the XBee adapter and connect it to your 34 | computer's USB or serial port. 35 | 36 | 2) Ensure that the module is in API mode. 37 | For further information on how to perform this task, read the 38 | 'Configuring Your XBee Modules' topic of the Getting Started guide. 39 | 40 | 3) Set the port and baud rate of the XBee radio in the sample file. 41 | If you configured the module in the previous step with XCTU, you will 42 | see the port number and baud rate in the 'Port' label of the device 43 | on the left view. 44 | 45 | 46 | Running the example 47 | ------------------- 48 | First, build the application. Then, you need to run the MicroPython 49 | 'relay_frames_button' sample in the module. Follow these steps to do so: 50 | 51 | 1) Launch PyCharm. 52 | 53 | 2) In the Welcome screen, click the 'Import XBee MicroPython Sample Project' 54 | option and import the 'Relay Frames Button' sample (XBEE > COMMUNICATION). 55 | 56 | 3) Run the sample project. 57 | NOTE: when asked to enable the MicroPython REPL mode, click No. 58 | 59 | Finally, launch this sample application. To verify that the communication 60 | works properly, press the SW2 button (if you have an XBIB-U-DEV carrier board) 61 | or the Comm DIO0 one (if you have an XBIB-C). The application should print 62 | the following line in the standard output: 63 | 64 | Data received from MicroPython >> 'Button pressed' 65 | 66 | Every time you press that button, the MicroPython application will send a User 67 | Data Relay frame to the XBee serial interface. 68 | -------------------------------------------------------------------------------- /examples/communication/micropython/SendMicroPythonDataSample/SendMicroPythonDataSample.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019, Digi International Inc. 2 | # 3 | # Permission to use, copy, modify, and/or distribute this software for any 4 | # purpose with or without fee is hereby granted, provided that the above 5 | # copyright notice and this permission notice appear in all copies. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | from digi.xbee.devices import XBeeDevice 16 | from digi.xbee.models.options import XBeeLocalInterface 17 | import time 18 | 19 | # TODO: Replace with the serial port where your local module is connected to. 20 | PORT = "COM1" 21 | # TODO: Replace with the baud rate of your local module. 22 | BAUD_RATE = 9600 23 | 24 | DATA_ON = "ON" 25 | DATA_OFF = "OFF" 26 | 27 | 28 | def main(): 29 | print(" +--------------------------------------------------+") 30 | print(" | XBee Python Library Send MicroPython Data Sample |") 31 | print(" +--------------------------------------------------+\n") 32 | 33 | device = XBeeDevice(PORT, BAUD_RATE) 34 | 35 | try: 36 | device.open() 37 | 38 | for i in range(10): 39 | data = DATA_ON if i % 2 == 0 else DATA_OFF 40 | 41 | print("Sending data to MicroPython interface >> '%s'... " % data, end="") 42 | 43 | device.send_micropython_data(data.encode("utf-8")) 44 | 45 | print("Success") 46 | 47 | time.sleep(1) 48 | finally: 49 | if device is not None and device.is_open(): 50 | device.close() 51 | 52 | 53 | if __name__ == '__main__': 54 | main() 55 | -------------------------------------------------------------------------------- /examples/communication/micropython/SendMicroPythonDataSample/readme.txt: -------------------------------------------------------------------------------- 1 | Introduction 2 | ------------ 3 | This sample Python application shows how to send data to the MicroPython 4 | interface of the XBee device. 5 | 6 | The application sends 10 messages to the MicroPython interface in order to 7 | turn on and off an LED of the XBee carrier board. 8 | 9 | NOTE: This example uses the generic XBee device (XBeeDevice) class, but it 10 | can be applied to any other local XBee device class. 11 | 12 | 13 | Requirements 14 | ------------ 15 | To run this example you will need: 16 | 17 | * One XBee3 module in API mode and its corresponding carrier board (XBIB 18 | or equivalent). 19 | * The XCTU application (available at www.digi.com/xctu). 20 | * The PyCharm IDE with the Digi XBee MicroPython plugin installed. 21 | 22 | 23 | Compatible protocols 24 | -------------------- 25 | * 802.15.4 26 | * Cellular 27 | * DigiMesh 28 | * Zigbee 29 | 30 | 31 | Example setup 32 | ------------- 33 | 1) Plug the XBee radio into the XBee adapter and connect it to your 34 | computer's USB or serial port. 35 | 36 | 2) Ensure that the module is in API mode. 37 | For further information on how to perform this task, read the 38 | 'Configuring Your XBee Modules' topic of the Getting Started guide. 39 | 40 | 3) Set the port and baud rate of the XBee radio in the sample file. 41 | If you configured the module in the previous step with XCTU, you 42 | will see the port number and baud rate in the 'Port' label of the 43 | device on the left view. 44 | 45 | 46 | Running the example 47 | ------------------- 48 | First, build the application. Then, you need to run the MicroPython 49 | 'relay_frames_led' sample in the module. Follow these steps to do so: 50 | 51 | 1) Launch PyCharm. 52 | 53 | 2) In the Welcome screen, click the 'Import XBee MicroPython Sample Project' 54 | option and import the 'Relay Frames LED' sample (XBEE > COMMUNICATION). 55 | 56 | 3) Run the sample project. 57 | NOTE: when asked to enable the MicroPython REPL mode, click No. 58 | 59 | Finally, launch this sample application. A total of 10 data messages are sent 60 | to the MicroPython interface to turn on and off an LED. When that happens, a 61 | line with the result of each operation is printed to the standard output: 62 | 63 | Sending data to MicroPython interface >> 'ON'... Success 64 | Sending data to MicroPython interface >> 'OFF'... Success 65 | Sending data to MicroPython interface >> 'ON'... Success 66 | ... 67 | 68 | Verify that the On/Sleep LED of the XBee carrier board blinks during 10 69 | seconds. 70 | -------------------------------------------------------------------------------- /examples/communication/relay/ReceiveUserDataRelaySample/ReceiveUserDataRelaySample.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019, Digi International Inc. 2 | # 3 | # Permission to use, copy, modify, and/or distribute this software for any 4 | # purpose with or without fee is hereby granted, provided that the above 5 | # copyright notice and this permission notice appear in all copies. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | from digi.xbee.devices import XBeeDevice 16 | 17 | # TODO: Replace with the serial port where your local module is connected to. 18 | PORT = "COM1" 19 | # TODO: Replace with the baud rate of your local module. 20 | BAUD_RATE = 9600 21 | 22 | 23 | def main(): 24 | print(" +----------------------------------------------------+") 25 | print(" | XBee Python Library Receive User Data Relay Sample |") 26 | print(" +----------------------------------------------------+\n") 27 | 28 | device = XBeeDevice(PORT, BAUD_RATE) 29 | 30 | try: 31 | device.open() 32 | 33 | def relay_data_callback(relay_message): 34 | print("Relay data received from %s >> '%s'" % 35 | (relay_message.local_interface.name, 36 | relay_message.data.decode("utf-8"))) 37 | 38 | device.add_user_data_relay_received_callback(relay_data_callback) 39 | 40 | print("Waiting for User Data Relay messages...\n") 41 | input() 42 | 43 | finally: 44 | if device is not None and device.is_open(): 45 | device.close() 46 | 47 | 48 | if __name__ == '__main__': 49 | main() 50 | -------------------------------------------------------------------------------- /examples/communication/relay/SendUserDataRelaySample/SendUserDataRelaySample.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019, Digi International Inc. 2 | # 3 | # Permission to use, copy, modify, and/or distribute this software for any 4 | # purpose with or without fee is hereby granted, provided that the above 5 | # copyright notice and this permission notice appear in all copies. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | from digi.xbee.devices import XBeeDevice 16 | from digi.xbee.models.options import XBeeLocalInterface 17 | import time 18 | 19 | # TODO: Replace with the serial port where your local module is connected to. 20 | PORT = "COM1" 21 | # TODO: Replace with the baud rate of your local module. 22 | BAUD_RATE = 9600 23 | DEST_INTERFACE = XBeeLocalInterface.BLUETOOTH 24 | # TODO: Optionally, replace with the text of the message. 25 | DATA_TO_SEND = "Hello from the serial interface (#%s)" 26 | 27 | 28 | def main(): 29 | print(" +-------------------------------------------------+") 30 | print(" | XBee Python Library Send User Data Relay Sample |") 31 | print(" +-------------------------------------------------+\n") 32 | 33 | device = XBeeDevice(PORT, BAUD_RATE) 34 | 35 | try: 36 | device.open() 37 | 38 | for i in range(10): 39 | data = (DATA_TO_SEND % (i + 1)) 40 | 41 | print("Sending User Data Relay to %s >> '%s'... " % 42 | (DEST_INTERFACE.name, data), end="") 43 | 44 | device.send_user_data_relay(DEST_INTERFACE, data.encode("utf-8")) 45 | 46 | print("Success") 47 | 48 | time.sleep(1) 49 | finally: 50 | if device is not None and device.is_open(): 51 | device.close() 52 | 53 | 54 | if __name__ == '__main__': 55 | main() 56 | -------------------------------------------------------------------------------- /examples/communication/socket/SocketTCPClientSample/SocketTCPClientSample.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019, Digi International Inc. 2 | # 3 | # Permission to use, copy, modify, and/or distribute this software for any 4 | # purpose with or without fee is hereby granted, provided that the above 5 | # copyright notice and this permission notice appear in all copies. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | from digi.xbee import xsocket 16 | from digi.xbee.devices import CellularDevice 17 | 18 | # TODO: Replace with the serial port where your local module is connected to. 19 | PORT = "COM1" 20 | # TODO: Replace with the baud rate of your local module. 21 | BAUD_RATE = 9600 22 | DEST_ADDRESS = "numbersapi.com" 23 | DEST_PORT = 80 24 | REQUEST_TEXT = "GET /random/trivia HTTP/1.1\r\n" \ 25 | "Host: numbersapi.com\r\n\r\n" 26 | 27 | 28 | def main(): 29 | print(" +----------------------------------------------+") 30 | print(" | XBee Python Library Socket TCP Client Sample |") 31 | print(" +----------------------------------------------+\n") 32 | 33 | device = CellularDevice(PORT, BAUD_RATE) 34 | 35 | try: 36 | device.open() 37 | 38 | with xsocket.socket(device) as sock: 39 | print("- Connecting to '%s'" % DEST_ADDRESS) 40 | sock.connect((DEST_ADDRESS, DEST_PORT)) 41 | print("- Sending request text to the server") 42 | sock.send(REQUEST_TEXT.encode("utf-8")) 43 | print("- Waiting for the answer") 44 | answer = sock.recv(4096) 45 | print("- Data received:") 46 | print(answer.decode("utf-8")) 47 | 48 | finally: 49 | if device is not None and device.is_open(): 50 | device.close() 51 | 52 | 53 | if __name__ == '__main__': 54 | main() 55 | -------------------------------------------------------------------------------- /examples/communication/socket/SocketTCPClientSample/readme.txt: -------------------------------------------------------------------------------- 1 | Introduction 2 | ------------ 3 | This sample Python application shows how to perform a complete request with 4 | an HTTP server using the XBee socket API. 5 | 6 | The application opens the connection with an XBee device and, using the XBee 7 | socket API, it fetches a random fact about a number from a web services API 8 | offered by the website 'http://numbersapi.com'. 9 | 10 | NOTE: This example uses the Cellular device (CellularDevice) class as it is 11 | the only device able to use the XBee socket API. 12 | 13 | 14 | Requirements 15 | ------------ 16 | To run this example you will need: 17 | 18 | * One Cellular radio with a micro SIM card inserted and its corresponding 19 | carrier board (XBIB or equivalent). The Cellular module must be working 20 | in API mode and connected to the Internet. 21 | * The XCTU application (available at www.digi.com/xctu). 22 | 23 | 24 | Compatible protocols 25 | -------------------- 26 | * Cellular 27 | 28 | 29 | Example setup 30 | ------------- 31 | 1) Plug the Cellular radio into the XBee adapter and connect it to your 32 | computer's USB or serial ports. 33 | 34 | 2) Ensure that the module is in API mode and connected to the Internet 35 | (associated to the cellular network). For further information on how to 36 | perform this task, read the 'Configuring Your XBee Modules' topic of 37 | the Getting Started guide. 38 | 39 | 3) Set the port and baud rate of the Cellular device in the sample file. 40 | If you configured the module in the previous step with XCTU, you 41 | will see the port number and baud rate in the 'Port' label of the device 42 | on the left view. 43 | 44 | 45 | Running the example 46 | ------------------- 47 | First, build and launch the application. Then, wait for the example to 48 | connect with the server, send the request and get the answer. The following 49 | messages are printed by the application: 50 | 51 | - Connecting to 'numbersapi.com' 52 | - Sending request text to the server 53 | - Waiting for the answer 54 | 55 | If the answer is received successfully, the example prints it. After the HTTP 56 | header there should be an interesting fact about a number: 57 | 58 | - Data received: 59 | 60 | [...] 61 | 62 | 10000000000000000000 is the estimated insect population. 63 | -------------------------------------------------------------------------------- /examples/communication/socket/SocketTCPServerSample/PCClient.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019, Digi International Inc. 2 | # 3 | # Permission to use, copy, modify, and/or distribute this software for any 4 | # purpose with or without fee is hereby granted, provided that the above 5 | # copyright notice and this permission notice appear in all copies. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | import socket 16 | 17 | # TODO: Replace with the public IP of the XBee Cellular device. 18 | TCP_SERVER_ADDRESS = "52.43.121.77" 19 | TCP_SERVER_PORT = 0x1234 20 | # TODO: Optionally, replace with the text to be sent to the server. 21 | TCP_SERVER_REQUEST = "May the force be with you" 22 | 23 | 24 | def main(): 25 | print(" +----------------------------------------------------------+") 26 | print(" | XBee Python Library Socket TCP Server Sample - PC Client |") 27 | print(" +----------------------------------------------------------+\n") 28 | 29 | with socket.socket() as sock: 30 | print("- Connecting to TCP server '%s:%s'" % (TCP_SERVER_ADDRESS, TCP_SERVER_PORT)) 31 | sock.connect((TCP_SERVER_ADDRESS, TCP_SERVER_PORT)) 32 | print("- Sending '%s' to the TCP server" % TCP_SERVER_REQUEST) 33 | sock.sendall(TCP_SERVER_REQUEST.encode("utf-8")) 34 | print("- Waiting for echoed data") 35 | answer = sock.recv(4096) 36 | if answer is not None: 37 | print("- Data received: %s" % answer.decode("utf-8")) 38 | 39 | 40 | if __name__ == '__main__': 41 | main() 42 | -------------------------------------------------------------------------------- /examples/communication/socket/SocketTCPServerSample/SocketTCPServerSample.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019, Digi International Inc. 2 | # 3 | # Permission to use, copy, modify, and/or distribute this software for any 4 | # purpose with or without fee is hereby granted, provided that the above 5 | # copyright notice and this permission notice appear in all copies. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | from digi.xbee import xsocket 16 | from digi.xbee.devices import CellularDevice 17 | 18 | # TODO: Replace with the serial port where your local module is connected to. 19 | PORT = "COM1" 20 | # TODO: Replace with the baud rate of your local module. 21 | BAUD_RATE = 9600 22 | LISTEN_PORT = 0x1234 23 | 24 | 25 | def main(): 26 | print(" +----------------------------------------------+") 27 | print(" | XBee Python Library Socket TCP Server Sample |") 28 | print(" +----------------------------------------------+\n") 29 | 30 | device = CellularDevice(PORT, BAUD_RATE) 31 | 32 | try: 33 | device.open() 34 | 35 | with xsocket.socket(device) as sock: 36 | print("- Starting TCP server at port %s" % LISTEN_PORT) 37 | sock.bind(("0.0.0.0", LISTEN_PORT)) 38 | sock.listen() 39 | print("- Waiting for client") 40 | client, client_addr = sock.accept() 41 | print("- Client '%s:%s' connected" % (client_addr[0], client_addr[1])) 42 | print("- Waiting for incoming data") 43 | answer = None 44 | while not answer and client.is_connected: 45 | answer = client.recv(4096) 46 | 47 | if answer is not None: 48 | print("- Data received: %s" % answer.decode("utf-8")) 49 | print("- Sending data back to the client") 50 | client.sendall(answer) 51 | else: 52 | print("- Could not receive data from the client") 53 | print("- Closing client socket") 54 | client.close() 55 | 56 | finally: 57 | if device is not None and device.is_open(): 58 | device.close() 59 | 60 | 61 | if __name__ == '__main__': 62 | main() 63 | -------------------------------------------------------------------------------- /examples/communication/socket/SocketUDPServerClientSample/SocketUDPServerSample.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019, Digi International Inc. 2 | # 3 | # Permission to use, copy, modify, and/or distribute this software for any 4 | # purpose with or without fee is hereby granted, provided that the above 5 | # copyright notice and this permission notice appear in all copies. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | from digi.xbee import xsocket 16 | from digi.xbee.devices import CellularDevice 17 | from digi.xbee.models.protocol import IPProtocol 18 | 19 | # TODO: Replace with the serial port where your local module is connected to. 20 | PORT = "COM1" 21 | # TODO: Replace with the baud rate of your local module. 22 | BAUD_RATE = 9600 23 | LISTEN_PORT = 0x1234 24 | ECHO_SERVER_ADDRESS = "52.43.121.77" 25 | ECHO_SERVER_PORT = 10001 26 | # TODO: Optionally, replace with the text to be sent to the server. 27 | ECHO_SERVER_REQUEST = "May the force be with you" 28 | 29 | 30 | def main(): 31 | print(" +-----------------------------------------------------+") 32 | print(" | XBee Python Library Socket UDP Server Client Sample |") 33 | print(" +-----------------------------------------------------+\n") 34 | 35 | device = CellularDevice(PORT, BAUD_RATE) 36 | 37 | try: 38 | device.open() 39 | 40 | with xsocket.socket(device, IPProtocol.UDP) as sock: 41 | print("- Starting UDP server at port %s" % LISTEN_PORT) 42 | sock.bind(("0.0.0.0", LISTEN_PORT)) 43 | print("- Sending '%s' to the echo server" % ECHO_SERVER_REQUEST) 44 | sock.sendto(ECHO_SERVER_REQUEST.encode("utf-8"), (ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT)) 45 | print("- Waiting for incoming data") 46 | answer, address = sock.recvfrom(4096) 47 | if answer is not None: 48 | print("- Data received from %s:%s - '%s'" % (address[0], address[1], answer.decode("utf-8"))) 49 | finally: 50 | if device is not None and device.is_open(): 51 | device.close() 52 | 53 | 54 | if __name__ == '__main__': 55 | main() 56 | -------------------------------------------------------------------------------- /examples/communication/socket/SocketUDPServerClientSample/readme.txt: -------------------------------------------------------------------------------- 1 | Introduction 2 | ------------ 3 | This sample Python application shows how to create a UDP socket to deliver 4 | messages to a server and and listen for data coming from multiple peers using 5 | the XBee socket API. 6 | 7 | The application associates the UDP socket with a port (binds it) to listen 8 | for individual messages. Then, it sends a message to a server Digi has at 9 | 52.43.121.77 port 10001, which echos all UDP traffic sent to it. This causes 10 | the socket to receive the echoed message and prints it. 11 | 12 | NOTE: This example uses the Cellular device (CellularDevice) class as it is 13 | the only device able to use the XBee socket API. 14 | 15 | 16 | Requirements 17 | ------------ 18 | To run this example you will need: 19 | 20 | * One Cellular radio with a micro SIM card inserted and its corresponding 21 | carrier board (XBIB or equivalent). The Cellular module must be working 22 | in API mode and connected to the Internet. 23 | * The XCTU application (available at www.digi.com/xctu). 24 | 25 | 26 | Compatible protocols 27 | -------------------- 28 | * Cellular 29 | 30 | 31 | Example setup 32 | ------------- 33 | 1) Plug the Cellular radio into the XBee adapter and connect it to your 34 | computer's USB or serial ports. 35 | 36 | 2) Ensure that the module is in API mode and connected to the Internet 37 | (associated to the cellular network). For further information on how to 38 | perform this task, read the 'Configuring Your XBee Modules' topic of 39 | the Getting Started guide. 40 | 41 | 3) Set the port and baud rate of the Cellular device in the sample file. 42 | If you configured the module in the previous step with XCTU, you 43 | will see the port number and baud rate in the 'Port' label of the device 44 | on the left view. 45 | 46 | 47 | Running the example 48 | ------------------- 49 | First, build and launch the application. Then, wait for the example to 50 | start the UDP server and send a request to the echo server. The application 51 | displays the following output: 52 | 53 | - Starting UDP server at port 4660 54 | - Sending 'May the force be with you' to the echo server 55 | - Waiting for incoming data 56 | 57 | When the answer from the echo server is received, the application prints it: 58 | 59 | - Data received from 52.43.121.77:10001 - 'May the force be with you' 60 | -------------------------------------------------------------------------------- /examples/configuration/ConnectToAccessPointSample/readme.txt: -------------------------------------------------------------------------------- 1 | Introduction 2 | ------------ 3 | This sample Python application how to scan, connect to an access point and 4 | configure an XBee Wi-Fi module using the XBee Python Library. 5 | 6 | NOTE: This example uses the Wi-Fi device (WiFiDevice) class as it is the only 7 | device able to connect to access points. 8 | 9 | 10 | Requirements 11 | ------------ 12 | To run this example you will need: 13 | 14 | * One XBee Wi-Fi radio in API mode and its corresponding carrier board (XBIB 15 | or XBee Development Board). 16 | * The XCTU application (available at www.digi.com/xctu). 17 | * An access point to connect to. 18 | 19 | 20 | Compatible protocols 21 | -------------------- 22 | * Wi-Fi 23 | 24 | 25 | Example setup 26 | ------------- 27 | 1) Plug the Wi-Fi radio into the XBee adapter and connect it to your 28 | computer's USB or serial port. 29 | 30 | 2) Ensure that the module is in API mode. 31 | For further information on how to perform this task, read the 32 | 'Configuring Your XBee Modules' topic of the Getting Started guide. 33 | 34 | 3) Set the port and baud rate of the Wi-Fi radio in the 35 | sample file. If you configured the module in the 36 | previous step with XCTU, you will see the port number and baud rate in 37 | the 'Port' label of the device on the left view. 38 | 39 | 4) Set the SSID and password of the access point you are going to connect to 40 | in the 'SSID' and 'PASSWORD' variables of the sample file. 41 | 42 | 43 | Running the example 44 | ------------------- 45 | First, build and launch the application. To test the functionality, check 46 | that the following message is printed out in the console of the launched 47 | application: 48 | 49 | ">> Successfully connected to ''" 50 | 51 | That message indicates that the module is connected to the access point 52 | correctly. Other addressing information should be printed out as well. 53 | -------------------------------------------------------------------------------- /examples/configuration/ManageCommonParametersSample/ManageCommonParametersSample.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017, Digi International Inc. 2 | # 3 | # Permission to use, copy, modify, and/or distribute this software for any 4 | # purpose with or without fee is hereby granted, provided that the above 5 | # copyright notice and this permission notice appear in all copies. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | from digi.xbee.devices import XBeeDevice 16 | from digi.xbee.util import utils 17 | from digi.xbee.models.address import XBee64BitAddress 18 | from digi.xbee.models.status import PowerLevel 19 | 20 | # TODO: Replace with the serial port where your local module is connected to. 21 | PORT = "COM1" 22 | # TODO: Replace with the baud rate of your local module. 23 | BAUD_RATE = 9600 24 | 25 | PARAM_VALUE_PAN_ID = bytearray(b'\x01\x23') 26 | PARAM_DESTINATION_ADDR = XBee64BitAddress.BROADCAST_ADDRESS 27 | PARAM_POWER_LEVEL = PowerLevel.LEVEL_MEDIUM 28 | 29 | 30 | def main(): 31 | print(" +-----------------------------------------------------+") 32 | print(" | XBee Python Library Manage Common parameters Sample |") 33 | print(" +-----------------------------------------------------+\n") 34 | 35 | device = XBeeDevice(PORT, BAUD_RATE) 36 | 37 | try: 38 | device.open() 39 | 40 | print("Cached parameters\n" + "-" * 50) 41 | print("64-bit address: %s" % device.get_64bit_addr()) 42 | print("16-bit address: %s" % device.get_16bit_addr()) 43 | print("Node Identifier: %s" % device.get_node_id()) 44 | print("Firmware version: %s" % utils.hex_to_string(device.get_firmware_version())) 45 | print("Hardware version: %s" % device.get_hardware_version().description) 46 | 47 | print("") 48 | 49 | # Configure and read non-cached parameters. 50 | device.set_pan_id(PARAM_VALUE_PAN_ID) 51 | device.set_dest_address(PARAM_DESTINATION_ADDR) 52 | device.set_power_level(PARAM_POWER_LEVEL) 53 | 54 | print("Non-Cached parameters\n" + "-" * 50) 55 | print("PAN ID: %s" % utils.hex_to_string(device.get_pan_id())) 56 | print("Dest address: %s" % device.get_dest_address()) 57 | print("Power level: %s" % device.get_power_level().description) 58 | 59 | finally: 60 | if device is not None and device.is_open(): 61 | device.close() 62 | 63 | 64 | if __name__ == '__main__': 65 | main() 66 | -------------------------------------------------------------------------------- /examples/configuration/ManageCommonParametersSample/readme.txt: -------------------------------------------------------------------------------- 1 | Introduction 2 | ------------ 3 | This sample Python application shows how to get and set common parameters of 4 | the XBee device. Common parameters are split in cached and non-cached 5 | parameters. For that reason, the application refreshes the cached parameters 6 | before reading and displaying them. It then configures, reads and displays 7 | the value of non-cached parameters. 8 | 9 | The application uses the specific setters and getters provided by the XBee 10 | device object to configure and read the different parameters. 11 | 12 | NOTE: This example uses the generic XBee device (XBeeDevice) class, but it 13 | can be applied to any other local or remote XBee device class. 14 | 15 | 16 | Requirements 17 | ------------ 18 | To run this example you will need: 19 | 20 | * One XBee radio in API mode and its corresponding carrier board (XBIB 21 | or XBee Development Board). 22 | * The XCTU application (available at www.digi.com/xctu). 23 | 24 | 25 | Compatible protocols 26 | -------------------- 27 | * 802.15.4 28 | * DigiMesh 29 | * Point-to-Multipoint 30 | * Zigbee 31 | 32 | 33 | Example setup 34 | ------------- 35 | 1) Plug the XBee radio into the XBee adapter and connect it to your 36 | computer's USB or serial port. 37 | 38 | 2) Ensure that the module is in API mode. 39 | For further information on how to perform this task, read the 40 | 'Configuring Your XBee Modules' topic of the Getting Started guide. 41 | 42 | 3) Set the port and baud rate of the XBee radio in the sample file class. 43 | If you configured the module in the previous step with the XCTU, you 44 | will see the port number and baud rate in the 'Port' label of the device 45 | on the left view. 46 | 47 | 48 | Running the example 49 | ------------------- 50 | First, build and launch the application. To test the functionality, check 51 | that the output console displays the value of all the common (cached and 52 | non-cached) parameters. It should display something similar to this: 53 | 54 | Cached parameters 55 | ---------------------- 56 | [...] 57 | 58 | Non-Cached parameters 59 | ---------------------- 60 | [...] 61 | -------------------------------------------------------------------------------- /examples/configuration/RecoverSerialConnection/RecoverSerialConnection.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019, Digi International Inc. 2 | # 3 | # Permission to use, copy, modify, and/or distribute this software for any 4 | # purpose with or without fee is hereby granted, provided that the above 5 | # copyright notice and this permission notice appear in all copies. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | import logging 16 | 17 | from digi.xbee.devices import XBeeDevice 18 | from digi.xbee.exception import XBeeException 19 | 20 | # TODO: Replace with the serial port where your local module is connected to. 21 | PORT = "COM1" 22 | # List of baudrates 23 | BAUD_RATES = (115200, 57600, 38400, 19200, 9600) 24 | 25 | 26 | def main(): 27 | print(""" 28 | +------------------------------------------------------+ 29 | | XBee Python Library Recover serial connection Sample | 30 | +------------------------------------------------------+ 31 | """) 32 | 33 | for baudrate in BAUD_RATES: 34 | print("Opening the XBee device by forcing its baudrate to %d" % baudrate) 35 | device = XBeeDevice(PORT, baudrate) 36 | 37 | try: 38 | device.open(force_settings=True) 39 | print("Device opened and set to operate at %d bauds" % baudrate) 40 | except XBeeException as e: 41 | print("ERROR: %s" % str(e)) 42 | return 43 | finally: 44 | if device is not None and device.is_open(): 45 | device.close() 46 | 47 | 48 | if __name__ == '__main__': 49 | main() 50 | -------------------------------------------------------------------------------- /examples/configuration/RecoverSerialConnection/readme.txt: -------------------------------------------------------------------------------- 1 | Introduction 2 | ------------ 3 | This sample Python application shows how to recover the serial settings of a 4 | local XBee device. 5 | 6 | NOTE: This example uses the generic XBee device (XBeeDevice) class, but it 7 | can be applied to any other local device class. 8 | 9 | 10 | Requirements 11 | ------------ 12 | To run this example you will need: 13 | 14 | * One XBee radio and its corresponding carrier board (XBIB or XBee 15 | Development Board). 16 | 17 | 18 | Compatible hardware 19 | -------------------- 20 | * Local XBee3 devices 21 | 22 | 23 | Compatible protocols 24 | -------------------- 25 | * 802.15.4 26 | * DigiMesh 27 | * Zigbee 28 | 29 | 30 | Example setup 31 | ------------- 32 | 1) Plug the XBee radio into the XBee adapter and connect it to your 33 | computer's USB or serial port. 34 | 35 | 36 | Running the example 37 | ------------------- 38 | First, build and launch the application. You will see the next message: 39 | 40 | "Opening the XBee device by forcing its baudrate to " 41 | 42 | When the process completes, the following message is displayed: 43 | 44 | "Device opened and set to operate at bauds" 45 | 46 | If any error occurs during the process, it will be displayed in the console. 47 | -------------------------------------------------------------------------------- /examples/configuration/ResetModuleSample/ResetModuleSample.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017, Digi International Inc. 2 | # 3 | # Permission to use, copy, modify, and/or distribute this software for any 4 | # purpose with or without fee is hereby granted, provided that the above 5 | # copyright notice and this permission notice appear in all copies. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | from digi.xbee.devices import XBeeDevice 16 | 17 | # TODO: Replace with the serial port where your local module is connected to. 18 | PORT = "COM1" 19 | # TODO: Replace with the baud rate of your local module. 20 | BAUD_RATE = 9600 21 | 22 | 23 | def main(): 24 | print(" +-----------------------------------------+") 25 | print(" | XBee Python Library Reset Module Sample |") 26 | print(" +-----------------------------------------+\n") 27 | 28 | device = XBeeDevice(PORT, BAUD_RATE) 29 | 30 | try: 31 | device.open() 32 | 33 | device.reset() 34 | 35 | print("XBee module reset successfully") 36 | 37 | finally: 38 | if device is not None and device.is_open(): 39 | device.close() 40 | 41 | 42 | if __name__ == '__main__': 43 | main() 44 | -------------------------------------------------------------------------------- /examples/configuration/ResetModuleSample/readme.txt: -------------------------------------------------------------------------------- 1 | Introduction 2 | ------------ 3 | This sample Python application shows how to perform a software reset on the 4 | local XBee module. 5 | 6 | NOTE: This example uses the generic XBee device (XBeeDevice) class, 7 | but it can be applied to any other local XBee device class. 8 | 9 | 10 | Requirements 11 | ------------ 12 | To run this example you will need: 13 | 14 | * One XBee radio in API mode and its corresponding carrier board (XBIB 15 | or XBee Development Board). 16 | * The XCTU application (available at www.digi.com/xctu). 17 | 18 | 19 | Compatible protocols 20 | -------------------- 21 | * 802.15.4 22 | * Cellular 23 | * Cellular NB-IoT 24 | * DigiMesh 25 | * Point-to-Multipoint 26 | * Wi-Fi 27 | * Zigbee 28 | 29 | 30 | Example setup 31 | ------------- 32 | 1) Plug the XBee radio into the XBee adapter and connect it to your 33 | computer's USB or serial port. 34 | 35 | 2) Ensure that the module is in API mode. 36 | For further information on how to perform this task, read the 37 | 'Configuring Your XBee Modules' topic of the Getting Started guide. 38 | 39 | 3) Set the port and baud rate of the XBee radio in the sample file. 40 | If you configured the module in the previous step with the XCTU, you 41 | will see the port number and baud rate in the 'Port' label of the device 42 | on the left view. 43 | 44 | 45 | Running the example 46 | ------------------- 47 | First, build and launch the application. To test the functionality, check 48 | that the following message is printed out in the console of the launched 49 | application: 50 | 51 | "XBee module reset successfully" 52 | 53 | That message indicates that the module was reset correctly. 54 | -------------------------------------------------------------------------------- /examples/configuration/SetAndGetParametersSample/SetAndGetParametersSample.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017, Digi International Inc. 2 | # 3 | # Permission to use, copy, modify, and/or distribute this software for any 4 | # purpose with or without fee is hereby granted, provided that the above 5 | # copyright notice and this permission notice appear in all copies. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | from digi.xbee.devices import XBeeDevice 16 | from digi.xbee.util import utils 17 | 18 | # TODO: Replace with the serial port where your local module is connected to. 19 | PORT = "COM1" 20 | # TODO: Replace with the baud rate of your local module. 21 | BAUD_RATE = 9600 22 | 23 | PARAM_NODE_ID = "NI" 24 | PARAM_PAN_ID = "ID" 25 | PARAM_DEST_ADDRESS_H = "DH" 26 | PARAM_DEST_ADDRESS_L = "DL" 27 | 28 | PARAM_VALUE_NODE_ID = "Yoda" 29 | PARAM_VALUE_PAN_ID = utils.hex_string_to_bytes("1234") 30 | PARAM_VALUE_DEST_ADDRESS_H = utils.hex_string_to_bytes("00") 31 | PARAM_VALUE_DEST_ADDRESS_L = utils.hex_string_to_bytes("FFFF") 32 | 33 | 34 | def main(): 35 | print(" +-----------------------------------------------+") 36 | print(" | XBee Python Library Set/Get parameters Sample |") 37 | print(" +-----------------------------------------------+\n") 38 | 39 | device = XBeeDevice(PORT, BAUD_RATE) 40 | 41 | try: 42 | device.open() 43 | 44 | # Set parameters. 45 | device.set_parameter(PARAM_NODE_ID, bytearray(PARAM_VALUE_NODE_ID, 'utf8')) 46 | device.set_parameter(PARAM_PAN_ID, PARAM_VALUE_PAN_ID) 47 | device.set_parameter(PARAM_DEST_ADDRESS_H, PARAM_VALUE_DEST_ADDRESS_H) 48 | device.set_parameter(PARAM_DEST_ADDRESS_L, PARAM_VALUE_DEST_ADDRESS_L) 49 | 50 | # Get parameters. 51 | print("Node ID: %s" % device.get_parameter(PARAM_NODE_ID).decode()) 52 | print("PAN ID: %s" % utils.hex_to_string(device.get_parameter(PARAM_PAN_ID))) 53 | print("Destination address high: %s" % utils.hex_to_string(device.get_parameter(PARAM_DEST_ADDRESS_H))) 54 | print("Destination address low: %s" % utils.hex_to_string(device.get_parameter(PARAM_DEST_ADDRESS_L))) 55 | 56 | print("") 57 | print("All parameters were set correctly!") 58 | 59 | finally: 60 | if device is not None and device.is_open(): 61 | device.close() 62 | 63 | 64 | if __name__ == '__main__': 65 | main() 66 | -------------------------------------------------------------------------------- /examples/configuration/SetAndGetParametersSample/readme.txt: -------------------------------------------------------------------------------- 1 | Introduction 2 | ------------ 3 | This sample Python application shows how to set and get parameters of a local 4 | or remote XBee device. This method is intended to be used when you need to 5 | set or get the value of a parameter that does not have its own getter and 6 | setter within the XBee device object. 7 | 8 | The application sets the value of four parameters with different value types: 9 | string, byte array and integer. Then it reads them from the device to verify 10 | that the read values are the same as the values that were set. 11 | 12 | NOTE: This example uses the generic XBee device (XBeeDevice) class, but it 13 | can be applied to any other local or remote XBee device class. 14 | 15 | 16 | Requirements 17 | ------------ 18 | To run this example you will need: 19 | 20 | * One XBee radio in API mode and its corresponding carrier board (XBIB 21 | or XBee Development Board). 22 | * The XCTU application (available at www.digi.com/xctu). 23 | 24 | 25 | Compatible protocols 26 | -------------------- 27 | * 802.15.4 28 | * DigiMesh 29 | * Point-to-Multipoint 30 | * Zigbee 31 | 32 | 33 | Example setup 34 | ------------- 35 | 1) Plug the XBee radio into the XBee adapter and connect it to your 36 | computer's USB or serial port. 37 | 38 | 2) Ensure that the module is in API mode. 39 | For further information on how to perform this task, read the 40 | 'Configuring Your XBee Modules' topic of the Getting Started guide. 41 | 42 | 3) Set the port and baud rate of the XBee radio in the sample file class. 43 | If you configured the module in the previous step with the XCTU, you 44 | will see the port number and baud rate in the 'Port' label of the device 45 | on the left view. 46 | 47 | 48 | Running the example 49 | ------------------- 50 | First, build and launch the application. To test the functionality, check 51 | that the output console displays the parameters set and then states the 52 | following message: 53 | 54 | "All parameters were set correctly!" 55 | 56 | That message indicates that all the parameters could be set and their read 57 | values are the same as the values that were set. 58 | -------------------------------------------------------------------------------- /examples/filesystem/FormatFilesystemSample/readme.txt: -------------------------------------------------------------------------------- 1 | Introduction 2 | ------------ 3 | This sample Python application shows how to format the filesystem of a 4 | local XBee device and retrieve usage information. 5 | 6 | The application uses the FileSystemManager to access the device filesystem 7 | and execute the required actions. 8 | 9 | NOTE: This example uses the generic XBee device (XBeeDevice) class, but it 10 | can be applied to any other local device class. 11 | 12 | 13 | Requirements 14 | ------------ 15 | To run this example you will need: 16 | 17 | * One XBee radio in API mode and its corresponding carrier board (XBIB 18 | or XBee Development Board). 19 | * The XCTU application (available at www.digi.com/xctu). 20 | 21 | 22 | Compatible hardware 23 | -------------------- 24 | * Local XBee3 devices 25 | 26 | 27 | Compatible protocols 28 | -------------------- 29 | * 802.15.4 30 | * DigiMesh 31 | * Zigbee 32 | 33 | 34 | Example setup 35 | ------------- 36 | 1) Plug the XBee radio into the XBee adapter and connect it to your 37 | computer's USB or serial port. 38 | 39 | 2) Ensure that the module is in API mode. 40 | For further information on how to perform this task, read the 41 | 'Configuring Your XBee Modules' topic of the Getting Started guide. 42 | 43 | 3) Set the port and baud rate of the XBee radio in the sample file class. 44 | If you configured the module in the previous step with the XCTU, you 45 | will see the port number and baud rate in the 'Port' label of the device 46 | on the left view. 47 | 48 | 4) To use a remote XBee, configure its node identifier (NI) in the sample 49 | file. Leave it empty to use the local XBee. 50 | 51 | Running the example 52 | ------------------- 53 | First, build and launch the application. To test the functionality, check 54 | the filesystem usage information reported in the console before and after the 55 | filesystem format operation. 56 | 57 | If any error occurs during the process, it will be displayed in the console. 58 | -------------------------------------------------------------------------------- /examples/filesystem/ListDirectorySample/ListDirectorySample.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019, 2020, Digi International Inc. 2 | # 3 | # Permission to use, copy, modify, and/or distribute this software for any 4 | # purpose with or without fee is hereby granted, provided that the above 5 | # copyright notice and this permission notice appear in all copies. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | from digi.xbee.filesystem import FileSystemException 16 | from digi.xbee.devices import XBeeDevice 17 | from digi.xbee.exception import XBeeException 18 | 19 | # TODO: Replace with the serial port where your local module is connected to. 20 | PORT = "COM1" 21 | # TODO: Replace with the baud rate of your local module. 22 | BAUD_RATE = 9600 23 | # TODO: Replace with the name of the remote XBee to use. If empty, local is used. 24 | REMOTE_NODE_ID = None 25 | # TODO: Replace with the XBee file system path to list its contents. Leave as 'None' to use '/flash'. 26 | PATH_TO_LIST = None 27 | 28 | 29 | def main(): 30 | print(" +-------------------------------------------+") 31 | print(" | XBee Python Library List Directory Sample |") 32 | print(" +-------------------------------------------+\n") 33 | 34 | local_xbee = XBeeDevice(PORT, BAUD_RATE) 35 | fs_xbee = local_xbee 36 | 37 | try: 38 | local_xbee.open() 39 | 40 | if REMOTE_NODE_ID: 41 | # Obtain the remote XBee from the network. 42 | xbee_network = local_xbee.get_network() 43 | fs_xbee = xbee_network.discover_device(REMOTE_NODE_ID) 44 | if not fs_xbee: 45 | print("Could not find remote device '%s'" % REMOTE_NODE_ID) 46 | exit(1) 47 | 48 | filesystem_manager = fs_xbee.get_file_manager() 49 | 50 | path_to_list = PATH_TO_LIST 51 | if not path_to_list: 52 | path_to_list = "/flash" 53 | files = filesystem_manager.list_directory(path_to_list) 54 | print("Contents of '%s' (%s):\n" % 55 | (path_to_list, fs_xbee if fs_xbee.is_remote() else "local")) 56 | for file in files: 57 | print(file) 58 | except (XBeeException, FileSystemException) as e: 59 | print("ERROR: %s" % str(e)) 60 | exit(1) 61 | finally: 62 | if local_xbee and local_xbee.is_open(): 63 | local_xbee.close() 64 | 65 | 66 | if __name__ == '__main__': 67 | main() 68 | -------------------------------------------------------------------------------- /examples/filesystem/ListDirectorySample/readme.txt: -------------------------------------------------------------------------------- 1 | Introduction 2 | ------------ 3 | This sample Python application shows how to list the contents of an XBee 4 | device filesystem directory. 5 | 6 | The application uses the FileSystemManager to access the device filesystem 7 | and execute the required actions. 8 | 9 | NOTE: This example uses the generic XBee device (XBeeDevice) class, but it 10 | can be applied to any other local device class. 11 | 12 | 13 | Requirements 14 | ------------ 15 | To run this example you will need: 16 | 17 | * One XBee radio in API mode and its corresponding carrier board (XBIB 18 | or XBee Development Board). 19 | * The XCTU application (available at www.digi.com/xctu). 20 | 21 | 22 | Compatible hardware 23 | -------------------- 24 | * Local XBee3 devices 25 | 26 | 27 | Compatible protocols 28 | -------------------- 29 | * 802.15.4 30 | * DigiMesh 31 | * Zigbee 32 | 33 | 34 | Example setup 35 | ------------- 36 | 1) Plug the XBee radio into the XBee adapter and connect it to your 37 | computer's USB or serial port. 38 | 39 | 2) Ensure that the module is in API mode. 40 | For further information on how to perform this task, read the 41 | 'Configuring Your XBee Modules' topic of the Getting Started guide. 42 | 43 | 3) Set the port and baud rate of the XBee radio in the sample file class. 44 | If you configured the module in the previous step with the XCTU, you 45 | will see the port number and baud rate in the 'Port' label of the device 46 | on the left view. 47 | 48 | 4) To use a remote XBee, configure its node identifier (NI) in the sample 49 | file. Leave it empty to use the local XBee. 50 | 51 | 5) Configure the path of the XBee directory to list. 52 | 53 | 54 | Running the example 55 | ------------------- 56 | First, build and launch the application. To test the functionality, check 57 | that the console lists the selected directory contents like this: 58 | 59 | Contents of '/flash' (local): 60 | 61 | d 0.00B lib /flash/lib 62 | d 0.00B dir_1 /flash/dir_1 63 | d 0.00B dir_2 /flash/dir_2 64 | - 47.00B file.txt /flash/file.txt 65 | * 1.95KB secure.txt /flash/uploaded/secure.txt 66 | 67 | If any error occurs during the process, it will be displayed in the console. 68 | -------------------------------------------------------------------------------- /examples/filesystem/UploadDownloadFileSample/readme.txt: -------------------------------------------------------------------------------- 1 | Introduction 2 | ------------ 3 | This sample Python application shows how to upload and download a file from 4 | a local XBee device filesystem. 5 | 6 | The application uses the FileSystemManager to access the device filesystem 7 | and provides the local file and the necessary paths to the upload/download 8 | methods as well as callback functions to be notified of progress. 9 | 10 | NOTE: This example uses the generic XBee device (XBeeDevice) class, but it 11 | can be applied to any other local device class. 12 | 13 | 14 | Requirements 15 | ------------ 16 | To run this example you will need: 17 | 18 | * One XBee radio in API mode and its corresponding carrier board (XBIB 19 | or XBee Development Board). 20 | * The XCTU application (available at www.digi.com/xctu). 21 | * The file to upload to the local XBee device filesystem. 22 | 23 | 24 | Compatible hardware 25 | -------------------- 26 | * Local XBee3 devices 27 | 28 | 29 | Compatible protocols 30 | -------------------- 31 | * 802.15.4 32 | * DigiMesh 33 | * Zigbee 34 | 35 | 36 | Example setup 37 | ------------- 38 | 1) Plug the XBee radio into the XBee adapter and connect it to your 39 | computer's USB or serial port. 40 | 41 | 2) Ensure that the module is in API mode. 42 | For further information on how to perform this task, read the 43 | 'Configuring Your XBee Modules' topic of the Getting Started guide. 44 | 45 | 3) Set the port and baud rate of the XBee radio in the sample file class. 46 | If you configured the module in the previous step with the XCTU, you 47 | will see the port number and baud rate in the 'Port' label of the device 48 | on the left view. 49 | 50 | 4) To use a remote XBee, configure its node identifier (NI) in the sample 51 | file. Leave it empty to use the local XBee. 52 | 53 | 5) Configure the path of the file to upload as well as the remote and 54 | local paths to upload and download the file to. 55 | 56 | 57 | Running the example 58 | ------------------- 59 | First, build and launch the application. To test the functionality, check 60 | that the SHA256 hash reported in the console for the local file, the uploaded 61 | file and the downloaded file are the same: 62 | 63 | File hash summary 64 | ----------------------- 65 | Local: 017825c2c9c86e52b96e5d835205386badc8a3f3ebea36a53bba17abf8f058fe 66 | Uploaded: 017825c2c9c86e52b96e5d835205386badc8a3f3ebea36a53bba17abf8f058fe 67 | Downloaded: 017825c2c9c86e52b96e5d835205386badc8a3f3ebea36a53bba17abf8f058fe 68 | 69 | If any error occurs during the process, it will be displayed in the console. 70 | -------------------------------------------------------------------------------- /examples/filesystem/legacy/FormatFilesystemSample/FormatFilesystemSample.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019, 2020, Digi International Inc. 2 | # 3 | # Permission to use, copy, modify, and/or distribute this software for any 4 | # purpose with or without fee is hereby granted, provided that the above 5 | # copyright notice and this permission notice appear in all copies. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | from digi.xbee.filesystem import LocalXBeeFileSystemManager, FileSystemException 16 | from digi.xbee.devices import XBeeDevice 17 | from digi.xbee.exception import XBeeException 18 | 19 | # TODO: Replace with the serial port where your local module is connected to. 20 | PORT = "COM1" 21 | # TODO: Replace with the baud rate of your local module. 22 | BAUD_RATE = 9600 23 | 24 | 25 | def get_fs_info(fs_manager): 26 | try: 27 | info = fs_manager.get_usage_information() 28 | print("Filesystem information\n---------------------------") 29 | for entry in info: 30 | print("%s: %s bytes" % (entry, info[entry])) 31 | except FileSystemException: 32 | pass 33 | 34 | 35 | def main(): 36 | print(" +----------------------------------------------+") 37 | print(" | XBee Python Library Format Filesystem Sample |") 38 | print(" +----------------------------------------------+\n") 39 | 40 | device = XBeeDevice(PORT, BAUD_RATE) 41 | 42 | try: 43 | device.open() 44 | filesystem_manager = LocalXBeeFileSystemManager(device) 45 | print("Starting file system manager...", end=" ") 46 | filesystem_manager.connect() 47 | print("OK\n") 48 | 49 | get_fs_info(filesystem_manager) 50 | 51 | print("\nFormatting filesystem...", end=" ") 52 | filesystem_manager.format_filesystem() 53 | print("OK\n") 54 | 55 | get_fs_info(filesystem_manager) 56 | 57 | except (XBeeException, FileSystemException) as e: 58 | print("ERROR: %s" % str(e)) 59 | exit(1) 60 | finally: 61 | if filesystem_manager.is_connected: 62 | print("\nStopping file system manager...", end=" ") 63 | filesystem_manager.disconnect() 64 | print("OK") 65 | if device is not None and device.is_open(): 66 | device.close() 67 | 68 | 69 | if __name__ == '__main__': 70 | main() 71 | -------------------------------------------------------------------------------- /examples/filesystem/legacy/FormatFilesystemSample/readme.txt: -------------------------------------------------------------------------------- 1 | Introduction 2 | ------------ 3 | This sample Python application shows how to format the filesystem of a 4 | local XBee device and retrieve usage information. 5 | 6 | The application uses the LocalXBeeFileSystemManager to access the device 7 | filesystem and execute the required actions. 8 | 9 | NOTE: This example uses the generic XBee device (XBeeDevice) class, but it 10 | can be applied to any other local device class. 11 | 12 | 13 | Requirements 14 | ------------ 15 | To run this example you will need: 16 | 17 | * One XBee radio in API mode and its corresponding carrier board (XBIB 18 | or XBee Development Board). 19 | * The XCTU application (available at www.digi.com/xctu). 20 | 21 | 22 | Compatible hardware 23 | -------------------- 24 | * Local XBee3 devices 25 | 26 | 27 | Compatible protocols 28 | -------------------- 29 | * 802.15.4 30 | * DigiMesh 31 | * Zigbee 32 | 33 | 34 | Example setup 35 | ------------- 36 | 1) Plug the XBee radio into the XBee adapter and connect it to your 37 | computer's USB or serial port. 38 | 39 | 2) Ensure that the module is in API mode. 40 | For further information on how to perform this task, read the 41 | 'Configuring Your XBee Modules' topic of the Getting Started guide. 42 | 43 | 3) Set the port and baud rate of the XBee radio in the sample file class. 44 | If you configured the module in the previous step with the XCTU, you 45 | will see the port number and baud rate in the 'Port' label of the device 46 | on the left view. 47 | 48 | 49 | Running the example 50 | ------------------- 51 | First, build and launch the application. To test the functionality, check 52 | the filesystem usage information reported in the console before and after the 53 | filesystem format operation. 54 | 55 | If any error occurs during the process, it will be displayed in the console. 56 | -------------------------------------------------------------------------------- /examples/filesystem/legacy/ListDirectorySample/ListDirectorySample.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019, 2020, Digi International Inc. 2 | # 3 | # Permission to use, copy, modify, and/or distribute this software for any 4 | # purpose with or without fee is hereby granted, provided that the above 5 | # copyright notice and this permission notice appear in all copies. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | from digi.xbee.filesystem import LocalXBeeFileSystemManager, FileSystemElement, FileSystemException 16 | from digi.xbee.devices import XBeeDevice 17 | from digi.xbee.exception import XBeeException 18 | 19 | # TODO: Replace with the serial port where your local module is connected to. 20 | PORT = "COM1" 21 | # TODO: Replace with the baud rate of your local module. 22 | BAUD_RATE = 9600 23 | # TODO: Replace with the XBee file system path to list its contents. Leave as 'None' to use current dir. 24 | PATH_TO_LIST = None 25 | 26 | 27 | def main(): 28 | print(" +-------------------------------------------+") 29 | print(" | XBee Python Library List Directory Sample |") 30 | print(" +-------------------------------------------+\n") 31 | 32 | device = XBeeDevice(PORT, BAUD_RATE) 33 | 34 | try: 35 | device.open() 36 | filesystem_manager = LocalXBeeFileSystemManager(device) 37 | print("Starting file system manager...", end=" ") 38 | filesystem_manager.connect() 39 | print("OK\n") 40 | current_directory = filesystem_manager.get_current_directory() 41 | print("Current directory: %s" % current_directory) 42 | path_to_list = PATH_TO_LIST 43 | if path_to_list is None: 44 | path_to_list = current_directory 45 | files = filesystem_manager.list_directory(path_to_list) 46 | print("Contents of '%s':" % path_to_list) 47 | for file in files: 48 | print(str(file)) 49 | except (XBeeException, FileSystemException) as e: 50 | print("ERROR: %s" % str(e)) 51 | exit(1) 52 | finally: 53 | if filesystem_manager.is_connected: 54 | print("\nStopping file system manager...", end=" ") 55 | filesystem_manager.disconnect() 56 | print("OK") 57 | if device is not None and device.is_open(): 58 | device.close() 59 | 60 | 61 | if __name__ == '__main__': 62 | main() 63 | -------------------------------------------------------------------------------- /examples/filesystem/legacy/ListDirectorySample/readme.txt: -------------------------------------------------------------------------------- 1 | Introduction 2 | ------------ 3 | This sample Python application shows how to list the contents of an XBee 4 | device filesystem directory. 5 | 6 | The application uses the LocalXBeeFileSystemManager to access the device 7 | filesystem and execute the required actions. 8 | 9 | NOTE: This example uses the generic XBee device (XBeeDevice) class, but it 10 | can be applied to any other local device class. 11 | 12 | 13 | Requirements 14 | ------------ 15 | To run this example you will need: 16 | 17 | * One XBee radio in API mode and its corresponding carrier board (XBIB 18 | or XBee Development Board). 19 | * The XCTU application (available at www.digi.com/xctu). 20 | 21 | 22 | Compatible hardware 23 | -------------------- 24 | * Local XBee3 devices 25 | 26 | 27 | Compatible protocols 28 | -------------------- 29 | * 802.15.4 30 | * DigiMesh 31 | * Zigbee 32 | 33 | 34 | Example setup 35 | ------------- 36 | 1) Plug the XBee radio into the XBee adapter and connect it to your 37 | computer's USB or serial port. 38 | 39 | 2) Ensure that the module is in API mode. 40 | For further information on how to perform this task, read the 41 | 'Configuring Your XBee Modules' topic of the Getting Started guide. 42 | 43 | 3) Set the port and baud rate of the XBee radio in the sample file class. 44 | If you configured the module in the previous step with the XCTU, you 45 | will see the port number and baud rate in the 'Port' label of the device 46 | on the left view. 47 | 48 | 4) Configure the path of the XBee directory to list. 49 | 50 | 51 | Running the example 52 | ------------------- 53 | First, build and launch the application. To test the functionality, check 54 | that the console lists the selected directory contents like this: 55 | 56 | Starting file system manager... OK 57 | 58 | Current directory: /flash 59 | Contents of '/flash' (local): 60 | d 0.00B lib /flash/lib 61 | d 0.00B dir_1 /flash/dir_1 62 | d 0.00B dir_2 /flash/dir_2 63 | - 47.00B file.txt /flash/file.txt 64 | * 1.95KB secure.txt /flash/uploaded/secure.txt 65 | 66 | Stopping file system manager... OK 67 | 68 | If any error occurs during the process, it will be displayed in the console. 69 | -------------------------------------------------------------------------------- /examples/filesystem/legacy/RemoteFilesystemUpdateSample/RemoteFilesystemUpdateSample.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020, Digi International Inc. 2 | # 3 | # Permission to use, copy, modify, and/or distribute this software for any 4 | # purpose with or without fee is hereby granted, provided that the above 5 | # copyright notice and this permission notice appear in all copies. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | from digi.xbee.devices import XBeeDevice 16 | from digi.xbee.exception import OperationNotSupportedException, XBeeException 17 | from digi.xbee.filesystem import FileSystemException 18 | 19 | # TODO: Replace with the serial port where your local module is connected to. 20 | PORT = "COM1" 21 | # TODO: Replace with the baud rate of your local module. 22 | BAUD_RATE = 9600 23 | # TODO: Replace with the Node ID (NI) of the remote module to update its filesystem. 24 | REMOTE_NODE_ID = "REMOTE" 25 | # TODO: Replace with the location of the OTA filesystem image file to update. 26 | OTA_FILESYSTEM_FILE = "" 27 | 28 | 29 | def main(): 30 | print(" +-----------------------------------------------------+") 31 | print(" | XBee Python Library Remote Filesystem Update Sample |") 32 | print(" +-----------------------------------------------------+\n") 33 | 34 | device = XBeeDevice(PORT, BAUD_RATE) 35 | try: 36 | device.open() 37 | 38 | # Obtain the remote XBee device from the XBee network. 39 | xbee_network = device.get_network() 40 | remote_device = xbee_network.discover_device(REMOTE_NODE_ID) 41 | if remote_device is None: 42 | print("Could not find the remote device") 43 | exit(1) 44 | 45 | print("Starting filesystem image update process...") 46 | remote_device.update_filesystem_image(OTA_FILESYSTEM_FILE, 47 | progress_callback=progress_callback) 48 | print("Filesystem image updated successfully!") 49 | except (XBeeException, FileSystemException, OperationNotSupportedException) as e: 50 | print("ERROR: %s" % str(e)) 51 | exit(1) 52 | finally: 53 | if device is not None and device.is_open(): 54 | device.close() 55 | 56 | 57 | def progress_callback(task, percent): 58 | print("%s: %d%%" % (task, percent)) 59 | 60 | 61 | if __name__ == '__main__': 62 | main() 63 | -------------------------------------------------------------------------------- /examples/filesystem/legacy/UploadDownloadFileSample/readme.txt: -------------------------------------------------------------------------------- 1 | Introduction 2 | ------------ 3 | This sample Python application shows how to upload and download a file from 4 | a local XBee device filesystem. 5 | 6 | The application uses the LocalXBeeFileSystemManager to access the device 7 | filesystem and provides the local file and the necessary paths to the 8 | upload/download methods as well as callback functions to be notified of 9 | progress. 10 | 11 | NOTE: This example uses the generic XBee device (XBeeDevice) class, but it 12 | can be applied to any other local device class. 13 | 14 | 15 | Requirements 16 | ------------ 17 | To run this example you will need: 18 | 19 | * One XBee radio in API mode and its corresponding carrier board (XBIB 20 | or XBee Development Board). 21 | * The XCTU application (available at www.digi.com/xctu). 22 | * The file to upload to the local XBee device filesystem. 23 | 24 | 25 | Compatible hardware 26 | -------------------- 27 | * Local XBee3 devices 28 | 29 | 30 | Compatible protocols 31 | -------------------- 32 | * 802.15.4 33 | * DigiMesh 34 | * Zigbee 35 | 36 | 37 | Example setup 38 | ------------- 39 | 1) Plug the XBee radio into the XBee adapter and connect it to your 40 | computer's USB or serial port. 41 | 42 | 2) Ensure that the module is in API mode. 43 | For further information on how to perform this task, read the 44 | 'Configuring Your XBee Modules' topic of the Getting Started guide. 45 | 46 | 3) Set the port and baud rate of the XBee radio in the sample file class. 47 | If you configured the module in the previous step with the XCTU, you 48 | will see the port number and baud rate in the 'Port' label of the device 49 | on the left view. 50 | 51 | 4) Configure the path of the file to upload as well as the remote and 52 | local paths to upload and download the file to. 53 | 54 | 55 | Running the example 56 | ------------------- 57 | First, build and launch the application. To test the functionality, check 58 | that the SHA256 hash reported in the console for the local file, the uploaded 59 | file and the downloaded file are the same: 60 | 61 | File hash summary 62 | ----------------------- 63 | Local: 017825c2c9c86e52b96e5d835205386badc8a3f3ebea36a53bba17abf8f058fe 64 | Uploaded: 017825c2c9c86e52b96e5d835205386badc8a3f3ebea36a53bba17abf8f058fe 65 | Downloaded: 017825c2c9c86e52b96e5d835205386badc8a3f3ebea36a53bba17abf8f058fe 66 | 67 | If any error occurs during the process, it will be displayed in the console. 68 | -------------------------------------------------------------------------------- /examples/firmware/LocalFirmwareUpdateSample/LocalFirmwareUpdateSample.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019, Digi International Inc. 2 | # 3 | # Permission to use, copy, modify, and/or distribute this software for any 4 | # purpose with or without fee is hereby granted, provided that the above 5 | # copyright notice and this permission notice appear in all copies. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | from digi.xbee.devices import XBeeDevice 16 | from digi.xbee.exception import FirmwareUpdateException, OperationNotSupportedException, XBeeException 17 | 18 | # TODO: Replace with the serial port where your local module is connected to. 19 | PORT = "COM1" 20 | # TODO: Replace with the baud rate of your local module. 21 | BAUD_RATE = 9600 22 | # TODO: Replace with the location of the firmware files to update. 23 | XML_FIRMWARE_FILE = "" 24 | BOOTLOADER_FIRMWARE_FILE = None # Optional 25 | XBEE_FIRMWARE_FILE = None # Optional 26 | 27 | 28 | def main(): 29 | print(" +--------------------------------------------------+") 30 | print(" | XBee Python Library Local Firmware Update Sample |") 31 | print(" +--------------------------------------------------+\n") 32 | 33 | device = XBeeDevice(PORT, BAUD_RATE) 34 | 35 | try: 36 | device.open() 37 | print("Starting firmware update process...") 38 | device.update_firmware(XML_FIRMWARE_FILE, 39 | xbee_firmware_file=XBEE_FIRMWARE_FILE, 40 | bootloader_firmware_file=BOOTLOADER_FIRMWARE_FILE, 41 | progress_callback=progress_callback,) 42 | print("Firmware updated successfully!") 43 | except (XBeeException, FirmwareUpdateException, OperationNotSupportedException) as e: 44 | print("ERROR: %s" % str(e)) 45 | exit(1) 46 | finally: 47 | if device is not None and device.is_open(): 48 | device.close() 49 | 50 | 51 | def progress_callback(task, percent): 52 | print("%s: %d%%" % (task, percent)) 53 | 54 | 55 | if __name__ == '__main__': 56 | main() 57 | -------------------------------------------------------------------------------- /examples/firmware/LocalFirmwareUpdateSample/readme.txt: -------------------------------------------------------------------------------- 1 | Introduction 2 | ------------ 3 | This sample Python application shows how to update the firmware of a local 4 | XBee device. 5 | 6 | The application provides the required hardware files to the update method 7 | as well as a callback function to be notified of progress. 8 | 9 | NOTE: This example uses the generic XBee device (XBeeDevice) class, but it 10 | can be applied to any other local device class. 11 | 12 | 13 | Requirements 14 | ------------ 15 | To run this example you will need: 16 | 17 | * One XBee radio in API mode and its corresponding carrier board (XBIB 18 | or XBee Development Board). 19 | * The XCTU application (available at www.digi.com/xctu). 20 | * The firmware files to update the device. 21 | 22 | 23 | Compatible hardware 24 | -------------------- 25 | * Local XBee3 devices 26 | 27 | 28 | Compatible protocols 29 | -------------------- 30 | * 802.15.4 31 | * DigiMesh 32 | * Zigbee 33 | 34 | 35 | Example setup 36 | ------------- 37 | 1) Plug the XBee radio into the XBee adapter and connect it to your 38 | computer's USB or serial port. 39 | 40 | 2) Ensure that the module is in API mode. 41 | For further information on how to perform this task, read the 42 | 'Configuring Your XBee Modules' topic of the Getting Started guide. 43 | 44 | 3) Set the port and baud rate of the XBee radio in the sample file class. 45 | If you configured the module in the previous step with the XCTU, you 46 | will see the port number and baud rate in the 'Port' label of the device 47 | on the left view. 48 | 49 | 4) Configure the paths of the firmware files in the sample file class. 50 | Only the XML firmware file path is mandatory, the rest can be left as 51 | 'None'. In that case, the API will look for the firmware files in the same 52 | directory as the XML firmware file one. 53 | 54 | 55 | Running the example 56 | ------------------- 57 | First, build and launch the application. To test the functionality, check 58 | that the output console displays this message: 59 | 60 | "Starting firmware update process..." 61 | 62 | Followed by percentage progress messages: 63 | 64 | "Updating XBee firmware: 1%" 65 | "Updating XBee firmware: 2%" 66 | . . . 67 | 68 | When the process completes, the following message is displayed: 69 | 70 | "Firmware updated successfully!" 71 | 72 | If any error occurs during the process, it will be displayed in the console. 73 | -------------------------------------------------------------------------------- /examples/io/LocalADCSample/LocalADCSample.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017, Digi International Inc. 2 | # 3 | # Permission to use, copy, modify, and/or distribute this software for any 4 | # purpose with or without fee is hereby granted, provided that the above 5 | # copyright notice and this permission notice appear in all copies. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | from digi.xbee.devices import XBeeDevice 16 | from digi.xbee.io import IOLine, IOMode 17 | import threading 18 | import time 19 | 20 | # TODO: Replace with the serial port where your local module is connected to. 21 | PORT = "COM1" 22 | # TODO: Replace with the baud rate of your local module. 23 | BAUD_RATE = 9600 24 | 25 | IOLINE_IN = IOLine.DIO1_AD1 26 | 27 | 28 | def main(): 29 | print(" +-------------------------------------------+") 30 | print(" | XBee Python Library Read Local ADC Sample |") 31 | print(" +-------------------------------------------+\n") 32 | 33 | th = None 34 | 35 | device = XBeeDevice(PORT, BAUD_RATE) 36 | 37 | try: 38 | device.open() 39 | 40 | device.set_io_configuration(IOLINE_IN, IOMode.ADC) 41 | 42 | stop = False 43 | 44 | def polling_adc(): 45 | while not stop: 46 | # Read the analog value from the input line. 47 | value = device.get_adc_value(IOLINE_IN) 48 | print("%s: %d" % (IOLINE_IN, value)) 49 | time.sleep(1) 50 | 51 | th = threading.Thread(target=polling_adc) 52 | th.start() 53 | 54 | input() 55 | 56 | finally: 57 | stop = True 58 | if th is not None and th.isAlive(): 59 | th.join() 60 | if device is not None and device.is_open(): 61 | device.close() 62 | 63 | 64 | if __name__ == '__main__': 65 | main() 66 | -------------------------------------------------------------------------------- /examples/io/LocalDIOSample/LocalDIOSample.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017, Digi International Inc. 2 | # 3 | # Permission to use, copy, modify, and/or distribute this software for any 4 | # purpose with or without fee is hereby granted, provided that the above 5 | # copyright notice and this permission notice appear in all copies. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | from digi.xbee.devices import XBeeDevice 16 | from digi.xbee.io import IOLine, IOMode 17 | import time 18 | import threading 19 | 20 | # TODO: Replace with the serial port where your local module is connected to. 21 | PORT = "COM1" 22 | # TODO: Replace with the baud rate of your local module. 23 | BAUD_RATE = 9600 24 | 25 | IO_LINE_IN = IOLine.DIO3_AD3 26 | IO_LINE_OUT = IOLine.DIO4_AD4 27 | 28 | 29 | def main(): 30 | print(" +----------------------------------------------+") 31 | print(" | XBee Python Library Get/Set Local DIO Sample |") 32 | print(" +----------------------------------------------+\n") 33 | 34 | stop = False 35 | th = None 36 | 37 | device = XBeeDevice(PORT, BAUD_RATE) 38 | 39 | try: 40 | device.open() 41 | 42 | def io_detection_callback(): 43 | while not stop: 44 | # Read the digital value from the input line. 45 | io_value = device.get_dio_value(IO_LINE_IN) 46 | print("%s: %s" % (IO_LINE_IN, io_value)) 47 | 48 | # Set the previous value to the output line. 49 | device.set_dio_value(IO_LINE_OUT, io_value) 50 | 51 | time.sleep(1) 52 | 53 | th = threading.Thread(target=io_detection_callback) 54 | 55 | device.set_io_configuration(IO_LINE_IN, IOMode.DIGITAL_IN) 56 | device.set_io_configuration(IO_LINE_OUT, IOMode.DIGITAL_OUT_LOW) 57 | 58 | time.sleep(1) 59 | th.start() 60 | 61 | input() 62 | 63 | finally: 64 | stop = True 65 | if th is not None and th.is_alive(): 66 | th.join() 67 | if device is not None and device.is_open(): 68 | device.close() 69 | 70 | 71 | if __name__ == '__main__': 72 | main() 73 | -------------------------------------------------------------------------------- /examples/io/RemoteADCSample/RemoteADCSample.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017, Digi International Inc. 2 | # 3 | # Permission to use, copy, modify, and/or distribute this software for any 4 | # purpose with or without fee is hereby granted, provided that the above 5 | # copyright notice and this permission notice appear in all copies. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | from digi.xbee.devices import XBeeDevice 16 | from digi.xbee.io import IOLine, IOMode 17 | import time 18 | import threading 19 | 20 | # TODO: Replace with the serial port where your local module is connected to. 21 | PORT = "COM1" 22 | # TODO: Replace with the baud rate of your local module. 23 | BAUD_RATE = 9600 24 | 25 | REMOTE_NODE_ID = "REMOTE" 26 | 27 | IOLINE_IN = IOLine.DIO1_AD1 28 | 29 | 30 | def main(): 31 | print(" +--------------------------------------------+") 32 | print(" | XBee Python Library Read Remote ADC Sample |") 33 | print(" +--------------------------------------------+\n") 34 | 35 | stop = False 36 | th = None 37 | 38 | local_device = XBeeDevice(PORT, BAUD_RATE) 39 | 40 | try: 41 | local_device.open() 42 | 43 | # Obtain the remote XBee device from the XBee network. 44 | xbee_network = local_device.get_network() 45 | remote_device = xbee_network.discover_device(REMOTE_NODE_ID) 46 | if remote_device is None: 47 | print("Could not find the remote device") 48 | exit(1) 49 | 50 | remote_device.set_io_configuration(IOLINE_IN, IOMode.ADC) 51 | 52 | def read_adc_task(): 53 | while not stop: 54 | # Read the analog value from the remote input line. 55 | value = remote_device.get_adc_value(IOLINE_IN) 56 | print("%s: %d" % (IOLINE_IN, value)) 57 | 58 | time.sleep(0.2) 59 | 60 | th = threading.Thread(target=read_adc_task) 61 | 62 | time.sleep(0.5) 63 | th.start() 64 | 65 | input() 66 | 67 | finally: 68 | stop = True 69 | if th is not None and th.isAlive(): 70 | th.join() 71 | if local_device is not None and local_device.is_open(): 72 | local_device.close() 73 | 74 | 75 | if __name__ == '__main__': 76 | main() 77 | -------------------------------------------------------------------------------- /examples/network/DiscoverDevicesSample/DiscoverDevicesSample.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017, Digi International Inc. 2 | # 3 | # Permission to use, copy, modify, and/or distribute this software for any 4 | # purpose with or without fee is hereby granted, provided that the above 5 | # copyright notice and this permission notice appear in all copies. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | import time 16 | 17 | from digi.xbee.models.status import NetworkDiscoveryStatus 18 | from digi.xbee.devices import XBeeDevice 19 | 20 | # TODO: Replace with the serial port where your local module is connected to. 21 | PORT = "COM1" 22 | # TODO: Replace with the baud rate of your local module. 23 | BAUD_RATE = 9600 24 | 25 | 26 | def main(): 27 | print(" +---------------------------------------------+") 28 | print(" | XBee Python Library Discover Devices Sample |") 29 | print(" +---------------------------------------------+\n") 30 | 31 | device = XBeeDevice(PORT, BAUD_RATE) 32 | 33 | try: 34 | device.open() 35 | 36 | xbee_network = device.get_network() 37 | 38 | xbee_network.set_discovery_timeout(15) # 15 seconds. 39 | 40 | xbee_network.clear() 41 | 42 | # Callback for discovered devices. 43 | def callback_device_discovered(remote): 44 | print("Device discovered: %s" % remote) 45 | 46 | # Callback for discovery finished. 47 | def callback_discovery_finished(status): 48 | if status == NetworkDiscoveryStatus.SUCCESS: 49 | print("Discovery process finished successfully.") 50 | else: 51 | print("There was an error discovering devices: %s" % status.description) 52 | 53 | xbee_network.add_device_discovered_callback(callback_device_discovered) 54 | 55 | xbee_network.add_discovery_process_finished_callback(callback_discovery_finished) 56 | 57 | xbee_network.start_discovery_process() 58 | 59 | print("Discovering remote XBee devices...") 60 | 61 | while xbee_network.is_discovery_running(): 62 | time.sleep(0.1) 63 | 64 | finally: 65 | if device is not None and device.is_open(): 66 | device.close() 67 | 68 | 69 | if __name__ == '__main__': 70 | main() 71 | -------------------------------------------------------------------------------- /examples/network/DiscoverDevicesSample/readme.txt: -------------------------------------------------------------------------------- 1 | Introduction 2 | ------------ 3 | This sample Python application demonstrates how to obtain the XBee network 4 | object from a local XBee device and discover the remote XBee devices that 5 | compose the network. The example adds a discovery listener, so the events 6 | will be received by the callbacks provided by the listener object. 7 | 8 | The remote XBee devices are printed out as soon as they are found during the 9 | discovery. 10 | 11 | NOTE: This example uses the generic XBee device (XBeeDevice) class, but it 12 | can be applied to any other local XBee device class. 13 | 14 | 15 | Requirements 16 | ------------ 17 | To run this example you will need: 18 | 19 | * At least two XBee radios in API mode and their corresponding carrier 20 | board (XBIB or equivalent). More than two radios are recommended. 21 | * The XCTU application (available at www.digi.com/xctu). 22 | 23 | 24 | Compatible protocols 25 | -------------------- 26 | * 802.15.4 27 | * DigiMesh 28 | * Point-to-Multipoint 29 | * Zigbee 30 | 31 | 32 | Example setup 33 | ------------- 34 | 1) Plug the XBee radios into the XBee adapters and connect them to your 35 | computer's USB or serial ports. 36 | 37 | 2) Ensure that the modules are in API mode and on the same network. 38 | For further information on how to perform this task, read the 39 | 'Configuring Your XBee Modules' topic of the Getting Started guide. 40 | 41 | 3) Set the port and baud rate of the local XBee radio in the sample file. 42 | If you configured the modules in the previous step with the XCTU, you 43 | will see the port number and baud rate in the 'Port' label of the device 44 | on the left view. 45 | 46 | 47 | Running the example 48 | ------------------- 49 | First, build and launch the application. As soon as the application is 50 | executed, it will perform a device discovery in the network. To verify the 51 | application is working properly, check that the following happens: 52 | 53 | 1) The output console states the following message: 54 | 55 | "Discovering remote XBee devices..." 56 | 57 | 2) For each discovered device the output console should display the 58 | following message: 59 | 60 | "Device discovered: XXXXXXXXXXXXXXXX" 61 | 62 | - Where XXXXXXXXXXXXXXXX is the MAC address of the remote XBee 63 | device. 64 | 65 | 3) When the discovery process finishes the following message should be 66 | displayed: 67 | 68 | "Discovery process finished successfully." 69 | -------------------------------------------------------------------------------- /examples/profile/ApplyXBeeProfileRemoteSample/ApplyXBeeProfileRemoteSample.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019, Digi International Inc. 2 | # 3 | # Permission to use, copy, modify, and/or distribute this software for any 4 | # purpose with or without fee is hereby granted, provided that the above 5 | # copyright notice and this permission notice appear in all copies. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | from digi.xbee.devices import XBeeDevice 16 | 17 | # TODO: Replace with the location of the XBee profile file to read. 18 | PROFILE_PATH = "" 19 | # TODO: Replace with the serial port where your local module is connected to. 20 | PORT = "COM1" 21 | # TODO: Replace with the baud rate of your local module. 22 | BAUD_RATE = 9600 23 | # TODO: Replace with the Node ID (NI) of the remote module to update. 24 | REMOTE_NODE_ID = "" 25 | 26 | 27 | def main(): 28 | print(" +------------------------------------------------------+") 29 | print(" | XBee Python Library Apply XBee Profile Remote Sample |") 30 | print(" +------------------------------------------------------+\n") 31 | 32 | device = XBeeDevice(PORT, BAUD_RATE) 33 | try: 34 | device.open() 35 | 36 | # Obtain the remote XBee device from the XBee network. 37 | xbee_network = device.get_network() 38 | remote_device = xbee_network.discover_device(REMOTE_NODE_ID) 39 | if remote_device is None: 40 | print("Could not find the remote device") 41 | exit(1) 42 | 43 | print("Updating profile '%s'...\n" % PROFILE_PATH) 44 | remote_device.apply_profile(PROFILE_PATH, progress_callback=progress_callback) 45 | print("\nProfile updated successfully!") 46 | except Exception as e: 47 | print(str(e)) 48 | exit(1) 49 | finally: 50 | if device.is_open(): 51 | device.close() 52 | 53 | 54 | def progress_callback(task, percent): 55 | if percent is not None: 56 | print("%s: %d%%" % (task, percent)) 57 | else: 58 | print("%s" % task) 59 | 60 | 61 | if __name__ == '__main__': 62 | main() 63 | -------------------------------------------------------------------------------- /examples/profile/ApplyXBeeProfileSample/ApplyXBeeProfileSample.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019, Digi International Inc. 2 | # 3 | # Permission to use, copy, modify, and/or distribute this software for any 4 | # purpose with or without fee is hereby granted, provided that the above 5 | # copyright notice and this permission notice appear in all copies. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | from digi.xbee.devices import XBeeDevice 16 | 17 | # TODO: Replace with the location of the XBee profile file to read. 18 | PROFILE_PATH = "" 19 | # TODO: Replace with the serial port where your local module is connected to. 20 | PORT = "COM1" 21 | # TODO: Replace with the baud rate of your local module. 22 | BAUD_RATE = 9600 23 | 24 | 25 | def main(): 26 | print(" +----------------------------------------------+") 27 | print(" | XBee Python Library Read XBee Profile Sample |") 28 | print(" +----------------------------------------------+\n") 29 | 30 | device = XBeeDevice(PORT, BAUD_RATE) 31 | try: 32 | device.open() 33 | print("Updating profile '%s'...\n" % PROFILE_PATH) 34 | device.apply_profile(PROFILE_PATH, progress_callback=progress_callback) 35 | print("\nProfile updated successfully!") 36 | except Exception as e: 37 | print(str(e)) 38 | exit(1) 39 | finally: 40 | if device.is_open(): 41 | device.close() 42 | 43 | 44 | def progress_callback(task, percent): 45 | if percent is not None: 46 | print("%s: %d%%" % (task, percent)) 47 | else: 48 | print("%s" % task) 49 | 50 | 51 | if __name__ == '__main__': 52 | main() 53 | -------------------------------------------------------------------------------- /examples/profile/ApplyXBeeProfileSample/readme.txt: -------------------------------------------------------------------------------- 1 | Introduction 2 | ------------ 3 | This sample Python application shows how to apply an existing XBee profile 4 | to a XBee device. 5 | 6 | The application provides the profile file to the update method as well as a 7 | callback function to be notified of progress. 8 | 9 | NOTE: This example uses the generic XBee device (XBeeDevice) class, but it 10 | can be applied to any other local device class. 11 | 12 | 13 | Requirements 14 | ------------ 15 | To run this example you will need: 16 | 17 | * One XBee radio in API mode and its corresponding carrier board (XBIB 18 | or XBee Development Board). 19 | * The XCTU application (available at www.digi.com/xctu). 20 | * The XBee profile file to update the device. 21 | 22 | 23 | Compatible hardware 24 | -------------------- 25 | * Local XBee3 devices 26 | 27 | 28 | Compatible protocols 29 | -------------------- 30 | * 802.15.4 31 | * DigiMesh 32 | * Zigbee 33 | 34 | 35 | Example setup 36 | ------------- 37 | 1) Plug the XBee radio into the XBee adapter and connect it to your 38 | computer's USB or serial port. 39 | 40 | 2) Ensure that the module is in API mode. 41 | For further information on how to perform this task, read the 42 | 'Configuring Your XBee Modules' topic of the Getting Started guide. 43 | 44 | 3) Set the port and baud rate of the XBee radio in the sample file class. 45 | If you configured the module in the previous step with the XCTU, you 46 | will see the port number and baud rate in the 'Port' label of the device 47 | on the left view. 48 | 49 | 4) Configure the path of the XBee profile file in the sample file class. 50 | 51 | 52 | Running the example 53 | ------------------- 54 | First, build and launch the application. To test the functionality, check 55 | that the output console displays this message: 56 | 57 | "Updating profile ''..." 58 | 59 | Followed by percentage progress messages by task: 60 | 61 | "Updating XBee firmware: 1%" 62 | "Updating XBee firmware: 2%" 63 | . . . 64 | 65 | When the process completes, the following message is displayed: 66 | 67 | "Profile updated successfully!" 68 | 69 | If any error occurs during the process, it will be displayed in the console. 70 | -------------------------------------------------------------------------------- /examples/profile/ReadXBeeProfileSample/ReadXBeeProfileSample.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019, Digi International Inc. 2 | # 3 | # Permission to use, copy, modify, and/or distribute this software for any 4 | # purpose with or without fee is hereby granted, provided that the above 5 | # copyright notice and this permission notice appear in all copies. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | from digi.xbee.profile import XBeeProfile, ReadProfileException 16 | 17 | # TODO: Replace with the location of the XBee profile file to read. 18 | PROFILE_PATH = "" 19 | 20 | 21 | def main(): 22 | print(" +----------------------------------------------+") 23 | print(" | XBee Python Library Read XBee Profile Sample |") 24 | print(" +----------------------------------------------+\n") 25 | 26 | try: 27 | xbee_profile = XBeeProfile(PROFILE_PATH) 28 | print("Profile information\n-----------------------------------") 29 | print(" - Location: %s" % xbee_profile.profile_file) 30 | print(" - Version: %s" % xbee_profile.version) 31 | print(" - Firmware version: %s" % xbee_profile.firmware_version) 32 | print(" - Hardware version: %s" % xbee_profile.hardware_version) 33 | print(" - Protocol: %s" % xbee_profile.protocol.description) 34 | print(" - Flash firmware option: %s" % xbee_profile.flash_firmware_option.description) 35 | print(" - Description: %s" % xbee_profile.description) 36 | print(" - Reset settings: %s" % xbee_profile.reset_settings) 37 | print(" - Has filesystem: %s" % xbee_profile.has_filesystem) 38 | print(" - AT settings:") 39 | if not xbee_profile.profile_settings: 40 | print(" - None") 41 | return 42 | for profile_setting in xbee_profile.profile_settings.values(): 43 | print(" - Setting '%s' - type: %s - format: %s - value: %s" % 44 | (profile_setting.name, profile_setting.type.description, 45 | profile_setting.format.description, profile_setting.value)) 46 | 47 | except ReadProfileException as e: 48 | print(str(e)) 49 | 50 | 51 | if __name__ == '__main__': 52 | main() 53 | -------------------------------------------------------------------------------- /examples/profile/ReadXBeeProfileSample/readme.txt: -------------------------------------------------------------------------------- 1 | Introduction 2 | ------------ 3 | This sample Python application shows how to read an existing XBee profile 4 | and extract its properties. 5 | 6 | The application creates an XBee profile object from an existing XBee profile 7 | file and prints all the accessible settings and properties. 8 | 9 | 10 | Requirements 11 | ------------ 12 | To run this example you will need: 13 | 14 | * The XBee profile file to read. 15 | 16 | 17 | Compatible hardware 18 | -------------------- 19 | * No hardware required 20 | 21 | 22 | Compatible protocols 23 | -------------------- 24 | * Any 25 | 26 | 27 | Example setup 28 | ------------- 29 | 1) Configure the path of the XBee profile file in the sample file class. 30 | 31 | 32 | Running the example 33 | ------------------- 34 | First, build and launch the application. To test the functionality, check 35 | that the output console displays the profile information. 36 | 37 | If any error occurs during the process, it will be displayed in the console. 38 | -------------------------------------------------------------------------------- /examples/statistics/GetXBeeStatisticsSample/readme.txt: -------------------------------------------------------------------------------- 1 | Introduction 2 | ------------ 3 | This sample Python application shows how to get XBee statistics using 4 | the XBee Python Library. 5 | 6 | The application sets the value of four parameters with different value types: 7 | string, byte array and integer. Then it reads them from the device to verify 8 | that the read values are the same as the values that were set. After that, it 9 | gets the current XBee statistics. 10 | 11 | NOTE: This example uses the generic XBee device (XBeeDevice) class, 12 | but it can be applied to any other local XBee device class. 13 | 14 | Requirements 15 | ------------ 16 | To run this example you will need: 17 | 18 | * One XBee radio in API mode and its corresponding carrier board (XBIB 19 | or XBee Development Board). 20 | * The XCTU application (available at www.digi.com/xctu). 21 | 22 | 23 | Compatible protocols 24 | -------------------- 25 | * 802.15.4 26 | * DigiMesh 27 | * Point-to-Multipoint 28 | * Zigbee 29 | 30 | 31 | Example setup 32 | ------------- 33 | 1) Plug the XBee radio into the XBee adapter and connect it to your 34 | computer's USB or serial port. 35 | 36 | 2) Ensure that the module is in API mode. 37 | For further information on how to perform this task, read the 38 | 'Configuring Your XBee Modules' topic of the Getting Started guide. 39 | 40 | 3) Set the port and baud rate of the XBee radio in the sample file class. 41 | If you configured the module in the previous step with the XCTU, you 42 | will see the port number and baud rate in the 'Port' label of the device 43 | on the left view. 44 | 45 | 46 | Running the example 47 | ------------------- 48 | First, build and launch the application. To test the functionality, check 49 | that the output console displays the parameters set and then states the 50 | following message: 51 | 52 | "All parameters were set correctly!" 53 | 54 | That message indicates that all the parameters could be set and their read 55 | values are the same as the values that were set. 56 | Next, the XBee statistics are read and the next message appers: 57 | 58 | "All XBee Statistics displayed!" 59 | 60 | That message indicates that all XBee statistics were displayed. The statistics 61 | shown are: 62 | * RX info: Number of receive packets and bytes. 63 | * TX info: Number of transmitted packets and bytes. 64 | * Remote AT command errors: Number of packets of remote AT commands 65 | that failed. 66 | * TX numbers: Number of packets which transmission failed. 67 | -------------------------------------------------------------------------------- /functional_tests/Bluetooth/device_info.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024, Digi International Inc. 2 | # 3 | # This Source Code Form is subject to the terms of the Mozilla Public 4 | # License, v. 2.0. If a copy of the MPL was not distributed with this 5 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | from digi.xbee.devices import BluDevice 16 | 17 | # Configure your test device port and baud rate 18 | PORT_LOCAL = "COM1" 19 | BAUD_RATE_LOCAL = 9600 20 | 21 | 22 | def main(): 23 | print(" +-----------------------------+") 24 | print(" | XBee 3 BLU device info test |") 25 | print(" +-----------------------------+\n") 26 | 27 | local = BluDevice(PORT_LOCAL, BAUD_RATE_LOCAL) 28 | 29 | try: 30 | local.open() 31 | local.read_device_info() 32 | 33 | print("Firmware Version:", local.get_firmware_version().hex()) 34 | 35 | hv = local.get_hardware_version() 36 | print("Hardware Version: %s (0x%02X)" % (hv, hv.code)) 37 | 38 | print("Bluetooth MAC:", local.get_bluetooth_mac_addr()) 39 | print( 40 | "Bluetooth Identifier:", 41 | ascii( 42 | local.get_parameter("BI").decode( 43 | "ascii", errors="backslashreplace" 44 | ) 45 | ) 46 | ) 47 | 48 | print("Serial Number:", local.get_64bit_addr()) 49 | print("Node ID:", ascii(local.get_node_id())) 50 | 51 | finally: 52 | if local.is_open(): 53 | local.close() 54 | 55 | 56 | if __name__ == "__main__": 57 | main() 58 | -------------------------------------------------------------------------------- /functional_tests/comunication/read_data_timeout.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017-2019, Digi International Inc. 2 | # 3 | # This Source Code Form is subject to the terms of the Mozilla Public 4 | # License, v. 2.0. If a copy of the MPL was not distributed with this 5 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | import time 16 | 17 | from digi.xbee.devices import XBeeDevice 18 | from digi.xbee.devices import RemoteXBeeDevice 19 | from digi.xbee.exception import TimeoutException 20 | 21 | # TODO: Replace with the serial port where your first local module is connected to. 22 | PORT_LOCAL = "COM1" 23 | # TODO: Replace with the baud rate of your first local module. 24 | BAUD_RATE_LOCAL = 9600 25 | # TODO: Replace with the serial port where your second local module is connected to. 26 | PORT_REMOTE = "COM2" 27 | # TODO: Replace with the baud rate of your second local module. 28 | BAUD_RATE_REMOTE = 9600 29 | 30 | 31 | def main(): 32 | 33 | print(" +------------------------+") 34 | print(" | Read Data Timeout Test |") 35 | print(" +------------------------+\n") 36 | 37 | local = XBeeDevice(PORT_LOCAL, BAUD_RATE_LOCAL) 38 | local_remote = XBeeDevice(PORT_REMOTE, BAUD_RATE_REMOTE) 39 | 40 | message = None 41 | timeout_exception = None 42 | 43 | try: 44 | local.open() 45 | local_remote.open() 46 | 47 | message = local_remote.read_data() 48 | assert (message is None) 49 | 50 | remote = RemoteXBeeDevice(local, x64bit_addr=local_remote.get_64bit_addr()) 51 | local.send_data(remote, "Test message") 52 | 53 | time.sleep(1) 54 | 55 | message = local_remote.read_data() 56 | assert (message is not None) 57 | message = None 58 | message = local_remote.read_data(3) 59 | 60 | except TimeoutException as e: 61 | timeout_exception = e 62 | 63 | finally: 64 | assert (timeout_exception is not None) 65 | assert (message is None) 66 | 67 | print("Test finished successfully") 68 | 69 | if local is not None and local.is_open(): 70 | local.close() 71 | if local_remote is not None and local_remote.is_open(): 72 | local_remote.close() 73 | 74 | 75 | if __name__ == "__main__": 76 | main() 77 | -------------------------------------------------------------------------------- /functional_tests/comunication/send_data_16.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017-2019, Digi International Inc. 2 | # 3 | # This Source Code Form is subject to the terms of the Mozilla Public 4 | # License, v. 2.0. If a copy of the MPL was not distributed with this 5 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | import time 16 | 17 | from digi.xbee.devices import XBeeDevice 18 | from digi.xbee.devices import RemoteXBeeDevice 19 | 20 | # TODO: Replace with the serial port where your first local module is connected to. 21 | PORT_LOCAL = "COM1" 22 | # TODO: Replace with the baud rate of your first local module. 23 | BAUD_RATE_LOCAL = 9600 24 | # TODO: Replace with the serial port where your second local module is connected to. 25 | PORT_REMOTE = "COM2" 26 | # TODO: Replace with the baud rate of your second local module. 27 | BAUD_RATE_REMOTE = 9600 28 | 29 | 30 | def main(): 31 | 32 | print(" +-------------------+") 33 | print(" | Send Data 16 Test |") 34 | print(" +-------------------+\n") 35 | 36 | local = XBeeDevice(PORT_LOCAL, BAUD_RATE_LOCAL) 37 | local_remote = XBeeDevice(PORT_REMOTE, BAUD_RATE_REMOTE) 38 | 39 | try: 40 | local.open() 41 | local_remote.open() 42 | 43 | remote = RemoteXBeeDevice(local, x16bit_addr=local_remote.get_16bit_addr()) 44 | local.send_data(remote, "Test message") 45 | 46 | time.sleep(1) 47 | 48 | message = local_remote.read_data() 49 | assert (message is not None) 50 | assert (message.remote_device.get_16bit_addr() == local.get_16bit_addr()) 51 | 52 | print("Test finished successfully") 53 | 54 | finally: 55 | if local is not None and local.is_open(): 56 | local.close() 57 | if local_remote is not None and local_remote.is_open(): 58 | local_remote.close() 59 | 60 | 61 | if __name__ == "__main__": 62 | main() 63 | -------------------------------------------------------------------------------- /functional_tests/configuration/get_set_api_output_mode.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017, Digi International Inc. 2 | # 3 | # This Source Code Form is subject to the terms of the Mozilla Public 4 | # License, v. 2.0. If a copy of the MPL was not distributed with this 5 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | from digi.xbee.devices import XBeeDevice 16 | from digi.xbee.models.mode import APIOutputModeBit 17 | from digi.xbee.models.protocol import XBeeProtocol 18 | 19 | # TODO: Replace with the serial port where your local module is connected to. 20 | PORT = "COM1" 21 | # TODO: Replace with the baud rate of your local module. 22 | BAUD_RATE = 9600 23 | 24 | NATIVE = 0 25 | EXPLICIT = APIOutputModeBit.calculate_api_output_mode_value(XBeeProtocol.ZIGBEE, 26 | {APIOutputModeBit.EXPLICIT}) 27 | EXPLICIT_ZDO_PASSTHRU = APIOutputModeBit.calculate_api_output_mode_value( 28 | XBeeProtocol.ZIGBEE, 29 | {APIOutputModeBit.EXPLICIT, APIOutputModeBit.UNSUPPORTED_ZDO_PASSTHRU}) 30 | 31 | 32 | def main(): 33 | 34 | print(" +----------------------------------+") 35 | print(" | Get and Set API Output Mode Test |") 36 | print(" +----------------------------------+\n") 37 | 38 | device = XBeeDevice(PORT, BAUD_RATE) 39 | 40 | try: 41 | device.open() 42 | 43 | for api_output_mode in [EXPLICIT, EXPLICIT_ZDO_PASSTHRU, NATIVE]: 44 | device.set_api_output_mode_value(api_output_mode) 45 | ao_mode = device.get_api_output_mode_value() 46 | assert (ao_mode[0] == api_output_mode) 47 | 48 | print("Test finished successfully") 49 | 50 | finally: 51 | if device is not None and device.is_open(): 52 | device.close() 53 | 54 | 55 | if __name__ == '__main__': 56 | main() 57 | -------------------------------------------------------------------------------- /functional_tests/configuration/reset.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017, Digi International Inc. 2 | # 3 | # This Source Code Form is subject to the terms of the Mozilla Public 4 | # License, v. 2.0. If a copy of the MPL was not distributed with this 5 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | import time 16 | from digi.xbee.devices import XBeeDevice 17 | from digi.xbee.models.status import ModemStatus 18 | 19 | # TODO: Replace with the serial port where your local module is connected to. 20 | PORT = "COM1" 21 | # TODO: Replace with the baud rate of your local module. 22 | BAUD_RATE = 9600 23 | 24 | 25 | def main(): 26 | 27 | print(" +------------+") 28 | print(" | Reset Test |") 29 | print(" +------------+\n") 30 | 31 | device = XBeeDevice(PORT, BAUD_RATE) 32 | 33 | def modem_status_callback(status): 34 | if status == ModemStatus.COORDINATOR_STARTED: 35 | return 36 | assert (status in [ModemStatus.HARDWARE_RESET, ModemStatus.WATCHDOG_TIMER_RESET]) 37 | 38 | try: 39 | device.open() 40 | 41 | device.add_modem_status_received_callback(modem_status_callback) 42 | 43 | for i in range(10): 44 | device.reset() 45 | time.sleep(1) 46 | 47 | print("Test finished successfully") 48 | 49 | finally: 50 | device.del_modem_status_received_callback(modem_status_callback) 51 | 52 | if device is not None and device.is_open(): 53 | device.close() 54 | 55 | 56 | if __name__ == '__main__': 57 | main() 58 | -------------------------------------------------------------------------------- /functional_tests/filesystem/resources/f_1K.txt: -------------------------------------------------------------------------------- 1 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent eget lacinia lorem. Quisque eget odio eu est bibendum hendrerit at id risus. In hac habitasse platea dictumst. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Interdum et malesuada fames ac ante ipsum primis in faucibus. Nunc ultricies felis velit, sed fringilla lectus blandit non. Vivamus ultricies vitae nisl a molestie. In ligula felis, ultrices eget efficitur sed, ultricies eu tortor. Nunc efficitur aliquet justo, eu feugiat augue varius vitae. 2 | 3 | Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Praesent laoreet neque et libero elementum, et ornare sapien pharetra. Proin tortor odio, sagittis vitae bibendum nec, posuere a dolor. Curabitur viverra rutrum dui. Pellentesque pellentesque, lectus eu maximus tincidunt, lorem ligula cursus turpis, eu malesuada velit diam sed augue. Vivamus at odio eros. Phasellus lorem diam, viverra nec ipsum sed, ultrices nullam sodales. 4 | -------------------------------------------------------------------------------- /functional_tests/filesystem/resources/f_2K.txt: -------------------------------------------------------------------------------- 1 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla faucibus varius cursus. Suspendisse erat nisi, mollis gravida nisl eget, lacinia eleifend turpis. Nulla porttitor ex sed lacus gravida pulvinar. Mauris et semper sem, ut viverra nulla. Curabitur nisi sapien, feugiat ut blandit sed, scelerisque a orci. Curabitur fringilla elit id ullamcorper vestibulum. Curabitur condimentum dolor a lorem lobortis auctor. Duis eu nunc ut enim laoreet aliquam. 2 | 3 | Maecenas sodales consectetur arcu, ac pulvinar erat tincidunt eget. Aenean suscipit imperdiet neque, at tincidunt risus pellentesque vitae. Nunc euismod sodales ex, ac sollicitudin purus pulvinar vitae. Praesent ac pulvinar est, quis scelerisque purus. Vestibulum a augue nec risus dictum fermentum. Mauris fermentum leo nulla, vel dictum lorem tristique nec. Duis neque eros, lacinia ac metus ut, pellentesque scelerisque augue. In hac habitasse platea dictumst. Phasellus dignissim tortor tellus, vel elementum leo varius feugiat. Donec in tellus ultricies, efficitur dui nec, feugiat risus. 4 | 5 | Vestibulum a eleifend magna. Integer tempor sem a purus pretium, et fermentum nibh interdum. Morbi vitae dui id arcu efficitur iaculis. Cras dictum, orci at vehicula convallis, risus ex imperdiet est, a placerat nisl magna in lectus. Nullam vestibulum vitae nulla nec consectetur. Praesent vulputate gravida ipsum, eget egestas mauris condimentum ac. Praesent interdum vitae libero vel blandit. Donec at ligula dictum, dictum ante ac, pretium ex. Vivamus posuere purus lorem, quis pellentesque nunc mollis at. Donec placerat turpis sed odio convallis, a pulvinar augue sagittis. Nulla sagittis nunc massa, nec semper risus convallis sed. Curabitur auctor pellentesque faucibus. 6 | 7 | Ut efficitur diam ut urna venenatis lobortis id sed lectus. Aenean sit amet condimentum sapien. Morbi in massa ut lectus pretium vestibulum maximus non nunc. Pellentesque nec massa convallis, luctus felis at, accumsan lorem. Nam lacinia libero ut risus tincidunt placerat. Vivamus ornare varius laoreet. Nunc orci. 8 | -------------------------------------------------------------------------------- /functional_tests/io/pwm_duty_cycle.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017, Digi International Inc. 2 | # 3 | # This Source Code Form is subject to the terms of the Mozilla Public 4 | # License, v. 2.0. If a copy of the MPL was not distributed with this 5 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | from digi.xbee.devices import XBeeDevice 16 | from digi.xbee.io import IOLine, IOMode 17 | 18 | # TODO: Replace with the serial port where your local module is connected to. 19 | PORT = "COM1" 20 | # TODO: Replace with the baud rate of your local module. 21 | BAUD_RATE = 9600 22 | 23 | 24 | def main(): 25 | 26 | print(" +---------------------+") 27 | print(" | PWM Duty Cycle Test |") 28 | print(" +---------------------+\n") 29 | 30 | device = XBeeDevice(PORT, BAUD_RATE) 31 | 32 | try: 33 | device.open() 34 | 35 | device.set_io_configuration(IOLine.DIO10_PWM0, IOMode.PWM) 36 | device.set_io_configuration(IOLine.DIO11_PWM1, IOMode.PWM) 37 | 38 | device.set_pwm_duty_cycle(IOLine.DIO10_PWM0, 50) 39 | device.set_pwm_duty_cycle(IOLine.DIO11_PWM1, 100) 40 | 41 | dc1 = device.get_pwm_duty_cycle(IOLine.DIO10_PWM0) 42 | dc2 = device.get_pwm_duty_cycle(IOLine.DIO11_PWM1) 43 | 44 | assert (dc1 == 50) 45 | assert (dc2 == 100) 46 | 47 | print("Test finished successfully") 48 | 49 | finally: 50 | if device is not None and device.is_open(): 51 | device.close() 52 | 53 | 54 | if __name__ == "__main__": 55 | main() 56 | -------------------------------------------------------------------------------- /functional_tests/io/read_io_sample.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017-2019, Digi International Inc. 2 | # 3 | # This Source Code Form is subject to the terms of the Mozilla Public 4 | # License, v. 2.0. If a copy of the MPL was not distributed with this 5 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | from digi.xbee.models.address import XBee64BitAddress 16 | from digi.xbee.devices import XBeeDevice, RemoteXBeeDevice 17 | from digi.xbee.io import IOLine, IOMode 18 | 19 | # TODO: Replace with the serial port where your local module is connected to. 20 | PORT = "COM1" 21 | # TODO: Replace with the baud rate of your local module. 22 | BAUD_RATE = 9600 23 | # TODO: Replace with the 64-bit address of the remote device. 24 | REMOTE_DEVICE_ADDRESS = XBee64BitAddress.from_hex_string("0013A20040D47B73") 25 | 26 | 27 | def main(): 28 | 29 | print(" +---------------------+") 30 | print(" | Read IO Sample Test |") 31 | print(" +---------------------+\n") 32 | 33 | device = XBeeDevice(PORT, BAUD_RATE) 34 | 35 | try: 36 | device.open() 37 | 38 | device.set_io_configuration(IOLine.DIO1_AD1, IOMode.DIGITAL_IN) 39 | 40 | sample = device.read_io_sample() 41 | assert (sample.has_digital_value(IOLine.DIO1_AD1)) 42 | 43 | remote = RemoteXBeeDevice(device, x64bit_addr=REMOTE_DEVICE_ADDRESS) 44 | 45 | remote.set_io_configuration(IOLine.DIO1_AD1, IOMode.DIGITAL_IN) 46 | sample = remote.read_io_sample() 47 | assert (sample.has_digital_value(IOLine.DIO1_AD1)) 48 | 49 | print("Test finished successfully") 50 | 51 | finally: 52 | if device is not None and device.is_open(): 53 | device.close() 54 | 55 | 56 | if __name__ == "__main__": 57 | main() 58 | -------------------------------------------------------------------------------- /functional_tests/network/discover_network.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017, Digi International Inc. 2 | # 3 | # This Source Code Form is subject to the terms of the Mozilla Public 4 | # License, v. 2.0. If a copy of the MPL was not distributed with this 5 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. 6 | # 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | import time 16 | 17 | from digi.xbee.devices import XBeeDevice 18 | 19 | 20 | # TODO: Replace with the serial port where your local module is connected to. 21 | PORT = "COM1" 22 | # TODO: Replace with the baud rate of your local module. 23 | BAUD_RATE = 9600 24 | 25 | 26 | def main(): 27 | 28 | print(" +-----------------------+") 29 | print(" | Discover Network Test |") 30 | print(" +-----------------------+\n") 31 | 32 | device = XBeeDevice(PORT, BAUD_RATE) 33 | 34 | def device_discovered_callback(remote): 35 | devices_callback.append(remote) 36 | 37 | try: 38 | device.open() 39 | 40 | network = device.get_network() 41 | 42 | devices_callback = [] 43 | 44 | network.add_device_discovered_callback(device_discovered_callback) 45 | 46 | network.start_discovery_process() 47 | 48 | while network.is_discovery_running(): 49 | time.sleep(0.1) 50 | 51 | assert(devices_callback == network.get_devices()) 52 | 53 | print("Test finished successfully") 54 | 55 | finally: 56 | network.del_device_discovered_callback(device_discovered_callback) 57 | 58 | if device is not None and device.is_open(): 59 | device.close() 60 | 61 | 62 | if __name__ == "__main__": 63 | main() 64 | -------------------------------------------------------------------------------- /functional_tests/test.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | from digi.xbee.devices import XBeeDevice 4 | 5 | 6 | def main(): 7 | 8 | device = XBeeDevice("COM6", 9600) 9 | device.open() 10 | print(device.get_parameter("NI").decode()) 11 | device.close() 12 | device.open() 13 | print(device.get_parameter("NI").decode()) 14 | device.close() 15 | device.open() 16 | print(device.get_parameter("NI").decode()) 17 | device.close() 18 | device.open() 19 | print(device.get_parameter("NI").decode()) 20 | device.close() 21 | device.open() 22 | print(device.get_parameter("NI").decode()) 23 | device.close() 24 | 25 | 26 | if __name__ == '__main__': 27 | main() 28 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | pyserial>=3 2 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | [tox] 2 | envlist = py34 3 | --------------------------------------------------------------------------------