def __str__(self): return "ID: 0x%s\n" \ "State: %s\n" \ "Protocol: %s\n" \ "Local port: 0x%s\n" \ "Remote port: 0x%s\n" \ "Remote address: %s"\ % (utils.hex_to_string(utils.int_to_bytes(self.__socket_id, num_bytes=1), False), self.__state.description, self.__protocol.description, utils.hex_to_string(utils.int_to_bytes(self.__local_port, num_bytes=2), False), utils.hex_to_string(utils.int_to_bytes(self.__remote_port, num_bytes=2), False), self.__remote_addr)
def _get_api_packet_spec_data(self): """ Override method. .. seealso:: | :meth:`.XBeeAPIPacket._get_api_packet_spec_data` """ ret = utils.int_to_bytes(self.__request_id, num_bytes=1) ret += utils.int_to_bytes(0x00, num_bytes=1) if self.__response_data is not None: ret += self.__response_data return ret
def _get_api_packet_spec_data(self): """ Override method. .. seealso:: | :meth:`.XBeeAPIPacket._get_api_packet_spec_data` """ ret = bytearray(self.__src_addr.packed) ret += utils.int_to_bytes(self.__rssi, num_bytes=1) ret += utils.int_to_bytes(self.__rx_opts, num_bytes=1) if self.__data is not None: ret += self.__data return ret
def instantiate_zigbee_network(): try: print("Opening xbee port") xbee.open() print("Setting Power Level") xbee.set_parameter('PL', utils.int_to_bytes(power_level, num_bytes=1)) print("Setting API Mode") xbee.set_parameter('AP', utils.int_to_bytes(api_mode, num_bytes=1)) xbee.set_io_configuration(IOLine.DIO4_AD4, IOMode.DISABLED) print("Getting self id") global node_id node_id = xbee.get_node_id() global address address = str(xbee.get_64bit_addr()) print("This Node ID: ", node_id) print("Is Remote: ", xbee.is_remote()) print("Power Level: ", xbee.get_power_level()) print("Entering discovery mode...\n") xnet = xbee.get_network() xnet.set_discovery_timeout(15) xnet.clear() xnet.add_device_discovered_callback(xlib.discoverCallback) xnet.add_discovery_process_finished_callback(xlib.discoverCompleteCallback) global start_net start_net = time.time() xnet.start_discovery_process() while xnet.is_discovery_running(): time.sleep(0.5) global nodes nodes = xnet.get_devices() data = 'Zigbee node %s sending data' % (xbee.get_node_id()) return 1 except ConnectionException: print('Error Connection') xbee.close() return 0 except ATCommandException: print('Response of the command is not valid : ATCommandException') xbee.close() return 0 except InvalidOperatingModeException: print('Not in API Mode') xbee.close() return 0
def _get_api_packet_spec_data(self): """ Override method. .. seealso:: | :meth:`.XBeeAPIPacket._get_API_packet_spec_data` """ ret = bytearray(self.__src_addr.packed) ret += utils.int_to_bytes(self.__dest_port, num_bytes=2) ret += utils.int_to_bytes(self.__src_port, num_bytes=2) ret += utils.int_to_bytes(self.__ip_prot.code, num_bytes=1) ret += utils.int_to_bytes(self.__status, num_bytes=1) if self.__data is not None: ret += self.__data return ret
def _get_api_packet_spec_data(self): """ Override method. .. seealso:: | :meth:`.XBeeAPIPacket._get_API_packet_spec_data` """ ret = bytearray(self.__dest_address.packed) ret += utils.int_to_bytes(self.__dest_port, num_bytes=2) ret += utils.int_to_bytes(self.__source_port, num_bytes=2) ret += utils.int_to_bytes(self.__ip_protocol.code) ret += utils.int_to_bytes(self.__transmit_options) if self.__data is not None: ret += self.__data return ret
def _get_api_packet_spec_data(self): """ Override method. .. seealso:: | :meth:`.XBeeAPIPacket._get_api_packet_spec_data` """ return utils.int_to_bytes(self.__transmit_status.code, 1)
def _get_api_packet_spec_data(self): """ Override method. .. seealso:: | :meth:`.XBeeAPIPacket._get_api_packet_spec_data` """ return utils.int_to_bytes(self.__frame_error.code, num_bytes=1)
def _get_api_packet_spec_data(self): """ Override method. .. seealso:: | :meth:`.XBeeAPIPacket._get_api_packet_spec_data` """ ret = utils.int_to_bytes(self.__request_id, num_bytes=1) ret += utils.int_to_bytes(self.__transport, num_bytes=1) ret += utils.int_to_bytes(self.__flags, num_bytes=1) if self.__target is not None: ret += utils.int_to_bytes(len(self.__target), num_bytes=1) ret += bytearray(self.__target, "utf8") else: ret += utils.int_to_bytes(0x00, num_bytes=1) if self.__request_data is not None: ret += self.__request_data return ret
def _get_api_packet_spec_data(self): """ Override method. .. seealso:: | :meth:`.XBeeAPIPacket._get_API_packet_spec_data` """ ret = utils.int_to_bytes(self.__transmit_options, num_bytes=1) ret += self.__phone_number if self.__data is not None: ret += self.__data.encode("utf8") return ret
def _get_api_packet_spec_data(self): """ Override method. .. seealso:: | :meth:`.XBeeAPIPacket._get_api_packet_spec_data` """ ret = bytearray(self.__src_addr.packed) ret += bytearray(self.__cmd, "utf8") ret += utils.int_to_bytes(self.__resp_status.code, num_bytes=1) if self.__comm_val is not None: ret += self.__comm_val return ret
def _get_api_packet_spec_data(self): """ Override method. .. seealso:: | :meth:`.XBeeAPIPacket._get_api_packet_spec_data` """ ret = bytearray(self.__dest_addr.packed) ret += utils.int_to_bytes(self.__tx_opts, num_bytes=1) ret += bytearray(self.__cmd, "utf8") if self.__param is not None: ret += self.__param return ret
def _get_api_packet_spec_data(self): """ Override method. .. seealso:: | :meth:`.XBeeAPIPacket._get_api_packet_spec_data` """ ret = bytearray(self.__dest_address.packed) ret += utils.int_to_bytes(self.__transmit_options, num_bytes=1) ret += bytearray(self.__command, "utf8") if self.__parameter is not None: ret += self.__parameter return ret
def _get_api_packet_spec_data(self): """ Override method. .. seealso:: | :meth:`.XBeeAPIPacket._get_api_packet_spec_data` """ ret = bytearray([self.__src_event]) ret.append(self.length) ret += utils.int_to_bytes(self.__timestamp, num_bytes=4) ret.append(self.__ack_timeout_count) ret.append(self.__tx_block_count) ret.append(self._reserved) ret += self.__dst_addr.address ret += self.__src_addr.address ret += self.__responder_addr.address ret += self.__successor_addr.address if self.__additional_data: ret += self.__additional_data return ret
def _get_api_packet_spec_data(self): """ Override method. .. seealso:: | :meth:`.XBeeAPIPacket._get_api_packet_spec_data` """ if self.__path is not None: ret = utils.int_to_bytes(len(self.__path), num_bytes=1) ret += bytearray(self.__path, "utf8") else: ret = utils.int_to_bytes(0x00, num_bytes=1) if self.__content_type is not None: ret += utils.int_to_bytes(len(self.__content_type), num_bytes=1) ret += bytearray(self.__content_type, "utf8") else: ret += utils.int_to_bytes(0x00, num_bytes=1) ret += utils.int_to_bytes(0x00, num_bytes=1) # Transport is always TCP ret += utils.int_to_bytes(self.__options.code, num_bytes=1) if self.__file_data is not None: ret += self.__file_data return ret
dest_address = XBee64BitAddress.from_hex_string("000000000000FFFF") device.set_dest_address(dest_address) device.set_pan_id(bytearray.fromhex(opts.pan_id)) #cmd = 'AP2,' device.set_parameter("AP", bytearray.fromhex("02")) if (opts.coordinator): device.set_parameter("CE", bytearray.fromhex("01")) else: device.set_parameter("CE", bytearray.fromhex("00")) #cmd += 'CE1,' #API mode 2, and enable coordinator device.set_parameter("MY", utils.int_to_bytes(my_address)) device.set_parameter("NI", bytearray(opts.name, 'utf8')) device.set_parameter("BD", utils.int_to_bytes(baud_lookup[57600])) device.set_parameter("CH", bytearray.fromhex(opts.channel)) device.set_parameter("RN", bytearray.fromhex("01")) device.set_parameter("RO", bytearray.fromhex("05")) device.apply_changes() device.write_changes() device.reset() device.close() # cmd += 'MY%d,'%int(args[1]) #set the xbee address # cmd += 'BD%d,'%baud_lookup[57600] #set the xbee to interface at 57600 baud # cmd += 'ID%d,'%opts.pan_id # cmd += 'CH%s,'%opts.channel
def modem_status_receive_callback(modem_status): print("Modem Status event received: %s: %s" % (utils.hex_to_string(utils.int_to_bytes(modem_status.code, 1)), modem_status.description))