lassie

package module
v0.0.0-...-faedfc6 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2018 License: Apache-2.0 Imports: 14 Imported by: 2

README

lassie-go

Lassie provides a client for the REST API for Telenor LoRa.

Configuration

The configuration file is located at ${HOME}/.lassie. The file is a simple list of key/value pairs. Additional values are ignored. Comments must start with a #:

#
# This is the URL of the Congress REST API. The default value is
# https://api.lora.telenor.io and can usually be omitted.
address=https://api.lora.telenor.io

#
# This is the API token. Create new token by logging in to the Congress
# front-end at https://lora.engineering and create a new token there.
token=<your api token goes here>

The configuration file settings can be overridden by setting the environment variables LASSIE_ADDRESS and LASSIE_TOKEN. If you only use environment variables the configuration file can be ignored.

Use the NewWithAddr function to bypass the default configuration file and environment variables when you want to create the client programmatically.

Documentation

Overview

Package lassie provides a client for the REST API for Telenor LoRa.

All Create* and Update* methods return the created and updated entity, respectively, which may include setting fields that were not set.

Index

Constants

View Source
const (
	// DefaultAddr is the default address of the Congress API. You normally won't
	// have to change this.
	DefaultAddr = "https://api.lora.telenor.io"

	// ConfigFile is the default name for the config file. The configuration
	// file is a plain text file that contains the default Lassie configuration.
	// The configuration file is expected to be at the current home directory.
	ConfigFile = ".lassie"

	// AddressEnvironmentVariable is the name of the environment variable that
	// can be used to override the address set in the configuration file.
	// If the  environment variable isn't set (or is empty) the configuration
	// file settings will be used.
	AddressEnvironmentVariable = "LASSIE_ADDRESS"

	// TokenEnvironmentVariable is the name of the environment variable that
	// can be used to override the token set in the configuration file.
	TokenEnvironmentVariable = "LASSIE_TOKEN"
)
View Source
const AWSIoTConfigType = "awsiot"

AWSIoTConfigType is the string identifier for AWS IoT configs.

View Source
const MQTTConfigType = "mqtt"

MQTTConfigType is the string idenfier for MQTT configs

Variables

This section is empty.

Functions

This section is empty.

Types

type AWSIoTConfig

type AWSIoTConfig struct {
	Endpoint          string `json:"endpoint"`
	ClientID          string `json:"clientid"`
	ClientCertificate string `json:"clientCertificate"`
	PrivateKey        string `json:"privateKey"`
}

AWSIoTConfig is an application output configuration for AWS IoT.

func (*AWSIoTConfig) Map

func (a *AWSIoTConfig) Map() map[string]interface{}

Map returns the configuration as a map

func (*AWSIoTConfig) Type

func (a *AWSIoTConfig) Type() string

Type returns the string identifying the output

type Application

type Application struct {
	EUI  string            `json:"applicationEUI"`
	Tags map[string]string `json:"tags"`
}

Application represents an application.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a client for the Telenor LoRa-as-a-Service API.

func New

func New() (*Client, error)

New creates a new client with the default configuration. The default configuration can be specified in a configuration file or through environment variables.

func NewWithAddr

func NewWithAddr(addr, token string) (*Client, error)

NewWithAddr creates a new client with the specified address and token.

func (*Client) Address

func (c *Client) Address() string

Address returns the client's address.

func (*Client) Application

func (c *Client) Application(eui string) (Application, error)

Application gets an application.

func (*Client) ApplicationStream

func (c *Client) ApplicationStream(appeui string, handler func(DeviceData)) error

ApplicationStream calls handler in its own goroutine for each device message received. It blocks until an error occurs, including EOF when the connection is closed.

func (*Client) Applications

func (c *Client) Applications() ([]Application, error)

Applications gets all applications.

func (*Client) CreateApplication

func (c *Client) CreateApplication(app Application) (Application, error)

CreateApplication creates an application.

func (*Client) CreateDevice

func (c *Client) CreateDevice(appeui string, dev Device) (Device, error)

CreateDevice creates a device.

func (*Client) CreateGateway

func (c *Client) CreateGateway(gw Gateway) (Gateway, error)

CreateGateway creates a new gateway

func (*Client) CreateOutput

func (c *Client) CreateOutput(appEUI string, config OutputConfig) (Output, error)

CreateOutput creates a new application output.

func (*Client) DeleteApplication

func (c *Client) DeleteApplication(eui string) error

DeleteApplication deletes an application.

func (*Client) DeleteDevice

func (c *Client) DeleteDevice(appeui, deveui string) error

DeleteDevice deletes a device.

func (*Client) DeleteGateway

func (c *Client) DeleteGateway(eui string) error

DeleteGateway removes a gateway

func (*Client) DeleteOutput

func (c *Client) DeleteOutput(appEUI, outputEUI string) error

DeleteOutput removes (and stops) an application output

func (*Client) Device

func (c *Client) Device(appeui, deveui string) (Device, error)

Device gets a device.

func (*Client) Devices

func (c *Client) Devices(appeui string) ([]Device, error)

Devices gets all devices.

func (*Client) Gateway

func (c *Client) Gateway(eui string) (Gateway, error)

Gateway retrieves a gateway

func (*Client) GetScheduledMessage

