NOISSUE- Improve LoRa doc (#562)
* Improve lora docs Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Typo fix Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Typo fix Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Typo fix Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
This commit is contained in:
parent
bf9e148120
commit
c04909d645
|
@ -38,7 +38,7 @@ const (
|
|||
defRouteMapDB = "0"
|
||||
|
||||
envHTTPPort = "MF_LORA_ADAPTER_HTTP_PORT"
|
||||
envLoraMsgURL = "MF_LORA_ADAPTER_LORA_MESSAGE_URL"
|
||||
envLoraMsgURL = "MF_LORA_ADAPTER_MESSAGES_URL"
|
||||
envNatsURL = "MF_NATS_URL"
|
||||
envLogLevel = "MF_LORA_ADAPTER_LOG_LEVEL"
|
||||
envESURL = "MF_THINGS_ES_URL"
|
||||
|
|
|
@ -27,7 +27,7 @@ services:
|
|||
MF_LORA_ADAPTER_LOG_LEVEL: debug
|
||||
MF_THINGS_ES_URL: things-redis:6379
|
||||
MF_LORA_ADAPTER_ROUTEMAP_URL: lora-redis:6379
|
||||
MF_LORA_ADAPTER_LORA_MESSAGE_URL: tcp://lora.mqtt.mainflux.io:1883
|
||||
MF_LORA_ADAPTER_MESSAGES_URL: tcp://lora.mqtt.mainflux.io:1883
|
||||
MF_LORA_ADAPTER_HTTP_PORT: 8187
|
||||
MF_NATS_URL: nats://nats:4222
|
||||
ports:
|
||||
|
|
53
docs/lora.md
53
docs/lora.md
|
@ -1,4 +1,10 @@
|
|||
Before running Mainflux `lora-adapter` you must install and run [LoRa Server](https://www.loraserver.io/loraserver/overview). First, execute the following command:
|
||||
Bridging with LoRaWAN Networks can be done over the [lora-adapter](https://github.com/mainflux/mainflux/tree/master/lora). This service sits between Mainflux and [LoRa Server](https://www.loraserver.io) and just forwards the messages from one system to another via MQTT protocol, using the adequate MQTT topics and in the good message format (JSON and SenML), i.e. respecting the APIs of both systems.
|
||||
|
||||
LoRa Server is used for connectivity layer. Specially for the [LoRa Gateway Bridge](https://www.loraserver.io/lora-gateway-bridge/overview/) service, which abstracts the [SemTech packet-forwarder UDP protocol](https://github.com/Lora-net/packet_forwarder/blob/master/PROTOCOL.TXT) into JSON over MQTT. But also for the [LoRa Server](https://www.loraserver.io/loraserver/overview) service, responsible of the de-duplication and handling of uplink frames received by the gateway(s), handling of the LoRaWAN mac-layer and scheduling of downlink data transmissions. Finally the [Lora App Server](https://www.loraserver.io/lora-app-server/overview/) services is used to interact with the system.
|
||||
|
||||
## Run Lora Server
|
||||
|
||||
Before to run the `lora-adapter` you must install and run LoRa Server. First, execute the following command:
|
||||
|
||||
```bash
|
||||
go get github.com/brocaar/loraserver-docker
|
||||
|
@ -10,40 +16,42 @@ Once everything is installed, execute the following command from the LoRa Server
|
|||
docker-compose up
|
||||
```
|
||||
|
||||
The Mainflux lora-adapter can do bridging between both systems. Basically, the service subscribe to the [LoRa Gateway Bridge](https://www.loraserver.io/lora-gateway-bridge/overview/), a service which abstracts the [SemTech packet-forwarder UDP protocol](https://github.com/Lora-net/packet_forwarder/blob/master/PROTOCOL.TXT) into JSON over MQTT.
|
||||
**Troubleshouting:** Mainflux and LoRa Server use their own MQTT brokers. By default, those use the standard MQTT port `1883`. If you are running both systems on the same machine you must use different ports. You can fix this on Mainflux side configuring the environment variable `MF_MQTT_ADAPTER_PORT`.
|
||||
|
||||
You must configure the `MF_LORA_ADAPTER_LORA_MESSAGE_URL` variable in the [lora-adapter docker-compose.yml](https://github.com/mainflux/mainflux/blob/master/docker/addons/lora-adapter/docker-compose.yml) with the address of your LoRa Gateway Bridge, otherwise the composition will fail:
|
||||
|
||||
```bash
|
||||
docker-compose -f docker/addons/lora-adapter/docker-compose up
|
||||
```
|
||||
## Setup LoRa Server
|
||||
|
||||
At this point Mainflux and LoRa Server are running. To provision the LoRa Server with Networks, Organizations, Gateways, Applications and Devices you have to implement the gRPC API. Over the [LoRa App Server](https://www.loraserver.io/lora-app-server/overview), which is good example of the gRPC API implementation, you can do it as well.
|
||||
|
||||
#### LoRa Server setup
|
||||
Now that both systems are running you must provision LoRa Server, which offers for integration with external services, a RESTful and gRPC API. You can do it as well over the [LoRa App Server](https://www.loraserver.io/lora-app-server/overview), which is good example of integration.
|
||||
|
||||
- **Create Organization:** To add your own Gateways to the network you must have an Organization.
|
||||
- **Add Network LoRa Server:** Set the address of your Network-Server API that is used by LoRa App Server or other custom components interacting with LoRa Server (by default loraserver:8000).
|
||||
- **Create an Organization:** To add your own Gateways to the network you must have an Organization.
|
||||
- **Create a Network:** Set the address of your Network-Server API that is used by LoRa App Server or other custom components interacting with LoRa Server (by default loraserver:8000).
|
||||
- **Create a Gateways-Profile:** In this profile you can select the radio LoRa channels and the LoRa Network Server to use.
|
||||
- **Create a Service-profile:** A service-profile connects an organization to a network-server and defines the features that an organization can use on this Network-Server.
|
||||
- **Create a Gateway:** You must set proper ID in order to be discovered by LoRa Server.
|
||||
- **Create a LoRa Server Application:** You can then create Devices by connecting them to this application. This is equivalent to Devices connected to channels in Mainflux.
|
||||
- **Create an Application:** This will allows you to create Devices by connecting them to this application. This is equivalent to Devices connected to channels in Mainflux.
|
||||
- **Create a Device-Profile:** Before creating Device you must create Device profile where you will define some parameter as LoRaWAN MAC version (format of the device address) and the LoRaWAN regional parameter (frequency band). This will allow you to create many devices using this profile.
|
||||
- **Create a Device:** Then you can create a Device. You must configure the `network session key` and `application session key` of your Device. You can generate and copy them on your device configuration or you can use your own pre generated keys and set them using the [Lora App Server](https://www.loraserver.io/lora-app-server/overview/).
|
||||
- **Create a Device:** Finally, you can create a Device. You must configure the `network session key` and `application session key` of your Device. You can generate and copy them on your device configuration or you can use your own pre generated keys and set them using the LoRa App Server UI.
|
||||
Device connect through OTAA. Make sure that loraserver device-profile is using same release as device. If MAC version is 1.0.X, `application key = app_key` and `app_eui = deviceEUI`. If MAC version is 1.1 or ABP both parameters will be needed, APP_key and Network key.
|
||||
|
||||
#### Connect Mainflux and LoRa Server with lora-adapter
|
||||
|
||||
This adapter sits between Mainflux and LoRa Server and forwards the MQTT messages from the [LoRa Gateways Bridge](https://www.loraserver.io/lora-gateway-bridge/overview) to the Mainflux multi-protocol message broker, using the adequate MQTT topics and in the good message format (JSON and SenML), i.e. respecting the APIs of both systems.
|
||||
|
||||
|
||||
## Mainflux and LoRa Server
|
||||
|
||||
|
||||
Once everything is running and the LoRa Server is provisioned, execute the following command from Mainflux project root to run the lora-adapter:
|
||||
|
||||
|
||||
```bash
|
||||
docker-compose -f docker/addons/lora-adapter/docker-compose.yml up -d
|
||||
```
|
||||
|
||||
This service uses RedisDB to create a route map between both systems. As in Mainflux we use Channels to connect Things, LoRa Server uses Applications to connect Devices. There are then two routes,
|
||||
The lora-adapter uses the matadata of provision events emitted by mainflux-things service to update the route map. For that, you must provision Mainflux Channels and Things with an extra metadata key in the JSON Body of the HTTP request. It must be a JSON object with keys `type` and `appID` or `devEUI`. In this case `type` must be `lora`, `appID` and `devEUI` must be an existent Lora application ID and device EUI:
|
||||
**Troubleshouting:** The lora-adapter subscribes to the LoRa Server MQTT broker and will fail if the connection is not established. You must ensure that the environment variable `MF_LORA_ADAPTER_MESSAGES_URL` is propertly configured.
|
||||
|
||||
**Remark:** By defaut, `MF_LORA_ADAPTER_MESSAGES_URL` is set as `tcp://lora.mqtt.mainflux.io:1883` in the [docker-compose.yml](https://github.com/mainflux/mainflux/blob/master/docker/addons/lora-adapter/docker-compose.yml) file of the adapter. If you run the composition without configure this variable you will start to receive messages from our demo server.
|
||||
|
||||
### Route Map
|
||||
|
||||
The lora-adapter use [Redis](https://redis.io/) database to create a route map between both systems. As in Mainflux we use Channels to connect Things, LoRa Server uses Applications to connect Devices.
|
||||
|
||||
The lora-adapter uses the matadata of provision events emitted by Mainflux system to update his route map. For that, you must provision Mainflux Channels and Things with an extra metadata key in the JSON Body of the HTTP request. It must be a JSON object with keys `type` and `appID` or `devEUI`. In this case `type` must be `lora` and `appID` or `devEUI` must be an existent Lora application ID or device EUI:
|
||||
|
||||
**Channel structure:**
|
||||
|
||||
|
@ -70,5 +78,6 @@ The lora-adapter uses the matadata of provision events emitted by mainflux-thing
|
|||
}
|
||||
```
|
||||
|
||||
To forward LoRa messages the lora-adapter subscribes to topics `applications/+/devices/+` of the [LoRa Gateway Bridge](https://www.loraserver.io/lora-gateway-bridge/overview). It verifies `appID` and `devEUI` of published messages. If the mapping exists it uses corresponding `channelID` and `thingID` to sign and forwards the content of the LoRa message to the Mainflux message broker.
|
||||
For more information about service capabilities and its usage, please check out the API documentation.
|
||||
##### Messaging
|
||||
|
||||
To forward LoRa messages the lora-adapter subscribes to topics `applications/+/devices/+` of the LoRa Server MQTT broker. It verifies `appID` and `devEUI` of published messages. If the mapping exists it uses corresponding `channelID` and `thingID` to sign and forwards the content of the LoRa message to the Mainflux message broker.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# LoRa Adapter
|
||||
Adapter between Mainflux IoT system and [LoRa Server](https://github.com/brocaar/loraserver).
|
||||
|
||||
This adapter sits between Mainflux and LoRa server and just forwards the messages form one system to another via MQTT protocol, using the adequate MQTT topics and in the good message format (JSON and SenML), i.e. respecting the APIs of both systems.
|
||||
This adapter sits between Mainflux and LoRa server and just forwards the messages from one system to another via MQTT protocol, using the adequate MQTT topics and in the good message format (JSON and SenML), i.e. respecting the APIs of both systems.
|
||||
|
||||
LoRa Server is used for connectivity layer and data is pushed via this adapter service to Mainflux, where it is persisted and routed to other protocols via Mainflux multi-protocol message broker. Mainflux adds user accounts, application management and security in order to obtain the overall end-to-end LoRa solution.
|
||||
|
||||
|
@ -16,7 +16,7 @@ default values.
|
|||
| MF_LORA_ADAPTER_HTTP_PORT | Service HTTP port | 8180 |
|
||||
| MF_LORA_ADAPTER_LOG_LEVEL | Log level for the Lora Adapter | error |
|
||||
| MF_NATS_URL | NATS instance URL | nats://localhost:4222 |
|
||||
| MF_LORA_ADAPTER_LORA_MESSAGE_URL | LoRa Server mqtt broker URL | tcp://localhost:1883 |
|
||||
| MF_LORA_ADAPTER_MESSAGES_URL | LoRa Server mqtt broker URL | tcp://localhost:1883 |
|
||||
| MF_LORA_ADAPTER_ROUTEMAP_URL | Routemap database URL | localhost:6379 |
|
||||
| MF_LORA_ADAPTER_ROUTEMAP_PASS | Routemap database password | |
|
||||
| MF_LORA_ADAPTER_ROUTEMAP_DB | Routemap instance that should be used | 0 |
|
||||
|
@ -39,7 +39,7 @@ services:
|
|||
environment:
|
||||
MF_LORA_ADAPTER_LOG_LEVEL: [Lora Adapter Log Level]
|
||||
MF_NATS_URL: [NATS instance URL]
|
||||
MF_LORA_ADAPTER_LORA_MESSAGE_URL: [LoRa Server mqtt broker URL]
|
||||
MF_LORA_ADAPTER_MESSAGES_URL: [LoRa Server mqtt broker URL]
|
||||
MF_LORA_ADAPTER_ROUTEMAP_URL: [Lora adapter routemap URL]
|
||||
MF_LORA_ADAPTER_ROUTEMAP_PASS: [Lora adapter routemap password]
|
||||
MF_LORA_ADAPTER_ROUTEMAP_DB: [Lora adapter routemap instance]
|
||||
|
@ -64,7 +64,7 @@ make lora
|
|||
make install
|
||||
|
||||
# set the environment variables and run the service
|
||||
MF_LORA_ADAPTER_LOG_LEVEL=[Lora Adapter Log Level] MF_NATS_URL=[NATS instance URL] MF_LORA_ADAPTER_LORA_MESSAGE_URL=[LoRa Server mqtt broker URL] MF_LORA_ADAPTER_ROUTEMAP_URL=[Lora adapter routemap URL] MF_LORA_ADAPTER_ROUTEMAP_PASS=[Lora adapter routemap password] MF_LORA_ADAPTER_ROUTEMAP_DB=[Lora adapter routemap instance] MF_THINGS_ES_URL=[Things service event store URL] MF_THINGS_ES_PASS=[Things service event store password] MF_THINGS_ES_DB=[Things service event store db] MF_LORA_ADAPTER_INSTANCE_NAME=[LoRa adapter instance name] $GOBIN/mainflux-lora
|
||||
MF_LORA_ADAPTER_LOG_LEVEL=[Lora Adapter Log Level] MF_NATS_URL=[NATS instance URL] MF_LORA_ADAPTER_MESSAGES_URL=[LoRa Server mqtt broker URL] MF_LORA_ADAPTER_ROUTEMAP_URL=[Lora adapter routemap URL] MF_LORA_ADAPTER_ROUTEMAP_PASS=[Lora adapter routemap password] MF_LORA_ADAPTER_ROUTEMAP_DB=[Lora adapter routemap instance] MF_THINGS_ES_URL=[Things service event store URL] MF_THINGS_ES_PASS=[Things service event store password] MF_THINGS_ES_DB=[Things service event store db] MF_LORA_ADAPTER_INSTANCE_NAME=[LoRa adapter instance name] $GOBIN/mainflux-lora
|
||||
```
|
||||
|
||||
### Using docker-compose
|
||||
|
@ -78,36 +78,5 @@ docker-compose -f docker/addons/lora-adapter/docker-compose.yml up -d
|
|||
|
||||
## Usage
|
||||
|
||||
First of all you must run your LoRa Server. You need to clone the repository with command `go get github.com/brocaar/loraserver-docker` and deploy docker containers with command `docker-compose up` from `$GOPATH/src/github.com/brocaar/loraserver-docker` repository.
|
||||
Then you must provision your system. Basically it means create a Network-server where to connect your Gateways and Applications where to connect Devices. If you need more information about the LoRa Server setup you can check [the LoRa App Server documentation](https://www.loraserver.io/lora-app-server/overview/)
|
||||
|
||||
Once you are done with the LoRa Server setup you can run the lora-adapter. This service uses RedisDB to create a route map between both systems. As in Mainflux we use Channels to connect Things, Loraserser uses Applications to connect Devices. Route map connects applicationsID with channelID and deviceEUI with thingID.
|
||||
The lora-adapter uses the matadata of provision events emitted by mainflux-things service to update the route map.
|
||||
For that, you must provision Mainflux Channels and Things with an extra `metadata` key in the JSON Body of the HTTP request. It must be a JSON object with keys `type` and `appID` or `devEUI`. Obviously `type` must be `lora`, `appID` and `devEUI` must be an existent Lora application ID and device EUI.
|
||||
|
||||
```
|
||||
{
|
||||
"name": "<channel name>",
|
||||
"metadata:":{
|
||||
"type": "lora",
|
||||
"appID": "<application ID>"
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
```
|
||||
{
|
||||
"type": "device",
|
||||
"name": "<thing name>",
|
||||
"metadata:":{
|
||||
"type": "lora",
|
||||
"devEUI": "<device EUI>"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
To receive Lora messages the lora-adapter subscribes to topic `applications/+/devices/+` of the LoRa Server MQTT broker. The [LoRa Gateway Bridge](https://www.loraserver.io/lora-gateway-bridge/overview/)uses the same topic to publish decoded messages received from gateways as UDP packets. The lora-adapter verify the applicationID and the deviceEUI of published message and if they are known it forwards the message on the Mainflux NATS broker as corresponding channel and thing.
|
||||
|
||||
|
||||
For more information about service capabilities and its usage, please check out
|
||||
the [API documentation](swagger.yaml).
|
||||
the [Mainflux documentation](https://mainflux.readthedocs.io/en/latest/lora/).
|
||||
|
|
Loading…
Reference in New Issue