def __prepare_device(self): """ Performs the local XBee configuration before sending the ZDO command. This saves the current AO value and sets it to 1. """ if not self.__configure_ao: return if not self._xbee.is_remote(): xb = self._xbee else: xb = self._xbee.get_local_xbee_device() try: self.__saved_ao = xb.get_api_output_mode_value() # Do not configure AO if it is already if utils.is_bit_enabled(self.__saved_ao[0], 0): self.__saved_ao = None return value = APIOutputModeBit.calculate_api_output_mode_value(self._xbee.get_protocol(), {APIOutputModeBit.EXPLICIT}) xb.set_api_output_mode_value(value) except XBeeException as e: raise XBeeException("Could not prepare XBee for ZDO: " + str(e))
def main(): print(" +--------------------------------------------------+") print(" | XBee Python Library Receive Explicit Data Sample |") print(" +--------------------------------------------------+\n") device = ZigBeeDevice(PORT, BAUD_RATE) try: device.open() device.set_api_output_mode_value( APIOutputModeBit.calculate_api_output_mode_value( device.get_protocol(), {APIOutputModeBit.EXPLICIT})) def explicit_data_callback(explicit_xbee_message): print("From %s >> %s" % (explicit_xbee_message.remote_device.get_64bit_addr(), explicit_xbee_message.data.decode())) print(" - Source endpoint: %s" % utils.hex_to_string(utils.int_to_length(explicit_xbee_message.source_endpoint))) print(" - Destination endpoint: %s" % utils.hex_to_string(utils.int_to_length(explicit_xbee_message.dest_endpoint))) print(" - Cluster ID: %s" % utils.hex_to_string(utils.int_to_length(explicit_xbee_message.cluster_id))) print(" - Profile ID: %s" % utils.hex_to_string(utils.int_to_length(explicit_xbee_message.profile_id))) device.flush_queues() device.add_expl_data_received_callback(explicit_data_callback) print("Waiting for data in explicit format...\n") input() finally: if device is not None and device.is_open(): device.close()
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. from digi.xbee.devices import XBeeDevice from digi.xbee.models.mode import APIOutputModeBit from digi.xbee.models.protocol import XBeeProtocol # TODO: Replace with the serial port where your local module is connected to. PORT = "COM1" # TODO: Replace with the baud rate of your local module. BAUD_RATE = 9600 NATIVE = 0 EXPLICIT = APIOutputModeBit.calculate_api_output_mode_value( XBeeProtocol.ZIGBEE, {APIOutputModeBit.EXPLICIT}) EXPLICIT_ZDO_PASSTHRU = APIOutputModeBit.calculate_api_output_mode_value( XBeeProtocol.ZIGBEE, {APIOutputModeBit.EXPLICIT, APIOutputModeBit.UNSUPPORTED_ZDO_PASSTHRU}) def main(): print(" +----------------------------------+") print(" | Get and Set API Output Mode Test |") print(" +----------------------------------+\n") device = XBeeDevice(PORT, BAUD_RATE) try: device.open()