edge

package
v0.0.0-...-2d054f7 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2024 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Codecs = map[string]Codec{}
View Source
var DefaultInterval = time.Second * 5

DefaultInterval for sync.

View Source
var ErrNotFound = CodeError{404, "device or sensor/actuator not found"}

ErrNotFound is returned when the entity was not found.

View Source
var ScriptExecutors = map[string]ScriptExecutor{}

Functions

func AddUser

func AddUser(user *User) error

AddUser creates a new user.

func CheckCustomJSCodecsAvailable

func CheckCustomJSCodecsAvailable() error

TODO: use proper logging and error handling

func Connect

func Connect(addr string) error

func ConnectWithInfo

func ConnectWithInfo(info *mgo.DialInfo) error

ConnectWithInfo initializes the edge core by connecting to the database.

func DeleteActuator

func DeleteActuator(deviceID string, actuatorID string) (int, error)

DeleteActuator removes this actuator from the device and deletes all data points. This returns the number of data points deleted.

func DeleteCodec

func DeleteCodec(id string) error

func DeleteSensor

func DeleteSensor(deviceID string, sensorID string) (int, error)

DeleteSensor removes this sensor from the device and deletes all data points. This returns the number of data points deleted.

func DeleteUser

func DeleteUser(userID string) error

DeleteUser removes the giveb user.

func GenerateNewGatewayID

func GenerateNewGatewayID() string

GenerateNewGatewayID generated a new ID for the gateway that will be Unique and Random

func GetConfig

func GetConfig(key string) (string, error)

GetConfig returns the Wazigate user

func GetDeviceMeta

func GetDeviceMeta(deviceID string) (map[string]interface{}, error)

GetDeviceMeta returns the metadata of that device.

func GetDeviceName

func GetDeviceName(deviceID string) (string, error)

GetDeviceName returns the name of that device.

func GetMessages

func GetMessages(query *MessagesQuery) *messagesIterator

func LocalID

func LocalID() string

LocalID returns the ID of this device

func MakeDefaultUser

func MakeDefaultUser() error

MakeDefaultUser checks if there is no user registered in database, it makes a default user user: admin pass: loragateway

func MarshalDevice

func MarshalDevice(deviceID string, headers http.Header, w io.Writer) (string, error)

MarshalDevice writes complex data to the device. This might be JSON data, LoRaWAN XLPP payload or something else.

func NewError

func NewError(code int, text string) error

func NewErrorf

func NewErrorf(code int, format string, a ...interface{}) error

func PostActuator

func PostActuator(deviceID string, actuator *Actuator) error

PostActuator creates a new actuator for this device.

func PostCodec

func PostCodec(codec *ScriptCodec) error

func PostDevices

func PostDevices(device *Device) error

PostDevices creates a new device a the database.

func PostMessage

func PostMessage(m *Message) error

func PostSensor

func PostSensor(deviceID string, sensor *Sensor) error

PostSensor creates a new sensor for this device.

func SetActuatorMeta

func SetActuatorMeta(deviceID string, actuatorID string, meta map[string]interface{}) error

SetActuatorMeta changes this actuators metadata.

func SetConfig

func SetConfig(key string, value string) error

SetConfig saved a new value for a config key and creates if it does not exist

func SetDeviceID

func SetDeviceID(newID string) error

SetDeviceID changes the gateway ID.

func SetDeviceMeta

func SetDeviceMeta(deviceID string, meta Meta) error

SetDeviceMeta changes a device metadata.

func SetSensorMeta

func SetSensorMeta(deviceID string, sensorID string, meta Meta) error

SetSensorMeta changes this sensors metadata.

func SetSensorMetaField

func SetSensorMetaField(deviceID string, sensorID string, field string, value interface{}) error

func UnmarshalDevice

func UnmarshalDevice(deviceID string, headers http.Header, r io.Reader) error

UnmarshalDevice writes complex data to the device. This might be JSON data, LoRaWAN XLPP payload or something else.

func UpdateUser

func UpdateUser(userID string, newProfileData *User) error

Types

type Actuator

type Actuator struct {
	ID   string `json:"id" bson:"id"`
	Name string `json:"name" bson:"name"`

	Modified time.Time `json:"modified" bson:"modified"`
	Created  time.Time `json:"created" bson:"created"`

	Time  *time.Time  `json:"time" bson:"time"`
	Value interface{} `json:"value" bson:"value"`

	Meta Meta `json:"meta" bson:"meta"`
	// contains filtered or unexported fields
}

Actuator represents a Waziup actuator

func GetActuator

func GetActuator(deviceID string, actuatorID string) (*Actuator, error)

