2018-11-27 15:40:56 +08:00
## CLI
Mainflux CLI makes it easy to manage users, things, channels and messages.
CLI can be downloaded as separate asset from [project realeses ](https://github.com/mainflux/mainflux/releases ) or it can be built with `GNU Make` tool:
```
make cli
```
which will build `mainflux-cli` in `<project_root>/build` folder.
Executing `build/mainflux-cli` without any arguments will output help with all available commands and flags:
```
Usage:
mainflux-cli [command]
Available Commands:
2019-02-02 06:17:09 +08:00
channels Channels management
2018-11-27 15:40:56 +08:00
help Help about any command
2019-02-02 06:17:09 +08:00
messages Send or read messages
2019-10-29 19:59:54 +08:00
provision Bulk create things and channels from a config file
2019-02-02 06:17:09 +08:00
things Things management
users Users management
version Mainflux system version
2018-11-27 15:40:56 +08:00
Flags:
-c, --content-type string Mainflux message content type (default "application/senml+json")
-h, --help help for mainflux-cli
-a, --http-prefix string Mainflux http adapter prefix (default "http")
-i, --insecure Do not check for TLS cert
-l, --limit uint limit query parameter (default 100)
-m, --mainflux-url string Mainflux host URL (default "http://localhost")
-o, --offset uint offset query parameter
-t, --things-prefix string Mainflux things service prefix
-u, --users-prefix string Mainflux users service prefix
Use "mainflux-cli [command] --help" for more information about a command.
```
You can execute each command with `-h` flag for more information about that command, e.g.
```
./mainflux-cli channels -h
```
will get you usage info:
```
2019-02-02 06:17:09 +08:00
Channels management: create, get, update or delete Channels and get list of Things connected to Channels
2018-11-27 15:40:56 +08:00
Usage:
mainflux-cli channels [flags]
mainflux-cli channels [command]
Available Commands:
2019-02-02 06:17:09 +08:00
connections connections < channel_id > < user_auth_token >
2018-11-27 15:40:56 +08:00
create create < JSON_channel > < user_auth_token >
delete delete < channel_id > < user_auth_token >
2019-02-02 06:17:09 +08:00
get get < channel_id | all > < user_auth_token >
2018-11-27 15:40:56 +08:00
update update < JSON_string > < user_auth_token >
```
2019-02-02 06:17:09 +08:00
## Service
#### Get the version of Mainflux services
2018-11-27 15:40:56 +08:00
```
2019-02-02 06:17:09 +08:00
mainflux-cli version
2018-11-27 15:40:56 +08:00
```
2019-02-02 06:17:09 +08:00
### Users management
2018-11-27 15:40:56 +08:00
#### Create User
```
2019-02-02 06:17:09 +08:00
mainflux-cli users create john.doe@email.com password
2018-11-27 15:40:56 +08:00
```
#### Login User
```
2019-02-02 06:17:09 +08:00
mainflux-cli users token john.doe@email.com password
2018-11-27 15:40:56 +08:00
```
### System Provisioning
2019-04-20 20:09:11 +08:00
#### Create Thing
2018-11-27 15:40:56 +08:00
```
2019-04-20 20:09:11 +08:00
mainflux-cli things create '{"name":"myThing"}' < user_auth_token >
2018-11-27 15:40:56 +08:00
```
2019-10-29 19:59:54 +08:00
#### Bulk Provision Things
```bash
mainflux-cli provision things < file > < user_auth_token >
```
* `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
2018-11-27 15:40:56 +08:00
```
2019-02-02 06:17:09 +08:00
mainflux-cli things update '{"id":"< thing_id > ", "name":"myNewName"}' < user_auth_token >
2018-11-27 15:40:56 +08:00
```
2019-02-02 06:17:09 +08:00
#### Remove Thing
2018-11-27 15:40:56 +08:00
```
2019-02-02 06:17:09 +08:00
mainflux-cli things delete < thing_id > < user_auth_token >
2018-11-27 15:40:56 +08:00
```
2019-02-02 06:17:09 +08:00
#### Retrieve a subset list of provisioned Things
2018-11-27 15:40:56 +08:00
```
2019-02-02 06:17:09 +08:00
mainflux-cli things get all --offset=1 --limit=5 < user_auth_token >
2018-11-27 15:40:56 +08:00
```
2019-02-02 06:17:09 +08:00
#### Retrieve Thing By ID
2018-11-27 15:40:56 +08:00
```
2019-02-02 06:17:09 +08:00
mainflux-cli things get < thing_id > < user_auth_token >
2018-11-27 15:40:56 +08:00
```
2019-02-02 06:17:09 +08:00
#### Create Channel
2018-11-27 15:40:56 +08:00
```
2019-02-02 06:17:09 +08:00
mainflux-cli channels create '{"name":"myChannel"}' < user_auth_token >
2018-11-27 15:40:56 +08:00
```
2019-10-29 19:59:54 +08:00
#### Bulk Provision Channels
```bash
mainflux-cli provision channels < file > < user_auth_token >
```
* `file` - A CSV or JSON file containing channels
* `user_auth_token` - A valid user auth token for the current system
2019-02-02 06:17:09 +08:00
#### Update Channel
```
mainflux-cli channels update '{"id":"< channel_id > ","name":"myNewName"}' < user_auth_token >
2018-11-27 15:40:56 +08:00
```
2019-02-02 06:17:09 +08:00
#### Remove Channel
```
mainflux-cli channels delete < channel_id > < user_auth_token >
2018-11-27 15:40:56 +08:00
```
2019-02-02 06:17:09 +08:00
#### Retrieve a subset list of provisioned Channels
```
mainflux-cli channels get all --offset=1 --limit=5 < user_auth_token >
```
2018-11-27 15:40:56 +08:00
2019-02-02 06:17:09 +08:00
#### Retrieve Channel By ID
2018-11-27 15:40:56 +08:00
```
2019-02-02 06:17:09 +08:00
mainflux-cli channels get < channel_id > < user_auth_token >
2018-11-27 15:40:56 +08:00
```
### Access control
2019-02-02 06:17:09 +08:00
#### Connect Thing to Channel
```
mainflux-cli things connect < thing_id > < channel_id > < user_auth_token >
```
2018-11-27 15:40:56 +08:00
2019-02-02 06:17:09 +08:00
#### Disconnect Thing from Channel
2018-11-27 15:40:56 +08:00
```
2019-02-02 06:17:09 +08:00
mainflux-cli things disconnect < thing_id > < channel_id > < user_auth_token >
2018-11-27 15:40:56 +08:00
```
2019-02-02 06:17:09 +08:00
#### Retrieve a subset list of Channels connected to Thing
```
mainflux-cli things connections < thing_id > < user_auth_token >
```
2018-11-27 15:40:56 +08:00
2019-02-02 06:17:09 +08:00
#### Retrieve a subset list of Things connected to Channel
2018-11-27 15:40:56 +08:00
```
2019-02-02 06:17:09 +08:00
mainflux-cli channels connections < channel_id > < user_auth_token >
2018-11-27 15:40:56 +08:00
```
### Messaging
#### Send a message over HTTP
```
2019-02-02 06:17:09 +08:00
mainflux-cli msg 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-11-27 15:40:56 +08:00
```