Documentation
¶
Index ¶
- Constants
- func BoolToFloat(v bool) float64
- func FloatToBool(v float64) bool
- type Action
- type ActionType
- type Auth
- type Condition
- type Config
- type Edge
- type Event
- type EventLevel
- type EventType
- type GpsPos
- type Group
- type Node
- func (n *Node) Desc() string
- func (n *Node) ProcessPoint(pIn Point)
- func (n *Node) SetCmdPending(pending bool)
- func (n *Node) SetState(state int)
- func (n *Node) SetSwUpdateState(state SwUpdateState)
- func (n *Node) State() int
- func (n *Node) ToNodeEdge(parent string) NodeEdge
- func (n *Node) ToUser() User
- func (n *Node) UpdateState() (int, bool)
- type NodeCmd
- type NodeEdge
- type NodeVersion
- type Point
- type PointFilter
- type Points
- func (ps *Points) LatestTime() time.Time
- func (ps *Points) PbEncode() ([]byte, error)
- func (ps *Points) Text(id, typ string, index int) (string, bool)
- func (ps *Points) Value(id, typ string, index int) (float64, bool)
- func (ps *Points) ValueBool(id, typ string, index int) (bool, bool)
- func (ps *Points) ValueInt(id, typ string, index int) (int, bool)
- type Role
- type Rule
- type RuleConfig
- type RuleState
- type Sample
- type SampleAverager
- type SampleFilter
- type Samples
- type StandardResponse
- type SwUpdateState
- type TimeWindowAverager
- type User
- type UserRoles
Constants ¶
const ( SysStateUnknown int = 0 SysStatePowerOff = 1 SysStateOffline = 2 SysStateOnline = 3 )
don't even think about changing the below as it used in communications -- add new numbers if something needs changed/added.
const ( CmdUpdateApp string = "updateApp" CmdPoll = "poll" CmdFieldMode = "fieldMode" )
define valid commands
const ( SampleTypeStartApp string = "startApp" SampleTypeStartSystem = "startSystem" SampleTypeUpdateOS = "updateOS" SampleTypeUpdateApp = "updateApp" SampleTypeSysState = "sysState" )
define common sample types
const ( // general point types PointTypeDescription string = "description" PointTypeScale = "scale" PointTypeOffset = "offset" PointTypeUnits = "units" PointTypeValue = "value" PointTypeValueSet = "valueSet" PointTypeID = "id" PointTypeAddress = "address" PointTypeDebug = "debug" PointTypeInitialized = "initialized" PointTypePollPeriod = "pollPeriod" PointTypeErrorCount = "errorCount" PointTypeErrorCountReset = "errorCountReset" PointTypeErrorCountEOF = "errorCountEOF" PointTypeErrorCountEOFReset = "errorCountEOFReset" PointTypeErrorCountCRC = "errorCountCRC" PointTypeErrorCountCRCReset = "errorCountCRCReset" PointTypeReadOnly = "readOnly" // An device node describes an phyical device -- it may be the // cloud server, gateway, etc NodeTypeDevice = "device" PointTypeCmdPending = "cmdPending" PointTypeSwUpdateState = "swUpdateState" PointTypeStartApp = "startApp" PointTypeStartSystem = "startSystem" PointTypeUpdateOS = "updateOS" PointTypeUpdateApp = "updateApp" PointTypeSysState = "sysState" PointTypeSwUpdateRunning = "swUpdateRunning" PointTypeSwUpdateError = "swUpdateError" PointTypeSwUpdatePercComplete = "swUpdatePercComplete" PointTypeOSVersion = "osVersion" PointTypeAppVersion = "appVersion" PointTypeHwVersion = "hwVersion" // user node describes a system user and is used to control // access to the system (typically through web UI) NodeTypeUser = "user" PointTypeFirstName = "firstName" PointTypeLastName = "lastName" PointTypePhone = "phone" PointTypeEmail = "email" PointTypePass = "pass" // modbus nodes // in modbus land, terminology is a big backwards, client is master, // and server is slave. NodeTypeModbus = "modbus" PointTypeClientServer = "clientServer" PointValueClient = "client" PointValueServer = "server" PointTypePort = "port" PointTypeBaud = "baud" NodeTypeModbusIO = "modbusIo" PointTypeModbusIOType = "modbusIoType" PointValueModbusDiscreteInput = "modbusDiscreteInput" PointValueModbusCoil = "modbusCoil" PointValueModbusInputRegister = "modbusInputRegister" PointValueModbusHoldingRegister = "modbusHoldingRegister" PointTypeDataFormat = "dataFormat" PointValueUINT16 = "uint16" PointValueINT16 = "int16" PointValueUINT32 = "uint32" PointValueINT32 = "int32" PointValueFLOAT32 = "float32" // A group node is used to group users and devices // or generally to add structure to the node graph. NodeTypeGroup = "group" // a rule node describes a rule that may run on the system NodeTypeRule = "rule" NodeTypeRuleCondition = "ruleCondition" NodeTypeRuleAction = "ruleAction" // Transient points that are used for notifications, etc. // These points are not stored in the state state of any node, // but are recorded in the time series database to record history. PointMsgAll = "msgAll" PointMsgUser = "msgUser" )
define common node and point types that have special meaning in the system.
const (
ActionTypeNotify = "notify"
)
define valid action types
Variables ¶
This section is empty.
Functions ¶
func BoolToFloat ¶ added in v0.0.16
BoolToFloat converts bool to float
func FloatToBool ¶ added in v0.0.16
FloatToBool converts a float to bool
Types ¶
type Action ¶ added in v0.0.8
type Action struct {
Type ActionType `json:"type"`
Template string `json:"template"`
}
Action defines actions that can be taken if a rule is active. Template can optionally be used to customize the message that is sent and uses Io Type or IDs to fill in the values. Example might be: JamMonitoring: Alert: {{ description }} is in ALARM state with tank level of {{ tankLevel }}.
type ActionType ¶ added in v0.0.8
type ActionType string
ActionType defines the type of action to take
type Auth ¶ added in v0.0.5
type Auth struct {
Token string `json:"token"`
IsRoot bool `json:"isRoot"`
Email string `json:"email"`
}
Auth is an authentication response.
type Condition ¶ added in v0.0.8
type Condition struct {
SampleType string `json:"sampleType"`
SampleID string `json:"sampleID"`
Value float64 `json:"value"`
Operator string `json:"operator"`
}
Condition defines parameters to look for in a sample. Either SampleType or SampleID (or both) can be set. They can't both be "".
type Event ¶
type Event struct {
Time time.Time
Type EventType
Level EventLevel
Message string
}
Event describes something that happened and might be displayed to user in a a sequential log format.
type EventLevel ¶
type EventLevel int
EventLevel is used to describe the "severity" of the event and can be used to quickly filter the type of events
const ( EventLevelFault EventLevel = 3 EventLevelInfo EventLevelDebug )
define valid events
type EventType ¶
type EventType int
EventType describes an event. Custom applications that build on top of Simple IoT should custom event types at high number above 10,000 to ensure there is not a collision between type IDs. Note, these enums should never change.
const ( EventTypeStartSystem EventType = 10 EventTypeStartApp EventTypeSystemUpdate EventTypeAppUpdate )
define valid events
type GpsPos ¶
type GpsPos struct {
Lat float64 `json:"lat"`
Long float64 `json:"long"`
Fix string `json:"fix"`
NumSat int64 `json:"numSat"`
}
GpsPos describes location and fix information from a GPS
type Group ¶ added in v0.0.5
type Group struct {
ID string `json:"id" boltholdKey:"ID"`
Name string `json:"name"`
Parent string `json:"parent"`
Users []UserRoles `json:"users"`
}
An Group represents a named collection of Users and Devices.
type Node ¶ added in v0.0.12
type Node struct {
ID string `json:"id" boltholdKey:"ID"`
Type string `json:"type"`
Points Points `json:"points"`
Groups []string `json:"groups"`
Rules []string `json:"rules"`
}
Node represents the state of a device. UUID is recommended for ID to prevent collisions is distributed instances.
func (*Node) ProcessPoint ¶ added in v0.0.12
ProcessPoint takes a point for a device and adds/updates its array of points
func (*Node) SetCmdPending ¶ added in v0.0.12
SetCmdPending for device
func (*Node) SetSwUpdateState ¶ added in v0.0.12
func (n *Node) SetSwUpdateState(state SwUpdateState)
SetSwUpdateState for a device
func (*Node) ToNodeEdge ¶ added in v0.0.15
ToNodeEdge converts to data structure used in API requests
func (*Node) UpdateState ¶ added in v0.0.12
UpdateState does routine updates of state (offline status, etc). Returns true if state was updated. We originally considered offline to be when we did not receive data from a remote device for X minutes. However, with points that could represent a config change as well. Eventually we may want to improve this to look at point types, but this is probably OK for now.
type NodeCmd ¶ added in v0.0.12
type NodeCmd struct {
ID string `json:"id,omitempty" boltholdKey:"ID"`
Cmd string `json:"cmd"`
Detail string `json:"detail,omitempty"`
}
NodeCmd represents a command to be sent to a device
type NodeEdge ¶ added in v0.0.15
type NodeEdge struct {
ID string `json:"id" boltholdKey:"ID"`
Type string `json:"type"`
Parent string `json:"parent"`
Points Points `json:"points"`
}
NodeEdge combines node and edge data, used for APIs
func (*NodeEdge) ProcessPoint ¶ added in v0.0.16
ProcessPoint takes a point for a device and adds/updates its array of points
type NodeVersion ¶ added in v0.0.12
NodeVersion represents the device SW version
type Point ¶ added in v0.0.11
type Point struct {
// ID of the sensor that provided the point
ID string `json:"id,omitempty"`
// Type of point (voltage, current, key, etc)
Type string `json:"type,omitempty" boltholdIndex:"Type"`
// Index is used to specify a position in an array such as
// which pump, temp sensor, etc.
Index int `json:"index,omitempty"`
// Time the point was taken
Time time.Time `json:"time,omitempty" boltholdKey:"Time" gob:"-"`
// Duration over which the point was taken. This is useful
// for averaged values to know what time period the value applies
// to.
Duration time.Duration `json:"duration,omitempty"`
// Average OR
// Instantaneous analog or digital value of the point.
// 0 and 1 are used to represent digital values
Value float64 `json:"value,omitempty"`
// Optional text value of the point for data that is best represented
// as a string rather than a number.
Text string `json:"text,omitempty"`
// statistical values that may be calculated over the duration of the point
Min float64 `json:"min,omitempty"`
Max float64 `json:"max,omitempty"`
}
Point is a flexible data structure that can be used to represent a sensor value or a configuration parameter. ID, Type, and Index uniquely identify a point in a device
func PbDecodePoints ¶ added in v0.0.11
PbDecodePoints decode protobuf encoded points
type PointFilter ¶ added in v0.0.11
type PointFilter struct {
// contains filtered or unexported fields
}
PointFilter is used to send points upstream. It only sends the data has changed, and at a max frequency
func NewPointFilter ¶ added in v0.0.11
func NewPointFilter(minSend, periodicSend time.Duration) *PointFilter
NewPointFilter is used to creat a new point filter If points have changed that get sent out at a minSend interval frequency of minSend. All points are periodically sent at lastPeriodicSend interval. Set minSend to 0 for things like config settings where you want them to be sent whenever anything changes.
func (*PointFilter) Add ¶ added in v0.0.11
func (sf *PointFilter) Add(points []Point) []Point
Add adds points and returns points that meet the filter criteria
type Points ¶ added in v0.0.11
type Points []Point
Points is an array of Point
func (*Points) LatestTime ¶ added in v0.0.11
LatestTime returns the latest timestamp of a devices points
func (*Points) Text ¶ added in v0.0.11
Text fetches a text value from an array of points given ID, Type, and Index. If ID or Type are set to "", they are ignored.
func (*Points) Value ¶ added in v0.0.11
Value fetches a value from an array of points given ID, Type, and Index. If ID or Type are set to "", they are ignored.
type Role ¶ added in v0.0.5
type Role string
Role of user
const ( RoleAdmin Role = "admin" RoleUser = "user" )
define standard roles
type Rule ¶ added in v0.0.8
type Rule struct {
ID string `json:"id" boltholdKey:"ID"`
Config RuleConfig `json:"config"`
State RuleState `json:"state"`
}
Rule defines a conditions and actions that are run if condition is true. Global indicates the rule applies to all Devices. The rule config and state is separated so we can make updates to the Rule without config affecting state, and state affecting config as these are typically done by two different entities.
type RuleConfig ¶ added in v0.0.8
type RuleConfig struct {
Description string `json:"description"`
NodeID string `json:"nodeID"`
Conditions []Condition `json:"conditions"`
Actions []Action `json:"actions"`
Repeat time.Duration `json:"repeat"`
}
RuleConfig contains parts of the rule that a users changes
type Sample ¶
type Sample struct {
// ID of the sensor that provided the sample
ID string `json:"id,omitempty"`
// Type of sample (voltage, current, key, etc)
Type string `json:"type,omitempty" boltholdIndex:"Type"`
// Time the sample was taken
Time time.Time `json:"time,omitempty" boltholdKey:"Time" gob:"-"`
// Duration over which the sample was taken. This is useful
// for averaged values to know what time period the value applies
// to.
Duration time.Duration `json:"duration,omitempty"`
// Index is used to specify a position in an array such as
// which pump, temp sensor, etc.
Index int
// Average OR
// Instantaneous analog or digital value of the sample.
// 0 and 1 are used to represent digital values
Value float64 `json:"value,omitempty"`
// statistical values that may be calculated
Min float64 `json:"min,omitempty"`
Max float64 `json:"max,omitempty"`
// Tags are additional attributes used to describe the sample
// You might add things like friendly name, etc.
Tags map[string]string `json:"tags,omitempty"`
// Attributes are additional numerical values
Attributes map[string]float64 `json:"attributes,omitempty"`
}
Sample represents a value in time and should include data that may be graphed. The Sample data structure is obsolete and has been replaced by Point
func PbDecodeSamples ¶ added in v0.0.9
PbDecodeSamples decode protobuf encoded samples
func PbToSample ¶ added in v0.0.9
PbToSample converts pb sample to sample
type SampleAverager ¶
type SampleAverager struct {
// contains filtered or unexported fields
}
SampleAverager accumulates samples, and averages them. The average can be reset.
func NewSampleAverager ¶
func NewSampleAverager(sampleType string) *SampleAverager
NewSampleAverager initializes and returns an averager
func (*SampleAverager) AddSample ¶
func (sa *SampleAverager) AddSample(s Sample)
AddSample takes a sample, and adds it to the total
func (*SampleAverager) GetAverage ¶
func (sa *SampleAverager) GetAverage() Sample
GetAverage returns the average of the accumulated samples
func (*SampleAverager) ResetAverage ¶
func (sa *SampleAverager) ResetAverage()
ResetAverage sets the accumulated total to zero
type SampleFilter ¶ added in v0.0.10
type SampleFilter struct {
// contains filtered or unexported fields
}
SampleFilter is used to send samples upstream. It only sends the data has changed, and at a max frequency
func NewSampleFilter ¶ added in v0.0.10
func NewSampleFilter(minSend, periodicSend time.Duration) *SampleFilter
NewSampleFilter is used to creat a new sample filter If samples have changed that get sent out at a minSend interval frequency of minSend. All samples are periodically sent at lastPeriodicSend interval. Set minSend to 0 for things like config settings where you want them to be sent whenever anything changes.
func (*SampleFilter) Add ¶ added in v0.0.10
func (sf *SampleFilter) Add(samples []Sample) []Sample
Add adds samples and returns samples that meet the filter criteria
type StandardResponse ¶
type StandardResponse struct {
Success bool `json:"success"`
Error string `json:"error,omitempty"`
ID string `json:"id,omitempty"`
}
StandardResponse is the standard response to any request
type SwUpdateState ¶ added in v0.0.9
type SwUpdateState struct {
Running bool `json:"running"`
Error string `json:"error"`
PercentDone int `json:"percentDone"`
}
SwUpdateState represents the state of an update
type TimeWindowAverager ¶
type TimeWindowAverager struct {
// contains filtered or unexported fields
}
TimeWindowAverager accumulates samples, and averages them on a fixed time period and outputs the average/min/max, etc as a sample
func NewTimeWindowAverager ¶
func NewTimeWindowAverager(windowLen time.Duration, callBack func(Sample), sampleType string) *TimeWindowAverager
NewTimeWindowAverager initializes and returns an averager
func (*TimeWindowAverager) NewSample ¶
func (twa *TimeWindowAverager) NewSample(s Sample)
NewSample takes a sample, and if the time window expired, it calls the callback function with the a new sample which is avg of all samples since start time.
type User ¶
type User struct {
ID string `json:"id" boltholdKey:"ID"`
FirstName string `json:"firstName"`
LastName string `json:"lastName"`
Phone string `json:"phone"`
Email string `json:"email"`
Pass string `json:"pass"`
}
User represents a user of the system