Exemple #1
0
    def addAppKeys(self, uuid, groupAddrId=0):
        """ Used to:
            - subscribes the serial device to the group address
            - add publication address of each element to the serial device
            - bind app_key to each model on each element
            - set the client to publish to the group address
        
        Parameters
        ----------
            node : index of node in db
            groupAddrId : index of group address in db

        """
        node = self.uuid_to_node_index(uuid)
        command = cmd.AddrSubscriptionAdd(self.db.groups[groupAddrId].address)
        self.message_que.append(functools.partial(self.iaci.send, command))

        for e, element in enumerate(self.db.nodes[node].elements):

            # Add each element to the serial device's pubusb list
            element_address = self.db.nodes[node].unicast_address + e
            command = cmd.AddrPublicationAdd(element_address)
            self.message_que.append(functools.partial(self.iaci.send, command))

            for model in element.models:

                # Generic OnOff Server
                if str(model.model_id) == "1000":
                    self.message_que.append(
                        functools.partial(self.cc.model_app_bind,
                                          element_address, 0,
                                          mt.ModelId(0x1000)))

                # Generic OnOff Client
                if str(model.model_id) == "1001":
                    self.message_que.append(
                        functools.partial(self.cc.model_app_bind,
                                          element_address, 0,
                                          mt.ModelId(0x1001)))
                    self.message_que.append(
                        functools.partial(
                            self.cc.model_publication_set, element_address,
                            mt.ModelId(0x1001),
                            mt.Publish(self.db.groups[groupAddrId].address,
                                       index=0,
                                       ttl=1)))

                # Simple OnOff Server
                if str(model.model_id) == "00590000":
                    self.message_que.append(
                        functools.partial(
                            self.cc.model_app_bind, element_address, 0,
                            mt.ModelId(0x0000, company_id=0x0059)))

        self.message_que.append(
            functools.partial(self.addAppKeysComplete, uuid))

        self.send_next_message()
Exemple #2
0
    def _get_handles(self, node):
        self.device.send(
            cmd.DevkeyAdd(node.unicast_address, 0, node.device_key))
        self.device.send(cmd.AddrPublicationAdd(node.unicast_address))

        address_handle = self.address_queue.get()
        devkey_handle = self.devkey_queue.get()

        print('Got handle for node:', node.unicast_address, 'devkey_handle:',
              devkey_handle, 'address_handle:', address_handle)

        return (devkey_handle, address_handle)
Exemple #3
0
def connect_to_existing_mesh():
    print("**Connect to an existing mesh network!")
    time.sleep(2)

    device.send(
        cmd.DevkeyAdd(db.nodes[0].unicast_address, 0, db.nodes[0].device_key))
    device.send(cmd.AddrPublicationAdd(db.nodes[0].unicast_address))
    time.sleep(1)

    cc = interactive_pyaci.ConfigurationClient(db)
    device.model_add(cc)
    cc.publish_set(8, 0)
    cc.composition_data_get()
Exemple #4
0
    def __event_handler(self, event):
        if event._opcode == Event.PROV_UNPROVISIONED_RECEIVED:
            uuid = event._data["uuid"]
            rssi = event._data["rssi"]
            if uuid not in self.unprov_list:
                self.logger.info("Received UUID {} with RSSI: {} dB".format(
                    uuid.hex(), rssi))
                self.unprov_list.append(uuid)

        elif event._opcode == Event.PROV_CAPS_RECEIVED:
            element_count = event._data["num_elements"]
            self.logger.info("Received capabilities")
            self.logger.info("Number of elements: {}".format(element_count))

            self.iaci.send(
                cmd.OobUse(event._data["context_id"], OOBMethod.NONE, 0, 0))
            self.__session_data["elements"] = [
                mt.Element(i) for i in range(element_count)
            ]

        elif event._opcode == Event.PROV_COMPLETE:
            num_elements = len(self.__session_data["elements"])
            address_range = "{}-{}".format(
                hex(event._data["address"]),
                hex(event._data["address"] + num_elements - 1))

            self.logger.info("Provisioning complete")
            self.logger.info("\tAddress(es): " + address_range)
            self.logger.info("\tDevice key: {}".format(
                event._data["device_key"].hex()))
            self.logger.info("\tNetwork key: {}".format(
                event._data["net_key"].hex()))
            self.logger.info("Adding device key to subnet %d",
                             event._data["net_key_index"])
            # Devkey added to subnet 0.
            self.iaci.send(
                cmd.DevkeyAdd(event._data["address"], 0,
                              event._data["device_key"]))

            self.logger.info("Adding publication address of root element")
            self.iaci.send(cmd.AddrPublicationAdd(event._data["address"]))

            self.__session_data["device_key"] = event._data["device_key"]
            self.store(self.__session_data)

            # Update address to the next in range
            self.__next_free_address += num_elements

        else:
            self.default_handler(event)
Exemple #5
0
    def __event_handler(self, event):
        if event._opcode == Event.PROV_UNPROVISIONED_RECEIVED:
            if event._data not in self.__unprov_list:
                uuid_fmt = str(hexlify(event._data["uuid"]), 'ascii').upper()
                self.logger.info("Received UUID {} with RSSI: -{} dB".format(
                    uuid_fmt, event._data["rssi"]))
                self.__unprov_list.add(event._data)

        elif event._opcode == Event.PROV_CAPS_RECEIVED:
            self.logger.info("Received capabilities")
            self.logger.info("Number of elements: {}".format(
                str(event._data["num_elements"])))
            self.__caps[event._data["context_id"]] = event._data
            self.iaci.send(
                cmd.OobUse(event._data["context_id"], OOBMethod.NONE, 0))

        elif event._opcode == Event.PROV_COMPLETE:
            caps = self.__caps[event._data["context_id"]]
            num_elements = caps["num_elements"]
            address_range = "{}-{}".format(
                hex(event._data["address"]),
                hex(event._data["address"] + num_elements - 1))
            self.logger.info("Provisioning complete")
            self.logger.info("\tAddress(es): " + address_range)
            self.logger.info("\tDevice key: {}".format(
                str(hexlify(event._data["device_key"]), "ascii").upper()))
            self.logger.info("\tNetwork key: {}".format(
                str(hexlify(event._data["net_key"]), "ascii").upper()))

            self.logger.info("Adding device key to subnet 0")
            # Devkey added to subnet 0.
            self.iaci.send(
                cmd.DevkeyAdd(event._data["address"], 0,
                              event._data["device_key"]))

            self.logger.info("Adding publication address(es)")
            for i in range(0, num_elements):
                self.iaci.send(
                    cmd.AddrPublicationAdd(event._data["address"] + i))
            # Update address to the next in range
            self.__prov_data["address"] += num_elements

        else:
            self.default_handler(event)
Exemple #6
0
    def load_address_handles(self):
        address_handles = self.db.address_handles.copy()
        self.db.address_handles = []
        self.db.store()

        for item in address_handles:

            address = item["address"]
            opcode = item["opcode"]

            if RESPONSE_LUT[opcode]["name"] == "AddrSubscriptionAdd":
                command = cmd.AddrSubscriptionAdd(address)
            if RESPONSE_LUT[opcode]["name"] == "AddrSubscriptionAddVirtual":
                command = cmd.AddrSubscriptionAddVirtual(address)
            if RESPONSE_LUT[opcode]["name"] == "AddrPublicationAdd":
                command = cmd.AddrPublicationAdd(address)
            if RESPONSE_LUT[opcode]["name"] == "AddrPublicationAddVirtual":
                command = cmd.AddrPublicationAddVirtual(address)

            self.message_que.append(functools.partial(self.iaci.send, command))