func (c *Client) GetScheduledMessage(appeui, deveui string) (DownstreamMessage, error)

GetScheduledMessage returns the scheduled message for the device.

func (*Client) Output

func (c *Client) Output(appEUI, outputEUI string) (Output, error)

Output returns a single output

func (*Client) Outputs

func (c *Client) Outputs(appEUI string) ([]Output, error)

Outputs returns all outputs for the application

func (*Client) ScheduleMessage

func (c *Client) ScheduleMessage(appeui, deveui string, msg DownstreamMessage) error

ScheduleMessage schedules a downstream message to a device. Port is in range 1-223. If the ack flag is set the message will be re-sent until the device acknowledges it. The payload is hex encoded.

func (*Client) UpdateApplication

func (c *Client) UpdateApplication(app Application) (Application, error)

UpdateApplication updates an application.

func (*Client) UpdateDevice

func (c *Client) UpdateDevice(appeui string, dev Device) (Device, error)

UpdateDevice updates a device.

func (*Client) UpdateGateway

func (c *Client) UpdateGateway(gw Gateway) (Gateway, error)

UpdateGateway updates the gateway

func (*Client) UpdateOutput

func (c *Client) UpdateOutput(appEUI, outputEUI string, config OutputConfig) (Output, error)

UpdateOutput updates an application output with a new configuration

type ClientError

type ClientError struct {
	HTTPStatusCode int
	Message        string
}

ClientError describes what went wrong with a request that otherwise succeeded but which resulted in an HTTP status code >= 300.

func (ClientError) Error

func (e ClientError) Error() string

type Device

type Device struct {
	EUI                   string            `json:"deviceEUI"`
	Type                  string            `json:"deviceType"`
	DeviceAddress         string            `json:"devAddr"`
	ApplicationKey        string            `json:"appKey"`
	ApplicationSessionKey string            `json:"appSKey"`
	NetworkSessionKey     string            `json:"nwkSKey"`
	FrameCounterUp        uint16            `json:"fCntUp"`
	FrameCounterDown      uint16            `json:"fCntDn"`
	RelaxedCounter        bool              `json:"relaxedCounter"`
	KeyWarning            bool              `json:"keyWarning"`
	Tags                  map[string]string `json:"tags"`
}

Device represents a device.

type DeviceData

type DeviceData struct {
	DeviceEUI      string `json:"deviceEUI"`
	DeviceAddress  string `json:"devAddr"`
	GatewayEUI     string `json:"gatewayEUI"`
	ApplicationEUI string `json:"appEUI"`
	Timestamp      int64  `json:"timestamp"`
	HexData        string `json:"data"`
	Data           []byte
	Frequency      float32 `json:"frequency"`
	DataRate       string  `json:"dataRate"`
	RSSI           int32   `json:"rssi"`
	SNR            float32 `json:"snr"`
}

DeviceData represents data received from a device.

type DownstreamMessage

type DownstreamMessage struct {
	Port       uint8  `json:"port"`
	Ack        bool   `json:"ack"`
	HexPayload string `json:"data"`
}

DownstreamMessage represents downstream messages to devices.

type Gateway

type Gateway struct {
	EUI       string            `json:"gatewayEUI"`
	IP        string            `json:"ip"`
	StrictIP  bool              `json:"strictIP"`
	Latitude  float64           `json:"latitude"`
	Longitude float64           `json:"longitude"`
	Altitude  float64           `json:"altitude"`
	Tags      map[string]string `json:"tags"`
}

Gateway represents a gateway

type MQTTConfig

type MQTTConfig struct {
	Endpoint         string `json:"endpoint"`
	Port             int    `json:"port"`
	TLS              bool   `json:"tls"`
	CertificateCheck bool   `json:"certCheck"`
	Username         string `json:"username"`
	Password         string `json:"password"`
	ClientID         string `json:"clientid"`
	TopicName        string `json:"topicName"`
}

MQTTConfig is an application output configuration for the MQTT outputs.

func (*MQTTConfig) Map

func (m *MQTTConfig) Map() map[string]interface{}

Map returns the configuration as a map

func (*MQTTConfig) Type

func (m *MQTTConfig) Type() string

Type returns a string identifying the output

type Output

type Output struct {
	EUI    string                 `json:"eui"`
	AppEUI string                 `json:"appEUI"`
	Config map[string]interface{} `json:"config"`
	Log    []OutputLogEntry       `json:"logs"`
	Status string                 `json:"status"`
}

Output contains status, logs and configuration for an application output.

func (*Output) AWSIoTConfig

func (o *Output) AWSIoTConfig() (AWSIoTConfig, error)

AWSIoTConfig returns the AWS IoT config for the output

func (*Output) MQTTConfig

func (o *Output) MQTTConfig() (MQTTConfig, error)

MQTTConfig returns the MQTTConfig for the output.

type OutputConfig

type OutputConfig interface {
	Map() map[string]interface{}
	Type() string
}

OutputConfig is a configuration for application outputs. Use the actual output types

type OutputLogEntry

type OutputLogEntry struct {
	Time    string `json:"time"`
	Message string `json:"message"`
}

OutputLogEntry contains a single log entry from an application output. This log entries are kept just for simple diagnostics. If you are having problems with the output inspect the output's log entries.

Jump to

Keyboard shortcuts

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