Esempio n. 1
0
    async def _writeFastSetupV2(self, sphereId, crownstoneId, meshDeviceKey,
                                ibeaconUUID, ibeaconMajor, ibeaconMinor):
        packet = ControlPacketsGenerator.getSetupPacket(
            crownstoneId, sphereId, self.core.settings.adminKey,
            self.core.settings.memberKey, self.core.settings.basicKey,
            self.core.settings.serviceDataKey,
            self.core.settings.localizationKey, meshDeviceKey,
            self.core.settings.meshApplicationKey,
            self.core.settings.meshNetworkKey, ibeaconUUID, ibeaconMajor,
            ibeaconMinor)

        _LOGGER.info("Writing setup data to Crownstone...")
        await self.core.ble.writeToCharacteristic(
            CSServices.SetupService, SetupCharacteristics.SetupControl, packet)
Esempio n. 2
0
def setup() -> bool:
    logging.log(logging.INFO, "Perform setup")
    try:
        controlPacket = ControlPacketsGenerator.getSetupPacket(
            crownstoneId=crownstoneId,
            sphereId=sphereId,
            adminKey=Conversion.ascii_or_hex_string_to_16_byte_array(adminKey),
            memberKey=Conversion.ascii_or_hex_string_to_16_byte_array(
                memberKey),
            basicKey=Conversion.ascii_or_hex_string_to_16_byte_array(basicKey),
            serviceDataKey=Conversion.ascii_or_hex_string_to_16_byte_array(
                serviceDataKey),
            localizationKey=Conversion.ascii_or_hex_string_to_16_byte_array(
                localizationKey),
            meshDeviceKey=Conversion.ascii_or_hex_string_to_16_byte_array(
                meshDeviceKey),
            meshAppKey=Conversion.ascii_or_hex_string_to_16_byte_array(
                meshAppKey),
            meshNetworkKey=Conversion.ascii_or_hex_string_to_16_byte_array(
                meshNetworkKey),
            ibeaconUUID=ibeaconUUID,
            ibeaconMajor=ibeaconMajor,
            ibeaconMinor=ibeaconMinor)
        uartMessage = UartMessagePacket(UartTxType.CONTROL,
                                        controlPacket).getPacket()
        uartPacket = UartWrapperPacket(UartMessageType.UART_MESSAGE,
                                       uartMessage).getPacket()
        result = UartWriter(uartPacket).write_with_result_sync(
            [ResultValue.SUCCESS, ResultValue.WAIT_FOR_SUCCESS])
        if result.resultCode is ResultValue.SUCCESS:
            return True
        if result.resultCode is ResultValue.WAIT_FOR_SUCCESS:
            # Actually we should wait for the next result code..
            time.sleep(3.0)
            return True
        logging.log(logging.WARN, f"Setup failed, result={result}")
        return False

    except CrownstoneException as e:
        logging.log(logging.WARN, f"Failed to setup: {e}")
        return False