Documentation ¶
Overview ¶
Package data contains common data structures that are used throughout the project.
Encode, Decode, MergePoints, and MergeEdgePoints can be used to convert your custom types to/from the NodeEdge type that SIOT uses for its wire and storage format.
Index ¶
- Constants
- Variables
- func BoolToFloat(v bool) float64
- func Decode(input NodeEdgeChildren, output interface{}) error
- func FloatToBool(v float64) bool
- func MergeEdgePoints(id, parent string, points []Point, output interface{}) error
- func MergePoints(id string, points []Point, output interface{}) error
- type Auth
- type ByEdgeID
- type ByHash
- type Config
- type Edge
- type Event
- type EventLevel
- type EventType
- type GpsPos
- type Message
- type MsgService
- type Node
- type NodeCmd
- type NodeEdge
- func Encode(in interface{}) (NodeEdge, error)
- func PbDecodeNode(data []byte) (NodeEdge, error)
- func PbDecodeNodeRequest(buf []byte) (NodeEdge, error)
- func PbDecodeNodes(data []byte) ([]NodeEdge, error)
- func PbDecodeNodesRequest(data []byte) ([]NodeEdge, error)
- func PbToNode(pbNode *pb.Node) (NodeEdge, error)
- func RemoveDuplicateNodesID(nodes []NodeEdge) []NodeEdge
- func RemoveDuplicateNodesIDParent(nodes []NodeEdge) []NodeEdge
- func (n *NodeEdge) AddPoint(pIn Point)
- func (n NodeEdge) CalcHash(children []NodeEdge) uint32
- func (n NodeEdge) Desc() string
- func (n NodeEdge) IsTombstone() (bool, time.Time)
- func (n NodeEdge) String() string
- func (n *NodeEdge) ToNode() Node
- func (n *NodeEdge) ToPb() ([]byte, error)
- func (n *NodeEdge) ToPbNode() (*pb.Node, error)
- type NodeEdgeChildren
- type NodeVersion
- type Nodes
- type Notification
- type Point
- type PointAverager
- type PointFilter
- type Points
- func (ps *Points) Add(pIn Point)
- func (ps Points) Desc() string
- func (ps *Points) Find(typ, key string) (Point, bool)
- func (ps *Points) Hash() uint32
- func (ps *Points) LatestTime() time.Time
- func (ps Points) Len() int
- func (ps Points) Less(i, j int) bool
- func (ps Points) String() string
- func (ps Points) Swap(i, j int)
- func (ps *Points) Text(typ, key string) (string, bool)
- func (ps *Points) ToPb() ([]byte, error)
- func (ps *Points) Value(typ, key string) (float64, bool)
- func (ps *Points) ValueBool(typ, key string) (bool, bool)
- func (ps *Points) ValueInt(typ, key string) (int, bool)
- type StandardResponse
- type SwUpdateState
- type TimeWindowAverager
- type User
Constants ¶
const ( CmdUpdateApp string = "updateApp" CmdPoll = "poll" CmdFieldMode = "fieldMode" )
define valid commands
const ( // general point types PointTypeChannel string = "channel" PointTypeDevice = "device" PointTypeDescription = "description" PointTypeFilePath = "filePath" PointTypeNodeType = "nodeType" PointTypeTombstone = "tombstone" PointTypeScale = "scale" PointTypeOffset = "offset" PointTypeUnits = "units" PointTypeValue = "value" PointTypeValueSet = "valueSet" PointTypeIndex = "index" // PointTypeID typically refers to Node ID PointTypeID = "id" PointTypeAddress = "address" PointTypeDebug = "debug" PointTypeInitialized = "initialized" PointTypePollPeriod = "pollPeriod" PointTypeErrorCount = "errorCount" PointTypeErrorCountReset = "errorCountReset" PointTypeErrorCountEOF = "errorCountEOF" PointTypeErrorCountEOFReset = "errorCountEOFReset" PointTypeErrorCountCRC = "errorCountCRC" PointTypeErrorCountCRCReset = "errorCountCRCReset" PointTypeSyncCount = "syncCount" PointTypeSyncCountReset = "syncCountReset" PointTypeReadOnly = "readOnly" PointTypeURI = "uri" PointTypeDisable = "disable" PointTypePeriod = "period" // 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" PointValueSysStateUnknown = "unknown" PointValueSysStatePowerOff = "powerOff" PointValueSysStateOffline = "offline" PointValueSysStateOnline = "online" PointTypeSwUpdateRunning = "swUpdateRunning" PointTypeSwUpdateError = "swUpdateError" PointTypeSwUpdatePercComplete = "swUpdatePercComplete" PointTypeVersionOS = "versionOS" PointTypeVersionApp = "versionApp" PointTypeVersionHW = "versionHW" // 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" // user edge points PointTypeRole = "role" PointValueRoleAdmin = "admin" PointValueRoleUser = "user" // User Authentication NodeTypeJWT = "jwt" PointTypeToken = "token" // 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" PointTypeProtocol = "protocol" PointValueRTU = "RTU" PointValueTCP = "TCP" NodeTypeModbusIO = "modbusIo" PointTypeModbusIOType = "modbusIoType" PointValueModbusDiscreteInput = "modbusDiscreteInput" PointValueModbusCoil = "modbusCoil" PointValueModbusInputRegister = "modbusInputRegister" PointValueModbusHoldingRegister = "modbusHoldingRegister" PointTypeDataFormat = "dataFormat" PointValueUINT16 = "uint16" PointValueINT16 = "int16" PointValueUINT32 = "uint32" PointValueINT32 = "int32" PointValueFLOAT32 = "float32" NodeTypeOneWire = "oneWire" NodeTypeOneWireIO = "oneWireIO" // A group node is used to group users and devices // or generally to add structure to the node graph. NodeTypeGroup = "group" NodeTypeDb = "db" PointTypeBucket = "bucket" PointTypeOrg = "org" // a rule node describes a rule that may run on the system NodeTypeRule = "rule" PointTypeActive = "active" NodeTypeCondition = "condition" PointTypeConditionType = "conditionType" PointValuePointValue = "pointValue" PointValueSchedule = "schedule" PointTypeTrigger = "trigger" PointTypeStart = "start" PointTypeEnd = "end" PointTypeWeekday = "weekday" PointTypePointID = "pointID" PointTypePointKey = "pointKey" PointTypePointType = "pointType" PointTypePointIndex = "pointIndex" PointTypeValueType = "valueType" PointValueNumber = "number" PointValueOnOff = "onOff" PointValueText = "text" PointTypeOperator = "operator" PointValueGreaterThan = ">" PointValueLessThan = "<" PointValueEqual = "=" PointValueNotEqual = "!=" PointValueOn = "on" PointValueOff = "off" PointValueContains = "contains" PointTypeValueText = "valueText" PointTypeMinActive = "minActive" NodeTypeAction = "action" NodeTypeActionInactive = "actionInactive" PointTypeAction = "action" PointValueNotify = "notify" PointValueSetValue = "setValue" PointValuePlayAudio = "playAudio" // Transient points that are used for notifications, etc. // These points are not stored in the state of any node, // but are recorded in the time series database to record history. PointMsgAll = "msgAll" PointMsgUser = "msgUser" NodeTypeMsgService = "msgService" PointTypeService = "service" PointValueTwilio = "twilio" PointValueSMTP = "smtp" PointTypeSID = "sid" PointTypeAuthToken = "authToken" PointTypeFrom = "from" NodeTypeVariable = "variable" PointTypeVariableType = "variableType" NodeTypeSync = "sync" PointTypeMetricNatsCycleNodePoint = "metricNatsCycleNodePoint" PointTypeMetricNatsCycleNodeEdgePoint = "metricNatsCycleNodeEdgePoint" PointTypeMetricNatsCycleNode = "metricNatsCycleNode" PointTypeMetricNatsCycleNodeChildren = "metricNatsCycleNodeChildren" PointTypeMetricNatsPendingNodePoint = "metricNatsPendingNodePoint" PointTypeMetricNatsPendingNodeEdgePoint = "metricNatsPendingNodeEdgePoint" PointTypeMetricNatsThroughputNodePoint = "metricNatsThroughputNodePoint" PointTypeMetricNatsThroughputNodeEdgePoint = "metricNatsThroughputNodeEdgePoint" // serial MCU clients NodeTypeSerialDev = "serialDev" PointTypeRx = "rx" PointTypeTx = "tx" PointTypeRxReset = "rxReset" PointTypeTxReset = "txReset" PointTypeLog = "log" PointTypeUptime = "uptime" PointTypeMaxMessageLength = "maxMessageLength" // CAN bus clients NodeTypeCanBus = "canBus" PointTypeMsgsInDb = "msgsInDb" PointTypeSignalsInDb = "signalsInDb" PointTypeMsgsRecvdDb = "msgsRecvdDb" PointTypeMsgsRecvdDbReset = "msgsRecvdDbReset" PointTypeMsgsRecvdOther = "msgsRecvdOther" PointTypeMsgsRecvdOtherReset = "msgsRecvdOtherReset" NodeTypeCanDatabase = "canDatabase" NodeTypeSignalGenerator = "signalGenerator" PointTypeFrequency = "frequency" PointTypeAmplitude = "amplitude" PointTypeSampleRate = "sampleRate" NodeTypeFile = "file" PointTypeName = "name" PointTypeData = "data" )
define common node and point types that have special meaning in the system.
Variables ¶
var ErrDocumentNotFound = errors.New("document not found")
ErrDocumentNotFound is returned in APIs if document is not found
Functions ¶
func BoolToFloat ¶ added in v0.0.16
BoolToFloat converts bool to float
func Decode ¶ added in v0.3.0
func Decode(input NodeEdgeChildren, output interface{}) error
Decode converts a Node to custom struct. output can be a struct type that contains node, point, and edgepoint tags as shown below. It is recommended that id and parent node tags always be included.
type exType struct { ID string `node:"id"` Parent string `node:"parent"` Description string `point:"description"` Count int `point:"count"` Role string `edgepoint:"role"` Tombstone bool `edgepoint:"tombstone"` Conditions []Condition `child:"condition"` }
output can also be a *reflect.Value
func FloatToBool ¶ added in v0.0.16
FloatToBool converts a float to bool
func MergeEdgePoints ¶ added in v0.3.0
MergeEdgePoints takes edge points and updates a type that matching edgepoint tags. See Decode for an example type.
Types ¶
type ByEdgeID ¶ added in v0.0.30
type ByEdgeID []*Edge
ByEdgeID implements sort interface for NodeEdge by ID
type ByHash ¶ added in v0.0.30
type ByHash []*Edge
ByHash implements sort interface for NodeEdge by Hash
type Edge ¶ added in v0.0.15
type Edge struct { ID string `json:"id"` Up string `json:"up"` Down string `json:"down"` Points Points `json:"points"` Hash uint32 `json:"hash"` Type string `json:"type"` }
Edge is used to describe the relationship between two nodes
func (*Edge) IsTombstone ¶ added in v0.0.30
IsTombstone returns true of edge points to a deleted node
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 Message ¶ added in v0.0.23
type Message struct { ID string UserID string ParentID string NotificationID string Email string Phone string Subject string Message string }
Message describes a notification that is sent to a particular user
func PbDecodeMessage ¶ added in v0.0.23
PbDecodeMessage converts a protobuf to a message data structure
type MsgService ¶ added in v0.0.23
MsgService is used to represent message services such as Twilio, SMTP, etc
func NodeToMsgService ¶ added in v0.0.23
func NodeToMsgService(node Node) (MsgService, error)
NodeToMsgService converts a node to message service
type Node ¶ added in v0.0.12
type Node struct { ID string `json:"id" boltholdKey:"ID"` Type string `json:"type"` Points Points `json:"points"` }
Node represents the state of a device. UUID is recommended for ID to prevent collisions is distributed instances.
func (*Node) GetState ¶ added in v0.0.30
GetState checks state of node and 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 (perhaps Sample).
func (*Node) ToNodeEdge ¶ added in v0.0.15
ToNodeEdge converts to data structure used in API requests
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"` Hash uint32 `json:"hash"` Parent string `json:"parent"` Points Points `json:"points"` EdgePoints Points `json:"edgePoints"` }
NodeEdge combines node and edge data, used for APIs
func Encode ¶ added in v0.3.0
Encode is used to convert a user struct to a node. in must be a struct type that contains node, point, and edgepoint tags as shown below. It is recommended that id and parent node tags always be included.
type exType struct { ID string `node:"id"` Parent string `node:"parent"` Description string `point:"description"` Count int `point:"count"` Role string `edgepoint:"role"` Tombstone bool `edgepoint:"tombstone"` }
func PbDecodeNode ¶ added in v0.0.22
PbDecodeNode converts a protobuf to node data structure
func PbDecodeNodeRequest ¶ added in v0.0.30
PbDecodeNodeRequest converts a protobuf to node data structure
func PbDecodeNodes ¶ added in v0.0.30
PbDecodeNodes decode probuf encoded nodes
func PbDecodeNodesRequest ¶ added in v0.0.30
PbDecodeNodesRequest decode probuf encoded nodes
func RemoveDuplicateNodesID ¶ added in v0.0.23
RemoveDuplicateNodesID removes duplicate nodes in list with the same ID (can have different parents)
func RemoveDuplicateNodesIDParent ¶ added in v0.0.23
RemoveDuplicateNodesIDParent removes duplicate nodes in list with the same ID and parent
func (*NodeEdge) AddPoint ¶ added in v0.0.44
AddPoint takes a point for a device and adds/updates its array of points
func (NodeEdge) IsTombstone ¶ added in v0.0.30
IsTombstone returns Tombstone value and timestamp
type NodeEdgeChildren ¶ added in v0.5.0
type NodeEdgeChildren struct { NodeEdge NodeEdge Children []NodeEdgeChildren }
NodeEdgeChildren is used to pass a tree node structure into the decoder
type NodeVersion ¶ added in v0.0.12
NodeVersion represents the device SW version
type Nodes ¶ added in v0.0.30
type Nodes []NodeEdge
Nodes defines a list of nodes
type Notification ¶ added in v0.0.23
type Notification struct { ID string `json:"id"` Parent string `json:"parent"` SourceNode string `json:"sourceNode"` Subject string `json:"subject"` Message string `json:"message"` }
Notification represents a message sent by a node
func PbDecodeNotification ¶ added in v0.0.23
func PbDecodeNotification(data []byte) (Notification, error)
PbDecodeNotification converts a protobuf to notification data structure
func (*Notification) ToPb ¶ added in v0.0.23
func (n *Notification) ToPb() ([]byte, error)
ToPb converts to protobuf data
type Point ¶ added in v0.0.11
type Point struct { // Type of point (voltage, current, key, etc) Type string `json:"type,omitempty"` // Key is used to allow a group of points to represent a "map" Key string `json:"key,omitempty"` // Time the point was taken Time time.Time `json:"time,omitempty"` // Index is used to specify a position in an array such as // which pump, temp sensor, etc. Index float64 `json:"index,omitempty"` // 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"` // catchall field for data that does not fit into float or string -- // should be used sparingly Data []byte `json:"data,omitempty"` // Used to indicate a point has been deleted. This value is only // ever incremented. Odd values mean point is deleted. Tombstone int `json:"tombstone,omitempty"` // Where did this point come from. If from the owning node, it may be blank. Origin string `json:"origin"` }
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
type PointAverager ¶ added in v0.0.23
type PointAverager struct {
// contains filtered or unexported fields
}
PointAverager accumulates points, and averages them. The average can be reset.
func NewPointAverager ¶ added in v0.0.23
func NewPointAverager(pointType string) *PointAverager
NewPointAverager initializes and returns an averager
func (*PointAverager) AddPoint ¶ added in v0.0.23
func (pa *PointAverager) AddPoint(s Point)
AddPoint takes a point, and adds it to the total
func (*PointAverager) GetAverage ¶ added in v0.0.23
func (pa *PointAverager) GetAverage() Point
GetAverage returns the average of the accumulated points
func (*PointAverager) ResetAverage ¶ added in v0.0.23
func (pa *PointAverager) ResetAverage()
ResetAverage sets the accumulated total to zero
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 PbDecodePoints ¶ added in v0.0.11
PbDecodePoints decode protobuf encoded points
func (*Points) Add ¶ added in v0.0.44
Add takes a point and updates an existing array of points. Existing points are replaced if the Timestamp in pIn is > than the existing timestamp. If the pIn timestamp is zero, the current time is used.
func (*Points) Find ¶ added in v0.0.30
Find fetches a point given ID, Type, and Index and true of found, or false if not found
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 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
func (*SwUpdateState) Points ¶ added in v0.0.30
func (sws *SwUpdateState) Points() Points
Points converts SW update state to node points
type TimeWindowAverager ¶
type TimeWindowAverager struct {
// contains filtered or unexported fields
}
TimeWindowAverager accumulates points, and averages them on a fixed time period and outputs the average/min/max, etc as a point
func NewTimeWindowAverager ¶
func NewTimeWindowAverager(windowLen time.Duration, callBack func(Point), pointType string) *TimeWindowAverager
NewTimeWindowAverager initializes and returns an averager
func (*TimeWindowAverager) NewPoint ¶ added in v0.0.23
func (twa *TimeWindowAverager) NewPoint(s Point)
NewPoint takes a point, and if the time window expired, it calls the callback function with the a new point which is avg of all points 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
func NodeToUser ¶ added in v0.0.23
NodeToUser converts a node to a user