GetActuator returns the Waziup actuator.

func (*Actuator) MarshalJSON

func (actuator *Actuator) MarshalJSON() ([]byte, error)

func (*Actuator) SetJSONSelect

func (actuator *Actuator) SetJSONSelect(s []string)

type CodeError

type CodeError struct {
	Code int
	Text string
}

CodeError is a error with a code (like 404 Not Found).

func (CodeError) Error

func (e CodeError) Error() string

type Codec

type Codec interface {
	UnmarshalDevice(deviceID string, headers http.Header, r io.Reader) error
	MarshalDevice(deviceID string, headers http.Header, w io.Writer) error
	CodecName() string
}

func FindCodec

func FindCodec(deviceID string, contentType string) (name string, codec Codec, err error)

type CodecsIter

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

CodecsIter iterates over codecs. Call .Next() to get the next codec.

func GetCodecs

func GetCodecs() *CodecsIter

GetCodecs returns an iterator over all codecs.

func (*CodecsIter) Close

func (iter *CodecsIter) Close() error

Close closes the iterator.

func (*CodecsIter) Next

func (iter *CodecsIter) Next() (*ScriptCodec, error)

Next returns the next codec or nil.

type Config

type Config struct {
	Key   string `json:"key" bson:"key"`
	Value string `json:"value" bson:"value"`
}

Config represents a Wazigate edge Config

type Device

type Device struct {
	Name      string      `json:"name" bson:"name"`
	ID        string      `json:"id" bson:"_id"`
	Sensors   []*Sensor   `json:"sensors" bson:"sensors"`
	Actuators []*Actuator `json:"actuators" bson:"actuators"`
	Modified  time.Time   `json:"modified" bson:"modified"`
	Created   time.Time   `json:"created" bson:"created"`
	Meta      Meta        `json:"meta" bson:"meta"`
	// contains filtered or unexported fields
}

Device represents a Waziup Device.

func DeleteDevice

func DeleteDevice(deviceID string) (*Device, int, int, error)

DeleteDevice removes the device and all sensor and actuator values from the database. This returns the removed device and the number of sensor and actuator values that were removed.

func GetDevice

func GetDevice(deviceID string) (*Device, error)

GetDevice returns the Waziup device with that id.

func (*Device) MarshalJSON

func (device *Device) MarshalJSON() ([]byte, error)

func (*Device) SetJSONSelect

func (device *Device) SetJSONSelect(s []string)

type DeviceIterator

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

DeviceIterator iterates over devices. Call .Next() to get the next device.

func GetDevices

func GetDevices(query *Query) *DeviceIterator

GetDevices returns an iterator over all devices.

func (*DeviceIterator) Close

func (iter *DeviceIterator) Close() error

Close closes the iterator.

func (*DeviceIterator) Next

func (iter *DeviceIterator) Next() (*Device, error)

Next returns the next device or nil.

type Message

type Message struct {
	ID              bson.ObjectId `json:"id" bson:"_id"`
	Text            string        `json:"text" bson:"text"`
	Title           string        `json:"title" bson:"title"`
	Severity        string        `json:"severity" bson:"severity"`
	HRef            string        `json:"href" bson:"href"`
	Target          string        `json:"target" bson:"target"`
	Time            time.Time     `json:"time" bson:"time"`
	DisplayDuration int           `json:"displayDuration" bson:"displayDuration"`
}

type MessagesQuery

type MessagesQuery struct {
	Limit int64
	From  time.Time
	To    time.Time
}

func (*MessagesQuery) Parse

func (query *MessagesQuery) Parse(req *http.Request) string

Parse reads url.Values into the DevicesQuery.

type Meta

type Meta map[string]interface{}

Meta holds entity metadata.

func PostActuatorValue

func PostActuatorValue(deviceID string, actuatorID string, val Value) (Meta, error)

PostActuatorValue stores a new actuator value for this actuator.

func PostActuatorValues

func PostActuatorValues(deviceID string, actuatorID string, vals []Value) (Meta, error)

PostActuatorValues can be used to post multiple data point for this actuator.

func PostSensorValue

func PostSensorValue(deviceID string, sensorID string, val Value) (Meta, error)

PostSensorValue stores a new sensor value for this sensor.

func PostSensorValues

func PostSensorValues(deviceID string, sensorID string, vals []Value) (Meta, error)

PostSensorValues can be used to post multiple data point for this sensor.

func SetActuatorName

func SetActuatorName(deviceID string, actuatorID string, name string) (Meta, error)

SetActuatorName changes this actuators name.

func SetDeviceName

func SetDeviceName(deviceID string, name string) (Meta, error)

SetDeviceName changes a device name.

func SetSensorName

func SetSensorName(deviceID string, sensorID string, name string) (Meta, error)

SetSensorName changes this sensors name.

func (Meta) DoNotSync

func (meta Meta) DoNotSync() bool

DoNotSync = do not sync with clouds

func (Meta) SyncInterval

func (meta Meta) SyncInterval() time.Duration

SyncInterval = min time between syncs

type Query

type Query struct {
	Limit  int64
	Size   int64
	Meta   []string
	Select []string
}

Query is used to range or limit query results.

func (*Query) Parse

func (query *Query) Parse(values url.Values) error

Parse reads url.Values into the DevicesQuery.

type ScriptCodec

type ScriptCodec struct {
	ID        string `json:"id" bson:"_id"`
	Internal  bool   `json:"internal" bson:"-"`
	Name      string `json:"name" bson:"name"`
	ServeMime string `json:"serveMime" bson:"serveMime"`
	Mime      string `json:"mime" bson:"mime"`
	Script    string `json:"script" bson:"script"`
}

func (ScriptCodec) CodecName

func (codec ScriptCodec) CodecName() string

func (*ScriptCodec) MarshalDevice

func (script *ScriptCodec) MarshalDevice(deviceID string, headers http.Header, w io.Writer) error

func (*ScriptCodec) UnmarshalDevice

func (script *ScriptCodec) UnmarshalDevice(deviceID string, headers http.Header, r io.Reader) error

type ScriptExecutor

type ScriptExecutor interface {
	UnmarshalDevice(script *ScriptCodec, deviceID string, headers http.Header, r io.Reader) error
	MarshalDevice(script *ScriptCodec, deviceID string, headers http.Header, w io.Writer) error
	ExecutorName() string
}

type Sensor

type Sensor struct {
	ID   string `json:"id" bson:"id"`
	Name string `json:"name" bson:"name"`

	Modified time.Time `json:"modified" bson:"modified"`
	Created  time.Time `json:"created" bson:"created"`

	Kind     ontology.SensingKind `json:"kind" bson:"kind"`
	Quantity ontology.Quantity    `json:"quantity" bson:"quantity"`
	Unit     ontology.Unit        `json:"unit" bson:"unit"`

	Time  *time.Time  `json:"time" bson:"time"`
	Value interface{} `json:"value" bson:"value"`

	Meta Meta `json:"meta" bson:"meta"`
	// contains filtered or unexported fields
}

Sensor represents a Waziup sensor

func GetSensor

func GetSensor(deviceID string, sensorID string) (*Sensor, error)

GetSensor returns the Waziup sensor.

func (*Sensor) MarshalJSON

func (sensor *Sensor) MarshalJSON() ([]byte, error)

func (*Sensor) SetJSONSelect

func (sensor *Sensor) SetJSONSelect(s []string)

type User

type User struct {
	ID          string `json:"id" bson:"_id"`
	Name        string `json:"name" bson:"name"`
	Username    string `json:"username" bson:"username"`
	Password    string `json:"password" bson:"password"`
	NewPassword string `json:"newPassword"`
}

User represents a Wazigate user

func CheckUserCredentials

func CheckUserCredentials(username string, password string) (User, error)

func FindUserByUsername

func FindUserByUsername(username string) (User, error)

FindUserByUsername finds and returns the Wazigate user based on a given username

func GetUser

func GetUser(userID string) (User, error)

GetUser returns the Wazigate user

type Value

type Value struct {
	Value interface{} `json:"value" bson:"value"`
	Time  time.Time   `json:"time" bson:"time"`
}

Value is one datapoint

func NewValue

func NewValue(v interface{}, time time.Time) Value

NewValue creates a new data-point.

type ValueIterator

type ValueIterator interface {
	Next() (Value, error)
	Close() error
}

ValueIterator iterates over data points. Call .Next() to get the next value.

func GetActuatorValues

func GetActuatorValues(deviceID string, actuatorID string, query *ValuesQuery) ValueIterator

GetActuatorValues returns an iterator over all actuator values.

func GetSensorValues

func GetSensorValues(deviceID string, sensorID string, query *ValuesQuery) ValueIterator

GetSensorValues returns an iterator over all sensor values.

type ValuesQuery

type ValuesQuery struct {
	Limit int64
	From  time.Time
	To    time.Time
	Size  int64
}

ValuesQuery is used to range or limit query results.

func (*ValuesQuery) Parse

func (query *ValuesQuery) Parse(req *http.Request) string

Parse parses the HTTP Request into the Query parameters.

Directories

Path Synopsis
codecs

Jump to

Keyboard shortcuts

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