clouds

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: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MaxCloudEvents = 10

MaxCloudEvents is the number of cloud events to keep in memory.

Functions

func AddCloud

func AddCloud(cloud *Cloud) error

AddCloud inserts the Cloud to the cloud atlas.

func FlagActuator

func FlagActuator(deviceID string, actuatorID string, action Action, time time.Time, meta edge.Meta)

FlagActuator marks the actuator as dirty so that it will be synced wih the clouds.

func FlagDevice

func FlagDevice(deviceID string, action Action, meta edge.Meta)

FlagDevice marks the device as dirty so that it will be synced with the clouds.

func FlagSensor

func FlagSensor(deviceID string, sensorID string, action Action, time time.Time, meta edge.Meta)

FlagSensor marks the sensor as dirty so that it will be synced wih the clouds.

func GetClouds

func GetClouds() map[string]*Cloud

GetClouds returns the cloud atlas.

func IncludeDevice

func IncludeDevice(deviceID string)

func OnEvent

func OnEvent(cb EventCallback)

OnEvent sets the global EventCallback handler.

func OnStatus

func OnStatus(cb StatusCallback)

OnStatus sets the global StatusCallback handler.

func ReadCloudConfig

func ReadCloudConfig(r io.Reader) error

ReadCloudConfig reads clouds.json into the current configuration.

func RemoveCloud

func RemoveCloud(id string) bool

RemoveCloud pauses the cloud with that id and removes it from the cloud atlas.

func SetDownstream

func SetDownstream(ds Downstream)

SetDownstream changes the global Downstream handler.

func WriteCloudConfig

func WriteCloudConfig(w io.Writer) error

WriteCloudConfig writes the current configurations back to clouds.json.

Types

type Action

type Action int

A Action is performed by the cloud manager to resolve differences between the local stat and the cloud.

const (
	// ActionError indicates that there was an error with this entity.
	ActionError Action = 1 << iota
	// ActionNoSync indicates that this entity should not be synced.
	ActionNoSync
	// ActionSync will synchronoice values from a sensor or actuator.
	ActionSync
	// ActionModify modifiy changes names and metadata.
	ActionModify
	// ActionCreate creates (declares) the device/sensor/actuator at the cloud.
	ActionCreate
	// ActionDelete delete the device/sensor/actuator
	ActionDelete
)

func (Action) MarshalJSON

func (a Action) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

func (Action) String

func (a Action) String() string

func (*Action) UnmarshalJSON

func (a *Action) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler

type Cloud

type Cloud struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	Paused      bool   `json:"paused"`
	Pausing     bool   `json:"pausing"`
	PausingMQTT bool   `json:"pausing_mqtt"`
	REST        string `json:"rest"`
	MQTT        string `json:"mqtt"`

	Registered bool `json:"registered"`

	Events []Event `json:"events"`

	Username string `json:"username"`
	Token    string `json:"token"`

	Status      map[Entity]*Status `json:"-"`
	StatusMutex sync.Mutex         `json:"-"`
	// contains filtered or unexported fields
}

Cloud represents a configuration to access a Waziup Cloud.

func GetCloud

func GetCloud(id string) *Cloud

GetCloud returns the Cloud with the given ID.

func (*Cloud) FlagActuator

func (cloud *Cloud) FlagActuator(deviceID string, actuatorID string, action Action, time time.Time, meta edge.Meta)

FlagActuator marks the actuator as dirty.

func (*Cloud) FlagDevice

func (cloud *Cloud) FlagDevice(deviceID string, action Action, meta edge.Meta)

FlagDevice marks the device as dirty.

func (*Cloud) FlagSensor

func (cloud *Cloud) FlagSensor(deviceID string, sensorID string, action Action, time time.Time, meta edge.Meta)

FlagSensor marks the sensor as dirty.

func (*Cloud) IncludeDevice

func (cloud *Cloud) IncludeDevice(deviceID string)

IncludeDevice tells the cloud to sync with that device, especially to monitor that device at the remote cloud for actuation data.

func (*Cloud) Printf

func (cloud *Cloud) Printf(format string, code int, a ...interface{})

Printf logs some events for this cloud.

func (*Cloud) ResetStatus

func (cloud *Cloud) ResetStatus()

ResetStatus clears the status field.

func (*Cloud) SetPaused

func (cloud *Cloud) SetPaused(paused bool) (int, error)

SetPaused stops or resumes the sync manager.

func (*Cloud) SetToken

func (cloud *Cloud) SetToken(token string) (int, error)

SetToken changes the token (password) that is used for authentication with the waziup cloud.

func (*Cloud) SetUsername

func (cloud *Cloud) SetUsername(username string) (int, error)

SetUsername changes the uswername that is used for authentication with the waziup cloud.

func (*Cloud) Wakeup

func (cloud *Cloud) Wakeup()

type Downstream

type Downstream interface {
	Publish(sender mqtt.Sender, msg *mqtt.Message) int
}

Downstream handles incomming MQTT packets.

type Entity

type Entity struct {
	Device   string `json:"device,omitempty"`
	Sensor   string `json:"sensor,omitempty"`
	Actuator string `json:"actuator,omitempty"`
}

A Entity is either a Device, Sensor or Actuator.

func (Entity) String

func (ent Entity) String() string

type Event

type Event struct {
	Code    int       `json:"code"`
	Message string    `json:"msg"`
	Time    time.Time `json:"time"`
}

Event repesents cloud events.

type EventCallback

type EventCallback func(cloud *Cloud, event Event)

EventCallback is called when a cloud changes its state.

type Meta

type Meta struct {
	NoSync       bool
	SyncInterval time.Duration
}

Meta repesents synchronization instructions based on entity metadata (`.meta` fields).

func NewMeta

func NewMeta(json map[string]interface{}) (meta Meta)

NewMeta reads the json object and exracts a Meta object.

type Status

type Status struct {
	// Remote is the time the cloud is synced to.
	Remote time.Time `json:"remote"`
	// Action to perform.
	Action Action `json:"action"`

	// Wakeup Time
	Wakeup time.Time `json:"wakeup"`
	// Sleep durtion
	Sleep time.Duration `json:"sleep"`

	// Error, if any
	Error error `json:"error,omitempty"`
}

Status describes a single entity.

type StatusCallback

type StatusCallback func(cloud *Cloud, ent Entity, status *Status)

StatusCallback is called when a cloud updates its status.

Jump to

Keyboard shortcuts

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