2018-08-16 13:41:27 +02:00
# Mainflux CLI
2023-06-14 12:40:37 +02:00
2018-08-16 13:41:27 +02:00
## Build
2023-06-14 12:40:37 +02:00
2018-08-16 13:41:27 +02:00
From the project root:
2023-06-14 12:40:37 +02:00
2020-04-23 10:24:42 +02:00
```bash
2018-08-16 13:41:27 +02:00
make cli
```
## Usage
2023-06-14 12:40:37 +02:00
2018-08-16 13:41:27 +02:00
### Service
2023-06-14 12:40:37 +02:00
2022-01-24 21:18:53 +01:00
#### Get Mainflux Things services Health Check
2023-06-14 12:40:37 +02:00
2020-04-23 10:24:42 +02:00
```bash
2022-01-24 21:18:53 +01:00
mainflux-cli health
2018-08-16 13:41:27 +02:00
```
2019-02-01 23:17:09 +01:00
### Users management
2023-06-14 12:40:37 +02:00
2018-08-16 13:41:27 +02:00
#### Create User
2023-06-14 12:40:37 +02:00
2020-04-23 10:24:42 +02:00
```bash
2023-06-14 12:40:37 +02:00
mainflux-cli users create < user_name > < user_email > < user_password >
mainflux-cli users create < user_name > < user_email > < user_password > < user_token >
2018-08-16 13:41:27 +02:00
```
#### Login User
2023-06-14 12:40:37 +02:00
2020-04-23 10:24:42 +02:00
```bash
2020-03-09 11:31:19 +01:00
mainflux-cli users token < user_email > < user_password >
2018-08-16 13:41:27 +02:00
```
2023-06-14 12:40:37 +02:00
#### Get User
```bash
mainflux-cli users get < user_id > < user_token >
```
#### Get Users
2020-04-23 10:24:42 +02:00
```bash
2023-06-14 12:40:37 +02:00
mainflux-cli users get all < user_token >
2020-03-04 18:37:41 +01:00
```
2020-03-09 11:31:19 +01:00
#### Update User Metadata
2023-06-14 12:40:37 +02:00
2020-04-23 10:24:42 +02:00
```bash
2023-06-14 12:40:37 +02:00
mainflux-cli users update < user_id > '{"name":"value1", "metadata":{"value2": "value3"}}' < user_token >
2020-03-04 18:37:41 +01:00
```
#### Update User Password
2023-06-14 12:40:37 +02:00
```bash
mainflux-cli users password < old_password > < password > < user_token >
```
#### Enable User
```bash
mainflux-cli users enable < user_id > < user_token >
```
#### Disable User
2020-04-23 10:24:42 +02:00
```bash
2023-06-14 12:40:37 +02:00
mainflux-cli users disable < user_id > < user_token >
2020-03-04 18:37:41 +01:00
```
2018-08-16 13:41:27 +02:00
### System Provisioning
2023-06-14 12:40:37 +02:00
2020-04-23 10:24:42 +02:00
#### Create Thing
2023-06-14 12:40:37 +02:00
2020-04-23 10:24:42 +02:00
```bash
2023-06-14 12:40:37 +02:00
mainflux-cli things create '{"name":"myThing"}' < user_token >
2018-08-16 13:41:27 +02:00
```
2020-04-23 10:24:42 +02:00
#### Create Thing with metadata
2023-06-14 12:40:37 +02:00
2020-04-23 10:24:42 +02:00
```bash
2023-06-14 12:40:37 +02:00
mainflux-cli things create '{"name":"myThing", "metadata": {"key1":"value1"}}' < user_token >
2018-08-16 13:41:27 +02:00
```
2020-04-23 10:24:42 +02:00
#### Bulk Provision Things
2023-06-14 12:40:37 +02:00
2020-04-23 10:24:42 +02:00
```bash
2023-06-14 12:40:37 +02:00
mainflux-cli provision things < file > < user_token >
2018-08-16 13:41:27 +02:00
```
2023-06-14 12:40:37 +02:00
* `file` - A CSV or JSON file containing thing names (must have extension `.csv` or `.json` )
* `user_token` - A valid user auth token for the current system
An example CSV file might be:
```csv
thing1,
thing2,
thing3,
```
in which the first column is the thing's name.
A comparable JSON file would be
```json
[{
"name": "< thing1_name > ",
"status": "enabled"
},
{
"name": "< thing2_name > ",
"status": "disabled"
}, {
"name": "< thing3_name > ",
"status": "enabled",
"credentials": {
"identity": "< thing3_identity > ",
"secret": "< thing3_secret > "
}
}
]
```
With JSON you can be able to specify more fields of the channels you want to create
2020-04-23 10:24:42 +02:00
2019-02-01 23:17:09 +01:00
#### Update Thing
2023-06-14 12:40:37 +02:00
2020-04-23 10:24:42 +02:00
```bash
2023-06-14 12:40:37 +02:00
mainflux-cli things update < thing_id > '{"name":"value1", "metadata":{"key1": "value2"}}' < user_token >
2019-02-01 23:17:09 +01:00
```
2023-06-14 12:40:37 +02:00
#### Identify Thing
2020-04-23 10:24:42 +02:00
```bash
2023-06-14 12:40:37 +02:00
mainflux-cli things identify < thing_key >
2019-02-01 23:17:09 +01:00
```
2023-06-14 12:40:37 +02:00
#### Enable Thing
2020-04-23 10:24:42 +02:00
```bash
2023-06-14 12:40:37 +02:00
mainflux-cli things enable < thing_id > < user_token >
2018-08-16 13:41:27 +02:00
```
2023-06-14 12:40:37 +02:00
#### Disable Thing
2020-04-23 10:24:42 +02:00
```bash
2023-06-14 12:40:37 +02:00
mainflux-cli things disable < thing_id > < user_token >
```
#### Get Thing
```bash
mainflux-cli things get < thing_id > < user_token >
```
#### Get Things
```bash
mainflux-cli things get all < user_token >
```
#### Get a subset list of provisioned Things
```bash
mainflux-cli things get all --offset=1 --limit=5 < user_token >
2018-08-16 13:41:27 +02:00
```
2019-02-01 23:17:09 +01:00
#### Create Channel
2023-06-14 12:40:37 +02:00
2020-04-23 10:24:42 +02:00
```bash
2023-06-14 12:40:37 +02:00
mainflux-cli channels create '{"name":"myChannel"}' < user_token >
2018-08-16 13:41:27 +02:00
```
2020-04-23 10:24:42 +02:00
#### Bulk Provision Channels
2023-06-14 12:40:37 +02:00
2020-04-23 10:24:42 +02:00
```bash
2023-06-14 12:40:37 +02:00
mainflux-cli provision channels < file > < user_token >
```
* `file` - A CSV or JSON file containing channel names (must have extension `.csv` or `.json` )
* `user_token` - A valid user auth token for the current system
An example CSV file might be:
```csv
< channel1_name > ,
< channel2_name > ,
< channel3_name > ,
2018-08-16 13:41:27 +02:00
```
2023-06-14 12:40:37 +02:00
in which the first column is channel names.
A comparable JSON file would be
```json
[{
"name": "< channel1_name > ",
"description": "< channel1_description > ",
"status": "enabled"
},
{
"name": "< channel2_name > ",
"description": "< channel2_description > ",
"status": "disabled"
}, {
"name": "< channel3_name > ",
"description": "< channel3_description > ",
"status": "enabled"
}
]
```
With JSON you can be able to specify more fields of the channels you want to create
2020-04-23 10:24:42 +02:00
#### Update Channel
2023-06-14 12:40:37 +02:00
2020-04-23 10:24:42 +02:00
```bash
2023-06-14 12:40:37 +02:00
mainflux-cli channels update '{"id":"< channel_id > ","name":"myNewName"}' < user_token >
2018-08-16 13:41:27 +02:00
```
2020-04-23 10:24:42 +02:00
2023-06-14 12:40:37 +02:00
#### Enable Channel
2020-04-23 10:24:42 +02:00
```bash
2023-06-14 12:40:37 +02:00
mainflux-cli channels enable < channel_id > < user_token >
2018-08-16 13:41:27 +02:00
```
2023-06-14 12:40:37 +02:00
#### Disable Channel
2020-04-23 10:24:42 +02:00
```bash
2023-06-14 12:40:37 +02:00
mainflux-cli channels disable < channel_id > < user_token >
2018-08-16 13:41:27 +02:00
```
2023-06-14 12:40:37 +02:00
#### Get Channel
```bash
mainflux-cli channels get < channel_id > < user_token >
```
#### Get Channels
2020-04-23 10:24:42 +02:00
```bash
2023-06-14 12:40:37 +02:00
mainflux-cli channels get all < user_token >
```
#### Get a subset list of provisioned Channels
```bash
mainflux-cli channels get all --offset=1 --limit=5 < user_token >
2018-08-16 13:41:27 +02:00
```
### Access control
2023-06-14 12:40:37 +02:00
2019-02-01 23:17:09 +01:00
#### Connect Thing to Channel
2023-06-14 12:40:37 +02:00
2020-04-23 10:24:42 +02:00
```bash
2023-06-14 12:40:37 +02:00
mainflux-cli things connect < thing_id > < channel_id > < user_token >
2018-08-16 13:41:27 +02:00
```
2020-04-23 10:24:42 +02:00
#### Bulk Connect Things to Channels
2023-06-14 12:40:37 +02:00
2020-04-23 10:24:42 +02:00
```bash
2023-06-14 12:40:37 +02:00
mainflux-cli provision connect < file > < user_token >
2018-08-16 13:41:27 +02:00
```
2020-04-23 10:24:42 +02:00
2023-06-14 12:40:37 +02:00
* `file` - A CSV or JSON file containing thing and channel ids (must have extension `.csv` or `.json` )
* `user_token` - A valid user auth token for the current system
2020-04-23 10:24:42 +02:00
An example CSV file might be
```csv
2023-06-14 12:40:37 +02:00
< thing_id1 > ,< channel_id1 >
< thing_id2 > ,< channel_id2 >
2020-04-23 10:24:42 +02:00
```
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
{
2023-06-14 12:40:37 +02:00
"client_ids": [
"< thing_id1 > ",
"< thing_id2 > "
2020-04-23 10:24:42 +02:00
],
2023-06-14 12:40:37 +02:00
"group_ids": [
"< channel_id1 > ",
"< channel_id2 > "
2020-04-23 10:24:42 +02:00
]
}
```
#### Disconnect Thing from Channel
2019-02-01 23:17:09 +01:00
2023-06-14 12:40:37 +02:00
```bash
mainflux-cli things disconnect < thing_id > < channel_id > < user_token >
2019-02-01 23:17:09 +01:00
```
2023-06-14 12:40:37 +02:00
#### Get a subset list of Channels connected to Thing
2020-04-23 10:24:42 +02:00
```bash
2023-06-14 12:40:37 +02:00
mainflux-cli things connections < thing_id > < user_token >
2019-02-01 23:17:09 +01:00
```
2023-06-14 12:40:37 +02:00
#### Get a subset list of Things connected to Channel
2020-04-23 10:24:42 +02:00
```bash
2023-06-14 12:40:37 +02:00
mainflux-cli channels connections < channel_id > < user_token >
2018-08-16 13:41:27 +02:00
```
### Messaging
2023-06-14 12:40:37 +02:00
2018-08-16 13:41:27 +02:00
#### Send a message over HTTP
2023-06-14 12:40:37 +02:00
2020-04-23 10:24:42 +02:00
```bash
2023-06-14 12:40:37 +02: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_secret >
2018-08-16 13:41:27 +02:00
```
2020-03-09 11:31:19 +01:00
#### Read messages over HTTP
2023-06-14 12:40:37 +02:00
2020-04-23 10:24:42 +02:00
```bash
2023-06-14 12:40:37 +02:00
mainflux-cli messages read < channel_id > < user_token > -R < reader_url >
2020-03-09 11:31:19 +01:00
```
2020-04-23 10:24:42 +02:00
### Bootstrap
#### Add configuration
2023-06-14 12:40:37 +02:00
2020-04-23 10:24:42 +02:00
```bash
2023-06-14 12:40:37 +02:00
mainflux-cli bootstrap create '{"external_id": "myExtID", "external_key": "myExtKey", "name": "myName", "content": "myContent"}' < user_token > -b < bootstrap-url >
2020-04-23 10:24:42 +02:00
```
#### View configuration
2023-06-14 12:40:37 +02:00
2020-04-23 10:24:42 +02:00
```bash
2023-06-14 12:40:37 +02:00
mainflux-cli bootstrap get < thing_id > < user_token > -b < bootstrap-url >
2020-04-23 10:24:42 +02:00
```
#### Update configuration
2023-06-14 12:40:37 +02:00
2020-04-23 10:24:42 +02:00
```bash
2023-07-31 15:17:14 +03:00
mainflux-cli bootstrap update '{"thing_id":"< thing_id > ", "name": "newName", "content": "newContent"}' < user_token > -b < bootstrap-url >
2020-04-23 10:24:42 +02:00
```
#### Remove configuration
2023-06-14 12:40:37 +02:00
2020-04-23 10:24:42 +02:00
```bash
2023-06-14 12:40:37 +02:00
mainflux-cli bootstrap remove < thing_id > < user_token > -b < bootstrap-url >
2020-04-23 10:24:42 +02:00
```
#### Bootstrap configuration
2023-06-14 12:40:37 +02:00
2020-04-23 10:24:42 +02:00
```bash
2023-06-14 12:40:37 +02:00
mainflux-cli bootstrap bootstrap < external_id > < external_key > -b < bootstrap-url >
2020-04-23 10:24:42 +02:00
```
2020-09-23 23:18:53 +02:00
### Groups
2023-06-14 12:40:37 +02:00
#### Create Group
2020-09-23 23:18:53 +02:00
```bash
2023-06-14 12:40:37 +02:00
mainflux-cli groups create '{"name":"< group_name > ","description":"< description > ","parentID":"< parent_id > ","metadata":"< metadata > "}' < user_token >
2020-09-23 23:18:53 +02:00
```
2023-06-14 12:40:37 +02:00
#### Get Group
2020-09-23 23:18:53 +02:00
```bash
2023-06-14 12:40:37 +02:00
mainflux-cli groups get < group_id > < user_token >
2020-09-23 23:18:53 +02:00
```
2023-06-14 12:40:37 +02:00
#### Get Groups
2020-09-23 23:18:53 +02:00
```bash
2023-06-14 12:40:37 +02:00
mainflux-cli groups get all < user_token >
2020-09-23 23:18:53 +02:00
```
2023-06-14 12:40:37 +02:00
#### Get Group Members
2020-09-23 23:18:53 +02:00
```bash
2023-06-14 12:40:37 +02:00
mainflux-cli groups members < group_id > < user_token >
2020-09-23 23:18:53 +02:00
```
2023-06-14 12:40:37 +02:00
#### Get Memberships
2020-09-23 23:18:53 +02:00
```bash
2023-06-14 12:40:37 +02:00
mainflux-cli groups membership < member_id > < user_token >
2020-09-23 23:18:53 +02:00
```
2023-06-14 12:40:37 +02:00
#### Assign Members to Group
2020-09-23 23:18:53 +02:00
```bash
2023-06-14 12:40:37 +02:00
mainflux-cli groups assign < member_ids > < member_type > < group_id > < user_token >
2022-01-24 21:18:53 +01:00
```
2022-01-27 15:42:31 +01:00
2023-06-14 12:40:37 +02:00
#### Unassign Members to Group
2022-01-27 15:42:31 +01:00
```bash
2023-06-14 12:40:37 +02:00
mainflux-cli groups unassign < member_ids > < group_id > < user_token >
2022-01-27 15:42:31 +01:00
```
2023-06-14 12:40:37 +02:00
#### Enable Group
2022-01-27 15:42:31 +01:00
```bash
2023-06-14 12:40:37 +02:00
mainflux-cli groups enable < group_id > < user_token >
2022-01-27 15:42:31 +01:00
```
2023-06-14 12:40:37 +02:00
#### Disable Group
2022-01-27 15:42:31 +01:00
```bash
2023-06-14 12:40:37 +02:00
mainflux-cli groups disable < group_id > < user_token >
2022-01-27 15:42:31 +01:00
```