lora

package
v0.0.0-...-97327ab Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 6, 2019 License: Apache-2.0 Imports: 5 Imported by: 0

README

LoRa Adapter

Adapter between Mainflux IoT system and LoRa Server.

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.

Configuration

The service is configured using the environment variables presented in the following table. Note that any unset variables will be replaced with their default values.

Variable Description Default
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_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
MF_THINGS_ES_URL Things service event store URL localhost:6379
MF_THINGS_ES_PASS Things service event store password
MF_THINGS_ES_DB Things service event store db 0
MF_LORA_ADAPTER_INSTANCE_NAME LoRa adapter instance name lora

Deployment

The service is distributed as Docker container. The following snippet provides a compose file template that can be used to deploy the service container locally:

version: "2"
services:
  adapter:
    image: mainflux/lora:[version]
    container_name: [instance name]
    environment:
      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]

To start the service outside of the container, execute the following shell script:

# download the latest version of the service
go get github.com/mainflux/mainflux

cd $GOPATH/src/github.com/mainflux/mainflux

# compile the lora adapter
make lora

# copy binary to bin
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_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

This service can be deployed using docker containers. Docker compose file is available in <project_root>/docker/addons/lora-adapter/docker-compose.yml. In order to run Mainflux lora-adapter, execute the following command:

docker-compose -f docker/addons/lora-adapter/docker-compose.yml up -d

Usage

For more information about service capabilities and its usage, please check out the Mainflux documentation.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMalformedIdentity indicates malformed identity received (e.g.
	// invalid appID or deviceEUI).
	ErrMalformedIdentity = errors.New("malformed identity received")

	// ErrMalformedMessage indicates malformed LoRa message.
	ErrMalformedMessage = errors.New("malformed message received")

	// ErrNotFoundDev indicates a non-existent route map for a device EUI.
	ErrNotFoundDev = errors.New("route map not found for this device EUI")

	// ErrNotFoundApp indicates a non-existent route map for an application ID.
	ErrNotFoundApp = errors.New("route map not found for this application ID")
)

Functions

This section is empty.

Types

type DataRate

type DataRate struct {
	Modulation   string  `json:"modulation"`
	Bandwith     float64 `json:"bandwith"`
	SpreadFactor int64   `json:"spreadFactor"`
}

DataRate lora data rate

type Message

type Message struct {
	ApplicationID       string      `json:"applicationID"`
	ApplicationName     string      `json:"applicationName"`
	DeviceName          string      `json:"deviceName"`
	DevEUI              string      `json:"devEUI"`
	DeviceStatusBattery string      `json:"deviceStatusBattery"`
	DeviceStatusMrgin   string      `json:"deviceStatusMargin"`
	RxInfo              RxInfo      `json:"rxInfo"`
	TxInfo              TxInfo      `json:"txInfo"`
	FCnt                int         `json:"fCnt"`
	FPort               int         `json:"fPort"`
	Data                string      `json:"data"`
	Object              interface{} `json:"object"`
}

Message lora msg (www.loraserver.io/lora-app-server/integrate/data/)

type RouteMapRepository

type RouteMapRepository interface {
	// Save stores/routes pair lora application topic & mainflux channel.
	Save(string, string) error

	// Channel returns mainflux channel for given lora application.
	Get(string) (string, error)

	// Removes mapping from cache.
	Remove(string) error
}

RouteMapRepository store route map between Lora App Server and Mainflux

type RxInfo

type RxInfo []struct {
	Mac       string  `json:"mac"`
	Name      string  `json:"name"`
	Latitude  float64 `json:"latitude"`
	Longitude float64 `json:"longitude"`
	Altitude  float64 `json:"altitude"`
	Time      string  `json:"time"`
	Rssi      float64 `json:"rssi"`
	LoRaSNR   float64 `json:"loRaSNR"`
}

RxInfo receiver parameters

type Service

type Service interface {
	// CreateThing creates thing  mfx:lora & lora:mfx route-map
	CreateThing(string, string) error

	// UpdateThing updates thing mfx:lora & lora:mfx route-map
	UpdateThing(string, string) error

	// RemoveThing removes thing mfx:lora & lora:mfx route-map
	RemoveThing(string) error

	// CreateChannel creates channel mfx:lora & lora:mfx route-map
	CreateChannel(string, string) error

	// UpdateChannel updates mfx:lora & lora:mfx route-map
	UpdateChannel(string, string) error

	// RemoveChannel removes channel mfx:lora & lora:mfx route-map
	RemoveChannel(string) error

	// Publish forwards messages from the LoRa MQTT broker to Mainflux NATS broker
	Publish(context.Context, string, Message) error
}

Service specifies an API that must be fullfiled by the domain service implementation, and all of its decorators (e.g. logging & metrics).

func New

func New(pub mainflux.MessagePublisher, thingsRM, channelsRM RouteMapRepository) Service

New instantiates the LoRa adapter implementation.

type TxInfo

type TxInfo struct {
	Frequency float64  `json:"frequency"`
	DataRate  DataRate `json:"dataRate"`
	Adr       bool     `json:"adr"`
	CodeRate  string   `json:"codeRate"`
}

TxInfo transmeter parameters

Directories

Path Synopsis
Package nats contains NATS message publisher implementation.
Package nats contains NATS message publisher implementation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL