Documentation
¶
Overview ¶
Package data specifies data structures that are used on the wire.
Index ¶
- Constants
- type Action
- type ActionType
- type Auth
- type Condition
- type Config
- type Data
- type Device
- type DeviceCmd
- type DeviceConfig
- type DeviceState
- type DeviceVersion
- type Event
- type EventLevel
- type EventType
- type GpsPos
- type Group
- type Role
- type Rule
- type RuleConfig
- type RuleState
- type Sample
- type SampleAverager
- type Samples
- type StandardResponse
- type SwUpdateState
- type SysState
- type TimeWindowAverager
- type User
- type UserRoles
Constants ¶
const ( SysStateUnknown SysState = 0 SysStatePowerOff = 1 SysStateOffline = 2 SysStateOnline = 3 )
define valid system states 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 (
ActionTypeNotify = "notify"
)
define valid action types
Variables ¶
This section is empty.
Functions ¶
This section is empty.
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 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 Data ¶ added in v0.0.5
type Data struct {
Groups []Group `json:"groups"`
Users []User `json:"users"`
Devices []Device `json:"devices"`
}
Data provides all application data.
type Device ¶
type Device struct {
ID string `json:"id" boltholdKey:"ID"`
Config DeviceConfig `json:"config"`
State DeviceState `json:"state"`
CmdPending bool `json:"cmdPending"`
SwUpdateState SwUpdateState `json:"swUpdateState"`
Groups []uuid.UUID `json:"groups"`
Rules []uuid.UUID `json:"rules"`
}
Device represents the state of a device The config is typically updated by the portal/UI, and the State is updated by the device. Keeping these datastructures separate reduces the possibility that one update will step on another.
func (*Device) ProcessSample ¶
ProcessSample takes a sample for a device and adds/updates in Ios
func (*Device) UpdateState ¶ added in v0.0.6
UpdateState does routine updates of state (offline status, etc). Returns true if state was updated.
type DeviceCmd ¶
type DeviceCmd struct {
ID string `json:"id,omitempty" boltholdKey:"ID"`
Cmd string `json:"cmd"`
Detail string `json:"detail,omitempty"`
}
DeviceCmd represents a command to be sent to a device
type DeviceConfig ¶
type DeviceConfig struct {
Description string `json:"description"`
}
DeviceConfig represents a device configuration (stuff that is set by user in UI)
type DeviceState ¶
type DeviceState struct {
Version DeviceVersion `json:"version"`
Ios []Sample `json:"ios"`
LastComm time.Time `json:"lastComm"`
SysState SysState `json:"sysState"`
}
DeviceState represents information about a device that is collected, vs set by user.
type DeviceVersion ¶
DeviceVersion represents the device SW version
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 uuid.UUID `json:"id" boltholdKey:"ID"`
Name string `json:"name"`
Parent uuid.UUID `json:"parent"`
Users []UserRoles `json:"users"`
}
An Group represents a named collection of Users and Devices.
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 uuid.UUID `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"`
DeviceID string `json:"deviceID"`
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 {
// Type of sample (voltage, current, key, etc)
Type string `json:"type,omitempty" boltholdIndex:"Type"`
// ID of the sensor that provided the sample
ID string `json:"id,omitempty"`
// 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"`
// Time the sample was taken
Time time.Time `json:"time,omitempty" boltholdKey:"Time" gob:"-"`
// Duration over which the sample was taken
Duration time.Duration `json:"duration,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.
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 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.