Beispiel #1
0
    async def periodically_activate_ibeacon_index(
            self,
            crownstone_uid_array: List[int],
            index: int,
            interval_seconds: int,
            offset_seconds: int = 0) -> MeshResult:
        """
        You need to have 2 stored ibeacon payloads (state index 0 and 1) in order for this to work. This can be done by the set_ibeacon methods
        available in this class.

        Once the interval starts, it will set this ibeacon ID to be active. In order to have 2 ibeacon payloads interleaving, you have to call this method twice.
        To interleave every minute
        First,    periodically_activate_ibeacon_index, index 0, interval = 120 (2 minutes), offset = 0
        Secondly, periodically_activate_ibeacon_index, index 1, interval = 120 (2 minutes), offset = 60

        This will change the active ibeacon payload every minute:
        T        = 0.............60.............120.............180.............240
        activeId = 0.............1...............0...............1...............0
        period_0 = |------------120s-------------|--------------120s-------------|
        :param crownstone_uid_array:
        :param index:
        :param interval_seconds:
        :param offset_seconds:
        :return:
        """

        ibeaconConfigPacket = ControlPacketsGenerator.getIBeaconConfigIdPacket(
            index, offset_seconds, interval_seconds)
        return await self._command_via_mesh_broadcast_acked(
            crownstone_uid_array, ibeaconConfigPacket)
Beispiel #2
0
    async def stop_ibeacon_interval_and_set_index(
            self, crownstone_uid_array: List[int], index) -> MeshResult:
        """
        This method stops the interleaving for the specified ibeacon payload at that index.
        :param crownstone_uid_array:
        :param index:
        :return:
        """
        indexToEndWith = index
        indexToStartWith = 0
        if index == 0:
            indexToStartWith = 1

        ibeaconConfigPacketStart = ControlPacketsGenerator.getIBeaconConfigIdPacket(
            indexToStartWith, 0, 0)
        ibeaconConfigPacketFinish = ControlPacketsGenerator.getIBeaconConfigIdPacket(
            indexToEndWith, 0, 0)

        meshResult = MeshResult(crownstone_uid_array)

        initialResult = await self._command_via_mesh_broadcast_acked(
            crownstone_uid_array, ibeaconConfigPacketStart)

        meshResult.merge(initialResult)
        successfulIds = meshResult.get_successful_ids()
        if len(successfulIds) == 0:
            return meshResult

        secondResult = await self._command_via_mesh_broadcast_acked(
            successfulIds, ibeaconConfigPacketFinish)

        # if we succeeded in the initial phase, we should be able to finish the second case.
        failed_second_part = meshResult.compare_get_failed(secondResult)
        iterations = 0
        while len(failed_second_part) > 0 and iterations < 5:
            secondResult = await self._command_via_mesh_broadcast_acked(
                failed_second_part, ibeaconConfigPacketFinish)
            failed_second_part = meshResult.compare_get_failed(secondResult)
            iterations += 1

        meshResult.merge(secondResult)
        meshResult.conclude()

        return meshResult