piot

package module
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2020 License: MIT Imports: 25 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

PIOT Golang
===========

.. image:: https://dev.azure.com/michalnezerka/PIOT/_apis/build/status/mnezerka.go-piot?branchName=master

Golang package provides services and utilities for PIOT infrastructure tools.


Development environment - minimal
---------------------------------

1. Run mongodb docker container::

     docker-compose up -d mongodb

2. Run script ``scripts/env.sh`` to get IP address of mongo container
   and set env variable for piot server

3. Run tests (not in parallel since shared mongodb is used)::

     # all tests
     go test

     # tests for selected test case (matched against regexp)
     go test --run ShortNotation

Documentation

Index

Constants

View Source
const PIOT_MEASUREMENT_TOPIC = "value"

topic name used for publishing sensor readings

View Source
const TOPIC_AVAILABLE = "available"
View Source
const TOPIC_HUMIDITY = "humidity"
View Source
const TOPIC_IP = "net/ip"
View Source
const TOPIC_NET = "net"
View Source
const TOPIC_PRESSURE = "pressure"
View Source
const TOPIC_ROOT = "org"
View Source
const TOPIC_TEMP = "temperature"
View Source
const TOPIC_UNIT = "unit"
View Source
const TOPIC_WIFI_SSID = "net/wifi/ssid"
View Source
const TOPIC_WIFI_STRENGTH = "net/wifi/strength"
View Source
const VALUE_NO = "no"
View Source
const VALUE_YES = "yes"

Variables

This section is empty.

Functions

func GetPasswordHash

func GetPasswordHash(pwd string) (string, error)

func InfluxDbEscapeString added in v1.0.2

func InfluxDbEscapeString(str string) string

func NewLogger

func NewLogger(log_format string, level string) (*logging.Logger, error)

NewLogger creates instance of logger that should be used in all server handlers and routines. The idea is to have unified style of logging - logger is configured only once and at one place

func PrimitiveToString added in v1.0.2

func PrimitiveToString(value interface{}) (string, error)

Types

type Auth

type Auth struct{}

func (*Auth) AuthUser

func (a *Auth) AuthUser(ctx context.Context, email, password string) error

type HttpClient

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

func (*HttpClient) PostString

func (c *HttpClient) PostString(url, body string, username *string, password *string)

type IHttpClient

type IHttpClient interface {
	//PostMeasurement(ctx context.Context, thing *model.Thing, value string)
	PostString(url, body string, username *string, password *string)
}

func NewHttpClient

func NewHttpClient(log *logging.Logger) IHttpClient

type IInfluxDb

type IInfluxDb interface {
	PostMeasurement(thing *model.Thing, value string)
	PostSwitchState(thing *model.Thing, value string)
	PostLocation(thing *model.Thing, lat, lng float64, sat, ts int32)
}

func NewInfluxDb

func NewInfluxDb(log *logging.Logger, orgs *Orgs, httpClient IHttpClient, uri, username, password string) IInfluxDb

type IMqtt

type IMqtt interface {
	PushThingData(thing *model.Thing, topic, value string) error
	ProcessMessage(topic, payload string)
	Connect(subscribe bool) error
	Disconnect() error
	SetUsername(username string)
	SetPassword(password string)
	SetClient(id string)
}

func NewMqtt

func NewMqtt(uri string, log *logging.Logger, things *Things, orgs *Orgs, influxDb IInfluxDb, mysqlDb IMysqlDb) IMqtt

type IMysqlDb

type IMysqlDb interface {
	Open() error
	Close()
	StoreMeasurement(thing *model.Thing, value string)
	StoreSwitchState(thing *model.Thing, value string)
}

func NewMysqlDb

func NewMysqlDb(log *logging.Logger, orgs *Orgs, host, username, password, name string) IMysqlDb

type InfluxDb

type InfluxDb struct {
	Uri      string
	Username string
	Password string
	// contains filtered or unexported fields
}

func (*InfluxDb) PostLocation added in v1.0.2

func (db *InfluxDb) PostLocation(thing *model.Thing, lat, lng float64, sat, ts int32)

func (*InfluxDb) PostMeasurement

func (db *InfluxDb) PostMeasurement(thing *model.Thing, value string)

func (*InfluxDb) PostSwitchState

func (db *InfluxDb) PostSwitchState(thing *model.Thing, value string)

type Mqtt

type Mqtt struct {
	Uri      string
	Username *string
	Password *string
	Client   *string
	// contains filtered or unexported fields
}

func (*Mqtt) Connect

func (t *Mqtt) Connect(subscribe bool) error

func (*Mqtt) Disconnect

func (t *Mqtt) Disconnect() error

func (*Mqtt) GetThingTopic

func (t *Mqtt) GetThingTopic(thing *model.Thing, topic string) (string, error)

func (*Mqtt) ProcessDevices

func (t *Mqtt) ProcessDevices(org *model.Org, topic, payload string)

func (*Mqtt) ProcessMessage

func (t *Mqtt) ProcessMessage(topic, payload string)

Process message received from MQTT broker for org subscription

func (*Mqtt) ProcessSensors

func (t *Mqtt) ProcessSensors(org *model.Org, topic, payload string)

