Skip to content

Commit

Permalink
NOISSUE - Update docs (#36)
Browse files Browse the repository at this point in the history
* update docs

Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>

* update config file

Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>

* change log level

Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>

* update readme

Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>

* update config file

Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>

* update docs

Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>

* add services commands

Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>

* fix typo

Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>

* align with dflts

Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
  • Loading branch information
mteodor authored Apr 28, 2020
1 parent cbba89b commit fad5032
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 37 deletions.
98 changes: 82 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Mainflux IoT Agent is a communication, execution and SW management agent for Mai
## Install
Get the code:

```
```bash
go get github.com/mainflux/agent
cd $GOPATH/github.com/mainflux/agent
```
Expand All @@ -25,35 +25,101 @@ make
```

## Usage
Get Nats server and start it
```bash
go get github.com/nats-io/gnatsd
gnatsd
```
start Agent
```bash
MF_AGENT_BOOTSTRAP_ID=<bootstrap_id> \
MF_AGENT_BOOTSTRAP_KEY=<bootstrap_key> \
MF_AGENT_BOOTSTRAP_URL=https://mainflux.com/bs/things/bootstrap \
build/mainflux-agent
```

### Config
Agent configuration is kept in `cmd/config.toml`.
Agent configuration is kept in `config.toml` if not otherwise specified with env var.

Example configuration:
```
[server]
port = "9000"
File = "config.toml"
[thing]
id = "90f9aff0-73f6-476b-a4da-d277ab99d3ce"
key = "e606945e-47bd-405f-85f3-a4c55bd069c8"
[Agent]
[channels]
control = "3ace3fa3-aa84-4a02-b0ab-6d594268dc77"
data = "0bdeea73-8de1-420c-8c4d-a4e7d6c46e3b"
[Agent.channels]
control = ""
data = ""
[edgex]
url = "http://localhost:48090/api/v1/"
[Agent.edgex]
url = "http://localhost:48090/api/v1/"
[log]
level = "info"
[Agent.log]
level = "info"
[Agent.mqtt]
ca_path = "ca.crt"
cert_path = "thing.crt"
mtls = false
password = ""
priv_key_path = "thin.key"
qos = 0
retain = false
skip_tls_ver = false
url = "localhost:1883"
username = ""
[Agent.server]
nats_url = "localhost:4222"
port = "9000"
[mqtt]
url = "localhost:1883"
```

Environment:
| Variable | Description | Default |
|----------------------------------------|---------------------------------------------------------------|-----------------------------------|
| MF_AGENT_CONFIG_FILE | Location of configuration file | config.toml |
| MF_AGENT_LOG_LEVEL | Log level | info |
| MF_AGENT_EDGEX_URL | Edgex base url | http://localhost:48090/api/v1/ |
| MF_AGENT_MQTT_URL | MQTT broker url | localhost:1883 |
| MF_AGENT_HTTP_PORT | Agent http port | 9000 |
| MF_AGENT_BOOTSTRAP_URL | Mainflux bootstrap url | http://localhost:8202/things/bootstrap|
| MF_AGENT_BOOTSTRAP_ID | Mainflux bootstrap id | |
| MF_AGENT_BOOTSTRAP_KEY | Mainflux boostrap key | |
| MF_AGENT_BOOTSTRAP_RETRIES | Number of retries for bootstrap procedure | 5 |
| MF_AGENT_BOOTSTRAP_RETRY_DELAY_SECONDS | Number of seconds between retries | 10 |
| MF_AGENT_CONTROL_CHANNEL | Channel for sending controls, commands | |
| MF_AGENT_DATA_CHANNEL | Channel for data sending | |
| MF_AGENT_ENCRYPTION | Encryption | false |
| MF_AGENT_NATS_URL | Nats url | nats://localhost:4222 |
| MF_AGENT_MQTT_USERNAME | MQTT username, Mainflux thing id | |
| MF_AGENT_MQTT_PASSWORD | MQTT password, Mainflux thing key | |
| MF_AGENT_MQTT_SKIP_TLS | Skip TLS verification | true |
| MF_AGENT_MQTT_MTLS | Use MTLS for MQTT | false |
| MF_AGENT_MQTT_CA | Location for CA certificate for MTLS | ca.crt |
| MF_AGENT_MQTT_QOS | QoS | 0 |
| MF_AGENT_MQTT_RETAIN | MQTT retain | false |
| MF_AGENT_MQTT_CLIENT_CERT | Location of client certificate for MTLS | thing.cert |
| MF_AGENT_MQTT_CLIENT_PK | Location of client certificate key for MTLS | thing.key |

Here `thing` is a Mainflux thing, and control channel from `channels` is used with `req` and `res` subtopic
(i.e. app needs to PUB/SUB on `/channels/<channel_id>/messages/req` and `/channels/<channel_id>/messages/res`).

## Sending commands to other services
You can send commands to other services that are subscribed on the same Nats server as Agent.
Commands are being sent via MQTT to topic:
`channels/<control_channel>/messages/services/<service_name>/<subtopic>`
when messages is received Agent forwards them to Nats on subject:
`commands.<service_name>.<subtopic>`.
Payload is up to the application and service itself.

Example of on command can be:

```
mosquitto_pub -u <thing_id> -P <thing_key> -t channels/<control_channel>/messages/services/adc -h <mqtt_host> -p 1883 -m "[{\"bn\":\"1:\", \"n\":\"read\", \"vs\":\"temperature\"}]"
```


## License

[Apache-2.0](LICENSE)
Expand Down
10 changes: 4 additions & 6 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ import (
const (
defHTTPPort = "9000"
defBootstrapURL = "http://localhost:8202/things/bootstrap"
defBootstrapID = "75-7E-36-73-54-EC"
defBootstrapKey = "2cf9cb98-5ae9-42d8-bb21-1b6af97a490c"
defBootstrapID = ""
defBootstrapKey = ""
defBootstrapRetries = "5"
defBootstrapRetryDelaySeconds = "10"
defLogLevel = "info"
defEdgexURL = "http://localhost:48090/api/v1/"
defMqttURL = "localhost:1883"
defCtrlChan = "f36c3733-95a3-481c-a314-4125e03d8993"
defDataChan = "ea353dac-0298-4fbb-9e5d-501e3699949c"
defCtrlChan = ""
defDataChan = ""
defEncryption = "false"
defMqttUsername = ""
defMqttPassword = ""
Expand All @@ -62,8 +62,6 @@ const (
envBootstrapKey = "MF_AGENT_BOOTSTRAP_KEY"
envBootstrapRetries = "MF_AGENT_BOOTSTRAP_RETRIES"
envBootstrapRetryDelaySeconds = "MF_AGENT_BOOTSTRAP_RETRY_DELAY_SECONDS"
envThingID = "MF_AGENT_THING_ID"
envThingKey = "MF_AGENT_THING_KEY"
envCtrlChan = "MF_AGENT_CONTROL_CHANNEL"
envDataChan = "MF_AGENT_DATA_CHANNEL"
envEncryption = "MF_AGENT_ENCRYPTION"
Expand Down
38 changes: 24 additions & 14 deletions configs/config.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
[server]
port = "9000"
File = "config.toml"

[thing]
id = "90f9aff0-73f6-476b-a4da-d277ab99d3ce"
key = "e606945e-47bd-405f-85f3-a4c55bd069c8"
[Agent]

[channels]
control = "3ace3fa3-aa84-4a02-b0ab-6d594268dc77"
data = "0bdeea73-8de1-420c-8c4d-a4e7d6c46e3b"
[Agent.channels]
control = ""
data = ""

[edgex]
url = "http://localhost:48090/api/v1/"
[Agent.edgex]
url = "http://localhost:48090/api/v1/"

[log]
level = "info"
[Agent.log]
level = "info"

[mqtt]
url = "localhost:1883"
[Agent.mqtt]
ca_path = "ca.crt"
cert_path = "thing.crt"
mtls = false
password = ""
priv_key_path = "thing.key"
qos = 0
retain = false
skip_tls_ver = false
url = "localhost:1883"
username = ""

[Agent.server]
nats_url = "localhost:4222"
port = "9000"
2 changes: 1 addition & 1 deletion pkg/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func saveExportConfig(econf export.Config, logger log.Logger) {
if !exConfFileExist {
logger.Info(fmt.Sprintf("Saving export config file %s", econf.File))
if err := export.Save(econf); err != nil {
logger.Error(fmt.Sprintf("Failed to save export config file %s", err))
logger.Warn(fmt.Sprintf("Failed to save export config file %s", err))
}
}
}
Expand Down

0 comments on commit fad5032

Please sign in to comment.