Documentation ¶
Overview ¶
Copyright © 2022 Nicolas MASSE
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Copyright © 2022 Nicolas MASSE ¶
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Copyright © 2022 Nicolas MASSE ¶
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Index ¶
Constants ¶
const ( MQTT_QOS_0 = 0 // QoS 1 MQTT_QOS_1 = 1 // QoS 2 MQTT_QOS_2 = 2 // QoS 3 )
Those flags define the MQTT Quality of Service (QoS) levels
const ( // How many in-flight MQTT messages to buffer MESSAGE_CHANNEL_LENGTH = 10 // SQL Query to store current data UpsertCurrentQuery string = ` INSERT INTO current VALUES ($1, $2, $3) ON CONFLICT (timestamp, phase) DO UPDATE SET current = excluded.current` // SQL Query to store power data UpsertPowerQuery string = ` INSERT INTO power VALUES ($1, $2) ON CONFLICT (timestamp) DO UPDATE SET power = excluded.power` // SQL Query to store energy data UpsertEnergyQuery string = ` INSERT INTO energy VALUES ($1, $2, $3) ON CONFLICT (timestamp, tariff) DO UPDATE SET reading = excluded.reading` )
Variables ¶
var SqlMigrationFS embed.FS
SqlMigrationFS stores a list of database schema migration scripts
Functions ¶
func NewMqttClient ¶
func NewMqttClient(config MqttConfig) (mqtt.Client, error)
NewMqttClient creates a new MQTT client and connects to the broker
func SetMqttLogger ¶
SetMqttLogger sets the logger to be used by the underlying MQTT library
Types ¶
type MqttConfig ¶
type MqttConfig struct { BrokerURL string // broker url (tcp://hostname:port or ssl://hostname:port) Username string // username (optional) Password string // password (optional) ClientID string // MQTT ClientID Timeout time.Duration // how much time to wait for connect and subscribe operations to complete GracePeriod time.Duration // how much time to wait for the disconnect operation to complete }
An MqttConfig represents the required information to connect to an MQTT broker.
type Processor ¶
type Processor struct { Config ProcessorConfig // the configuration // contains filtered or unexported fields }
A Processor receives events from the MQTT broker and saves data to the database
func NewProcessor ¶
func NewProcessor(c ProcessorConfig) *Processor
NewProcessor creates a new processor from its configuration
type ProcessorConfig ¶
type ProcessorConfig struct { Sql SqlConfig Mqtt MqttConfig Logger *log.Logger }
A ProcessorConfig stores the configuration of a processor
type SqlConfig ¶
type SqlConfig struct {
Url string // Database URL (driver://user:password@hostname:port/db?opts)
}
An SqlConfig stores connection details to the database
type TicMessage ¶
type TicMessage struct { Timestamp UnixEpoch `json:"ts"` Field string `json:"-"` Value string `json:"val"` }
A TicMessage represents data received from the TIC (Tele Information Client)
type UnixEpoch ¶
A UnixEpoch is a time.Time that serializes / deserializes as Unix epoch
func (UnixEpoch) MarshalJSON ¶
MarshalJSON returns the current value as JSON
func (*UnixEpoch) UnmarshalJSON ¶
UnmarshalJSON initialises the current object from its JSON representation