func (*Mqtt) ProcessSwitches

func (t *Mqtt) ProcessSwitches(org *model.Org, topic, payload string)

func (*Mqtt) PushThingData

func (t *Mqtt) PushThingData(thing *model.Thing, topic, value string) error

func (*Mqtt) SetClient

func (t *Mqtt) SetClient(id string)

func (*Mqtt) SetPassword

func (t *Mqtt) SetPassword(password string)

func (*Mqtt) SetUsername

func (t *Mqtt) SetUsername(username string)

type MysqlDb

type MysqlDb struct {
	Host     string
	Username string
	Password string
	Name     string
	Db       *sql.DB
	// contains filtered or unexported fields
}

func (*MysqlDb) Close

func (db *MysqlDb) Close()

func (*MysqlDb) Open

func (db *MysqlDb) Open() error

func (*MysqlDb) StoreMeasurement

func (db *MysqlDb) StoreMeasurement(thing *model.Thing, value string)

func (*MysqlDb) StoreSwitchState

func (db *MysqlDb) StoreSwitchState(thing *model.Thing, value string)

type Orgs

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

func NewOrgs

func NewOrgs(log *logging.Logger, db *mongo.Database) *Orgs

func (*Orgs) Get

func (t *Orgs) Get(id primitive.ObjectID) (*model.Org, error)

func (*Orgs) GetByName

func (t *Orgs) GetByName(name string) (*model.Org, error)

type PiotDevices

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

func NewPiotDevices

func NewPiotDevices(logger *logging.Logger, things *Things, mqtt IMqtt, params *config.Parameters) *PiotDevices

constructor

func (*PiotDevices) ProcessPacket

func (p *PiotDevices) ProcessPacket(packet model.PiotDevicePacket) error

type RowMetric added in v1.0.2

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

func NewRowMetric added in v1.0.2

func NewRowMetric(
	name string,
	tags map[string]string,
	fields map[string]interface{},
	ts time.Time,
) *RowMetric

func (*RowMetric) Encode added in v1.0.2

func (rm *RowMetric) Encode() (*bytes.Buffer, error)

func (*RowMetric) FieldList added in v1.0.2

func (rm *RowMetric) FieldList() []*proto.Field

func (*RowMetric) Name added in v1.0.2

func (rm *RowMetric) Name() string

func (*RowMetric) TagList added in v1.0.2

func (rm *RowMetric) TagList() []*proto.Tag

func (*RowMetric) Time added in v1.0.2

func (rm *RowMetric) Time() time.Time

type Things

type Things struct {
	Db  *mongo.Database
	Log *logging.Logger
}

func NewThings

func NewThings(db *mongo.Database, log *logging.Logger) *Things

func (*Things) Find

func (t *Things) Find(name string) (*model.Thing, error)

func (*Things) FindPiot

func (t *Things) FindPiot(id string) (*model.Thing, error)

func (*Things) Get

func (t *Things) Get(id primitive.ObjectID) (*model.Thing, error)

func (*Things) GetFiltered

func (t *Things) GetFiltered(filter interface{}) ([]*model.Thing, error)

func (*Things) RegisterPiot

func (t *Things) RegisterPiot(id string, deviceType string) (*model.Thing, error)

func (*Things) SetAvailabilityTopic

func (t *Things) SetAvailabilityTopic(id primitive.ObjectID, topic string) error

func (*Things) SetAvailabilityYesNo

func (t *Things) SetAvailabilityYesNo(id primitive.ObjectID, yes, no string) error

func (*Things) SetLocation

func (t *Things) SetLocation(id primitive.ObjectID, lat, lng float64, sat, ts int32) error

func (*Things) SetLocationMqttTopic added in v1.0.4

func (t *Things) SetLocationMqttTopic(id primitive.ObjectID, topic string) error

func (*Things) SetLocationMqttValues added in v1.0.4

func (t *Things) SetLocationMqttValues(id primitive.ObjectID, lat, lng, sat, ts string) error

func (*Things) SetParent

func (t *Things) SetParent(id primitive.ObjectID, id_parent primitive.ObjectID) error

func (*Things) SetSensorClass

func (t *Things) SetSensorClass(id primitive.ObjectID, class string) error

func (*Things) SetSensorMeasurementTopic

func (t *Things) SetSensorMeasurementTopic(id primitive.ObjectID, topic string) error

func (*Things) SetSensorValue

func (t *Things) SetSensorValue(id primitive.ObjectID, value string) error

func (*Things) SetSwitchState

func (t *Things) SetSwitchState(id primitive.ObjectID, value bool) error

func (*Things) SetTelemetry

func (t *Things) SetTelemetry(id primitive.ObjectID, telemetry string) error

func (*Things) TouchThing

func (t *Things) TouchThing(id primitive.ObjectID) error

type Users

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

func NewUsers

func NewUsers(log *logging.Logger, db *mongo.Database) *Users

func (*Users) FindByEmail

func (t *Users) FindByEmail(email string) (*model.User, error)

func (*Users) FindUserOrgs

func (t *Users) FindUserOrgs(id primitive.ObjectID) ([]model.Org, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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