@@ -630,3 +630,152 @@ with the following methods:
630630+-------------+---------------------------+
631631| DNS address | **set_dns_address() ** |
632632+-------------+---------------------------+
633+
634+
635+ .. _configBluetooth :
636+
637+ Configure Bluetooth settings
638+ ----------------------------
639+
640+ Newer XBee3 devices have a Bluetooth® Low Energy (BLE) interface that enables
641+ you to connect your XBee device to another device such as a cellphone. The XBee
642+ device classes (local and remote) offer some methods that allow you to:
643+
644+ * :ref: `_configBluetoothEnableDisable `
645+ * :ref: `_configBluetoothConfigurePassword `
646+ * :ref: `_configBluetoothReadMacAddress `
647+
648+
649+ .. _configBluetoothEnableDisable :
650+
651+ Enable and disable Bluetooth
652+ ````````````````````````````
653+
654+ Before connecting to your XBee device over Bluetooth Low Energy, you first have
655+ to enable this interface. The XBee Python Library provides a couple of methods
656+ to enable or disable this interface:
657+
658+ +-------------------------+------------------------------------------------------------------+
659+ | Method | Description |
660+ +=========================+==================================================================+
661+ | **enable_bluetooth() ** | Enables the Bluetooth Low Energy interface of your XBee device. |
662+ +-------------------------+------------------------------------------------------------------+
663+ | **disable_bluetooth() ** | Disables the Bluetooth Low Energy interface of your XBee device. |
664+ +-------------------------+------------------------------------------------------------------+
665+
666+ **Enabling and disabling the Bluetooth interface **
667+
668+ .. code :: python
669+
670+ [... ]
671+
672+ # Instantiate an XBee device object.
673+ local_xbee = XBeeDevice(" COM1" , 9600 )
674+ local_xbee.open()
675+
676+ # Enable the Bluetooth interface.
677+ local_xbee.enable_bluetooth()
678+
679+ [... ]
680+
681+ # Disable the Bluetooth interface.
682+ local_xbee.disable_bluetooth()
683+
684+ [... ]
685+
686+ These methods may fail for the following reasons:
687+
688+ * ACK of the command sent is not received in the configured timeout, throwing
689+ a ``TimeoutException ``.
690+ * Other errors caught as ``XBeeException ``:
691+ * The operating mode of the device is not ``API_MODE `` or
692+ ``ESCAPED_API_MODE ``, throwing an ``InvalidOperatingModeException ``.
693+ * The response of the command is not valid, throwing an
694+ ``ATCommandException ``.
695+ * There is an error writing to the XBee interface, throwing a generic
696+ ``XBeeException ``.
697+
698+
699+ .. _configBluetoothConfigurePassword :
700+
701+ Configure the Bluetooth password
702+ ````````````````````````````````
703+
704+ Once you have enabled the Bluetooth Low Energy, you must configure the password
705+ you will use to connect to the device over that interface (if not previously
706+ done). For this purpose, the API offers the following method:
707+
708+ +----------------------------------------+-----------------------------------------------------------+
709+ | Method | Description |
710+ +========================================+===========================================================+
711+ | **update_bluetooth_password(String) ** | Specifies the new Bluetooth password of the XBee device. |
712+ +----------------------------------------+-----------------------------------------------------------+
713+
714+ **Configuring or changing the Bluetooth password **
715+
716+ .. code :: python
717+
718+ [... ]
719+
720+ # Instantiate an XBee device object.
721+ local_xbee = XBeeDevice(" COM1" , 9600 )
722+ local_xbee.open()
723+
724+ new_password = " myBluetoothPassword" # Do not hard-code it in the app!
725+
726+ # Configure the Bluetooth password.
727+ local_xbee.update_bluetooth_password(new_password)
728+
729+ [... ]
730+
731+ The ``update_bluetooth_password `` method may fail for the following reasons:
732+
733+ * ACK of the command sent is not received in the configured timeout, throwing
734+ a ``TimeoutException ``.
735+ * Other errors caught as ``XBeeException ``:
736+ * The operating mode of the device is not ``API_MODE `` or
737+ ``ESCAPED_API_MODE ``, throwing an ``InvalidOperatingModeException ``.
738+ * The response of the command is not valid, throwing an
739+ ``ATCommandException ``.
740+ * There is an error writing to the XBee interface, throwing a generic
741+ ``XBeeException ``.
742+
743+ .. warning ::
744+ Never hard-code the Bluetooth password in the code, a malicious person could
745+ decompile the application and find it out.
746+
747+
748+ .. _configBluetoothReadMacAddress :
749+
750+ Read the Bluetooth MAC address
751+ ``````````````````````````````
752+
753+ Another method that the XBee Java Library provides is
754+ ``get_bluetooth_mac_addr() ``, which returns the EUI-48 Bluetooth MAC address of
755+ your XBee device in a format such as "00112233AABB".
756+
757+ **Reading the Bluetooth MAC address **
758+
759+ .. code :: python
760+
761+ [... ]
762+
763+ # Instantiate an XBee device object.
764+ local_xbee = XBeeDevice(" COM1" , 9600 )
765+ local_xbee.open()
766+
767+ print (" The Bluetooth MAC address is: %s " % local_xbee.get_bluetooth_mac_addr())
768+
769+ [... ]
770+
771+ The ``get_bluetooth_mac_addr `` method may fail for the following reasons:
772+
773+ * ACK of the command sent is not received in the configured timeout, throwing
774+ a ``TimeoutException ``.
775+ * Other errors caught as ``XBeeException ``:
776+ * The operating mode of the device is not ``API_MODE `` or
777+ ``ESCAPED_API_MODE ``, throwing an ``InvalidOperatingModeException ``.
778+ * The response of the command is not valid, throwing an
779+ ``ATCommandException ``.
780+ * There is an error writing to the XBee interface, throwing a generic
781+ ``XBeeException ``.
0 commit comments