Package: crownstone-sdk
Python SDKThe Python SDK bundles a couple of tools based on the Python libs:https://github.com/crownstone/crownstone-lib-python-blehttps://github.com/crownstone/crownstone-lib-python-corehttps://github.com/crownstone/crownstone-lib-python-uartIf you are interested instead of creating your own tools using the above libraries, you are kindly referred to those
repositories themselves.Installation from PyPiYou can install these tools through pip:pip install crownstone-sdkInstallation from sourceYou can install these tools through pip also locally by:git clone https://github.com/crownstone/crownstone-python-sdk
cd crownstone-python-sdk
pip install .Tool argumentsThese tools are meant to be used as quick-access to common functionality. They are standalone binaries that work as is.
Again, for examples on how to use the libraries, go to the above repositories.The tool configuration can be done through files in this repository and name them exactly like this:tool_config.jsonYou can find a template of this in thetools/configfolder. Fill it with your settings in order for all tools to work.key_file.jsonYou can choose to use akey_file.jsonin a different location on your computer if you don't want to put keys in a repository (even thoughtool_config.jsonis in .gitignore). You can configure yourtool_configto do this.It is also possible to use command line arguments which will override the values in any file:--help                   show this help message and exit
  --bleAdapterAddress [I]  bleAdapterAddress of the BLE chip you want to use (linux only). This is usually a mac address.
  --keyFile KEYFILE        the json file with key information
  --configFile CONFIGFILE  the json file with config informationTool configThis is the tool config format. It is shown inconfig/tool_config.template.json.Obtaining keysGo tomy.crownstoneand copy the access token to your clipboard.
Click of theCrownstone REST API explorer, and set your access tokes.
Now you are able to make calls to the API.To get your sphere keys go to theusers/metab, click thetry it outbutton, and copy your ID from the response body.
With this ID you can access your keys on the/users/{id}/keysV2tab. Fill your ID into the form and the response body should display the keys and key types. These have to be formatted like shown bellow.{
  "absolutePathToKeyFile": null,
  "keys": {
    "admin":              "adminKeyForCrown",
    "member":             "memberKeyForHome",
    "basic":              "basicKeyForOther",
    "serviceDataKey":     "MyServiceDataKey",
    "localizationKey":    "aLocalizationKey",
    "meshApplicationKey": "MyGoodMeshAppKey",
    "meshNetworkKey":     "MyGoodMeshNetKey"
  },
  "bleAdapterAddress": null
}absolutePathToKeyFileIf this is defined, the keys are ignored. The tool will look for a key_file at that path instead.keysThese are the keys that belong to your sphere. They are used to decrypt the advertisements and to encrypt the communication during connections.bleAdapterAddressThe bleAdapterAddress of the BLE chip you want the library to use.Key fileThis is the format of thekey_file.json. You can use it via the absolutePathToKeyFile config or via the keyFile command line argument.{
  "admin":              "adminKeyForCrown",
  "member":             "memberKeyForHome",
  "basic":              "basicKeyForOther",
  "serviceDataKey":     "MyServiceDataKey",
  "localizationKey":    "aLocalizationKey",
  "meshApplicationKey": "MyGoodMeshAppKey",
  "meshNetworkKey":     "MyGoodMeshNetKey"
}commandLine argumentsThese arguments are available for all tools. A tool may have different arguments as well, those are listed as additional parameters below the tool.commandexplanation--bleAdapterAddressbleAdapterAddress of the BLE chip you want to use (linux only). This is usually a mac address.--keyFileThe json file with key information, expected values: admin, member, guest, basic, serviceDataKey, localizationKey, meshApplicationKey, and meshNetworkKey--configFileThe json all data required to configure the tools. See the template file or the definition above for more information.Available toolsCurrently, available tools are:cs_scan_any_crownstone --verbose [--macFilter filter]This will scan for any available BLE (Bluetooth Low Energy) device.Parametersverbose: Optionally show full advertisement, not just a single line summary.macFilter(string): Optionally only filter for specific MAC address (e.g.AA:BB:CC:DD:EE:FF).cs_scan_known_crownstone --verbose [--macFilter filter]This will scan for any Crownstone in your sphere. This requires the keys you set to match those on the Crownstones.Parametersverbose: Optionally show full advertisement, not just a single line summary.macFilter(string): Optionally only filter for specific MAC address (e.g.AA:BB:CC:DD:EE:FF).cs_switch_crownstone [--bleAddress address] --switchTo stateThis will switch a Crownstone in your sphere. This requires the keys you set to match those on the Crownstones.ParametersbleAddress(string): Optionally. The MAC address of the Crownstone that you want to switch (e.g.AA:BB:CC:DD:EE:FF). Required if you do not switch via broadcast.switchTo(integer): Set the switch state. Between 0 and 100 is dimming (0 is off, 100 is fully on). Set to 255 to switch to what the "behaviour rules" on the Crownstones want it to be.cs_upload_microapp --bleAddress address --file binaryFileThis will upload a microapp.ParametersbleAddress(string): Required MAC address of the Crownstone that you want to upload microapp to (e.g.AA:BB:CC:DD:EE:FF).file(string): Required binary file (.bin) of the microapp to be uploaded.cs_enable_microapp --bleAddress addressThis will enable a microapp. Required if a microapp is not yet been enabled or has been disabled.ParametersbleAddress(string): Required MAC address of the Crownstone that you want to upload microapp to (e.g.AA:BB:CC:DD:EE:FF).