2018-08-16 19:41:27 +08:00
# Mainflux CLI
## Build
From the project root:
2020-04-23 16:24:42 +08:00
```bash
2018-08-16 19:41:27 +08:00
make cli
```
## Usage
### Service
2019-02-02 06:17:09 +08:00
#### Get the version of Mainflux services
2020-04-23 16:24:42 +08:00
```bash
2018-08-16 19:41:27 +08:00
mainflux-cli version
```
2019-02-02 06:17:09 +08:00
### Users management
2018-08-16 19:41:27 +08:00
#### Create User
2020-04-23 16:24:42 +08:00
```bash
2020-03-09 18:31:19 +08:00
mainflux-cli users create < user_email > < user_password >
2018-08-16 19:41:27 +08:00
```
#### Login User
2020-04-23 16:24:42 +08:00
```bash
2020-03-09 18:31:19 +08:00
mainflux-cli users token < user_email > < user_password >
2018-08-16 19:41:27 +08:00
```
2020-03-05 01:37:41 +08:00
#### Retrieve User
2020-04-23 16:24:42 +08:00
```bash
2020-03-05 01:37:41 +08:00
mainflux-cli users get < user_auth_token >
```
2020-03-09 18:31:19 +08:00
#### Update User Metadata
2020-04-23 16:24:42 +08:00
```bash
2020-03-09 18:31:19 +08:00
mainflux-cli users update '{"key1":"value1", "key2":"value2"}' < user_auth_token >
2020-03-05 01:37:41 +08:00
```
#### Update User Password
2020-04-23 16:24:42 +08:00
```bash
2020-03-05 01:37:41 +08:00
mainflux-cli users password < old_password > < password > < user_auth_token >
```
2018-08-16 19:41:27 +08:00
### System Provisioning
2020-04-23 16:24:42 +08:00
#### Create Thing
```bash
mainflux-cli things create '{"name":"myThing"}' < user_auth_token >
2018-08-16 19:41:27 +08:00
```
2020-04-23 16:24:42 +08:00
#### Create Thing with metadata
```bash
mainflux-cli things create '{"name":"myThing", "metadata": {\"key1\":\"value1\"}}' < user_auth_token >
2018-08-16 19:41:27 +08:00
```
2020-04-23 16:24:42 +08:00
#### Bulk Provision Things
```bash
mainflux-cli provision things < file > < user_auth_token >
2018-08-16 19:41:27 +08:00
```
2020-04-23 16:24:42 +08:00
* `file` - A CSV or JSON file containing things
* `user_auth_token` - A valid user auth token for the current system
2019-02-02 06:17:09 +08:00
#### Update Thing
2020-04-23 16:24:42 +08:00
```bash
2019-02-02 06:17:09 +08:00
mainflux-cli things update '{"id":"< thing_id > ", "name":"myNewName"}' < user_auth_token >
```
#### Remove Thing
2020-04-23 16:24:42 +08:00
```bash
2019-02-02 06:17:09 +08:00
mainflux-cli things delete < thing_id > < user_auth_token >
```
#### Retrieve a subset list of provisioned Things
2020-04-23 16:24:42 +08:00
```bash
2018-08-16 19:41:27 +08:00
mainflux-cli things get all --offset=1 --limit=5 < user_auth_token >
```
#### Retrieve Thing By ID
2020-04-23 16:24:42 +08:00
```bash
2018-11-27 15:40:56 +08:00
mainflux-cli things get < thing_id > < user_auth_token >
2018-08-16 19:41:27 +08:00
```
2019-02-02 06:17:09 +08:00
#### Create Channel
2020-04-23 16:24:42 +08:00
```bash
2019-02-02 06:17:09 +08:00
mainflux-cli channels create '{"name":"myChannel"}' < user_auth_token >
2018-08-16 19:41:27 +08:00
```
2020-04-23 16:24:42 +08:00
#### Bulk Provision Channels
```bash
mainflux-cli provision channels < file > < user_auth_token >
2018-08-16 19:41:27 +08:00
```
2020-04-23 16:24:42 +08:00
* `file` - A CSV or JSON file containing channels
* `user_auth_token` - A valid user auth token for the current system
#### Update Channel
```bash
mainflux-cli channels update '{"id":"< channel_id > ","name":"myNewName"}' < user_auth_token >
2018-08-16 19:41:27 +08:00
```
2020-04-23 16:24:42 +08:00
2019-02-02 06:17:09 +08:00
#### Remove Channel
2020-04-23 16:24:42 +08:00
```bash
2019-02-02 06:17:09 +08:00
mainflux-cli channels delete < channel_id > < user_auth_token >
2018-08-16 19:41:27 +08:00
```
2019-02-02 06:17:09 +08:00
#### Retrieve a subset list of provisioned Channels
2020-04-23 16:24:42 +08:00
```bash
2019-02-02 06:17:09 +08:00
mainflux-cli channels get all --offset=1 --limit=5 < user_auth_token >
2018-08-16 19:41:27 +08:00
```
2019-02-02 06:17:09 +08:00
#### Retrieve Channel By ID
2020-04-23 16:24:42 +08:00
```bash
2019-02-02 06:17:09 +08:00
mainflux-cli channels get < channel_id > < user_auth_token >
2018-08-16 19:41:27 +08:00
```
### Access control
2019-02-02 06:17:09 +08:00
#### Connect Thing to Channel
2020-04-23 16:24:42 +08:00
```bash
2018-08-16 19:41:27 +08:00
mainflux-cli things connect < thing_id > < channel_id > < user_auth_token >
```
2020-04-23 16:24:42 +08:00
#### Bulk Connect Things to Channels
```bash
mainflux-cli provision connect < file > < user_auth_token >
2018-08-16 19:41:27 +08:00
```
2020-04-23 16:24:42 +08:00
* `file` - A CSV or JSON file containing thing and channel ids
* `user_auth_token` - A valid user auth token for the current system
An example CSV file might be
```csv
< thing_id > ,< channel_id >
< thing_id > ,< channel_id >
```
in which the first column is thing IDs and the second column is channel IDs. A connection will be created for each thing to each channel. This example would result in 4 connections being created.
A comparable JSON file would be
```json
{
"thing_ids": [
"< thing_id > ",
"< thing_id > "
],
"channel_ids": [
"< channel_id > ",
"< channel_id > "
]
}
```
#### Disconnect Thing from Channel
```bash
2018-08-16 19:41:27 +08:00
mainflux-cli things disconnect < thing_id > < channel_id > < user_auth_token >
2019-02-02 06:17:09 +08:00
```
#### Retrieve a subset list of Channels connected to Thing
2020-04-23 16:24:42 +08:00
```bash
2019-02-02 06:17:09 +08:00
mainflux-cli things connections < thing_id > < user_auth_token >
```
#### Retrieve a subset list of Things connected to Channel
2020-04-23 16:24:42 +08:00
```bash
2019-02-02 06:17:09 +08:00
mainflux-cli channels connections < channel_id > < user_auth_token >
2018-08-16 19:41:27 +08:00
```
2020-04-23 16:24:42 +08:00
2018-08-16 19:41:27 +08:00
### Messaging
#### Send a message over HTTP
2020-04-23 16:24:42 +08:00
```bash
2019-07-04 15:57:03 +08:00
mainflux-cli messages send < channel_id > '[{"bn":"Dev1","n":"temp","v":20}, {"n":"hum","v":40}, {"bn":"Dev2", "n":"temp","v":20}, {"n":"hum","v":40}]' < thing_auth_token >
2018-08-16 19:41:27 +08:00
```
2020-03-09 18:31:19 +08:00
#### Read messages over HTTP
2020-04-23 16:24:42 +08:00
```bash
2020-03-09 18:31:19 +08:00
mainflux-cli messages read < channel_id > < thing_auth_token >
```
2020-04-23 16:24:42 +08:00
### Bootstrap
#### Add configuration
```bash
mainflux-cli bootstrap add '{"external_id": "myExtID", "external_key": "myExtKey", "name": "myName", "content": "myContent"}' < user_auth_token >
```
#### View configuration
```bash
mainflux-cli bootstrap view < thing_id > < user_auth_token >
```
#### Update configuration
```bash
mainflux-cli bootstrap update '{"MFThing":"< thing_id > ", "name": "newName", "content": "newContent"}' < user_auth_token >
```
#### Remove configuration
```bash
mainflux-cli bootstrap remove < thing_id > < user_auth_token >
```
#### Bootstrap configuration
```bash
mainflux-cli bootstrap bootstrap < external_id > < external_key >
```
2020-09-24 05:18:53 +08:00
### Groups
#### Create new group
```bash
mainflux-cli groups create '{"name":"< group_name > ","parent_id":"< parent_group_id > ","description":"< description > ","metadata":{"key":"value",...}}' < user_auth_token >
```
#### Delete group
```bash
mainflux-cli groups delete < group_id > < user_auth_token >
```
#### Get group with id
```bash
mainflux-cli groups get < group_id > < user_auth_token >
```
#### List all groups
```bash
mainflux-cli groups get all < user_auth_token >
```
#### List children groups for some group
```bash
mainflux-cli groups get children < parent_group_id > < user_auth_token >
```
#### Assign user to a group
```bash
mainflux-cli groups assign < user_id > < group_id > < user_auth_token >
```
#### Unassign user from group
```bash
mainflux-cli groups unassign < user_id > < group_id > < user_auth_token >
```
#### List users for a group
```bash
mainflux-cli groups members < group_id > < user_auth_token >
```
#### List groups that user belongs to
```bash
mainflux-cli groups membership < user_id > < user_auth_token >
```