Skip to main content

Scheduling Device Charging

One common request is to schedule ports to turn off or reduce charging levels. This is requested on a timing basis or when device batteries reach a certain charge level.

Change on a time basis.

You can achieve this by using the API commands and writing a script that runs off a scheduling application.

There is both a CLI scripting method and an API scripting method. To turn the ports off, the commands would need to be as below.

CLI

mode o

JSON with the API

{
  "id": 0,
  "jsonrpc": "2.0",
  "method": "cbrx_connection_set",
  "params": [
    "connection-handle",
    "Mode",
    "o"
  ]
}

To obtain the connection handle, please see the API documentation. https://www.cambrionix.com/products/api

To turn the ports back on again, you would need to send the same script but with 's' rather than 'o' as the mode to signify 'sync' mode rather than 'off.' You can also change the script to change specific ports, this information can be found in the API documentation as above or in the CLI documentation. https://www.cambrionix.com/cli

Change on a battery percentage basis

If you wish to automate this with a battery charge percentage, then you will need first to run a command in the API to obtain the battery charge percentage, which will, in turn then run the above commands. One thing to note with this is that when you turn the port off, you will no longer be able to check for battery percent levels and, as such, will need to schedule the ports to turn back on after some time.

The command to obtain the battery percentage can be found below. The device must be trusted and the port in Sync mode to obtain this information. For Apple devices, this information gathering is built in, but for Android, you must have the ADB server running on your host system.

{
  "jsonrpc": "2.0",
  "id": 0,
  "method": "cbrx_discover",
  "params": [
    "all"
  ]
}

Once you have run this, you will see all connected devices and battery levels, and you can pull the information from the response to trigger another script to run.