feat(pkg/sensor): new support for sensor bme280

This commit is contained in:
2019-06-30 14:34:13 +02:00
parent 96eb1f4036
commit 289aaf2093
20 changed files with 309 additions and 87 deletions

View File

@ -45,6 +45,10 @@ func (h *Humidity) GetMeasuredValueType() MeasuredValueType {
return MeasuredValueTypeHumidity
}
func (h *Humidity) SetValue(value float64) {
h.HumidityValue = value
}
func (h *Humidity) SetTillDate(date time.Time) {
h.HumidityTillDate = date
}

View File

@ -12,6 +12,7 @@ type MeasuredValue interface {
GetCreationDate() *time.Time
GetUpdateDate() *time.Time
SetValue(value float64)
SetTillDate(date time.Time)
SetCreationDate(date *time.Time)
SetUpdateDate(date *time.Time)

View File

@ -13,6 +13,8 @@ type Sensor struct {
SensorName string `json:"sensor_name" xml:"sensor_name"`
SensorLocation string `json:"sensor_location" xml:"sensor_location"`
WireID *string `json:"wire_id" xml:"wire_id"`
I2CBus *int `json:"i2c_bus" xml:"i2c_bus"`
I2CAddress *uint8 `json:"i2c_address" xml:"i2c_address"`
GPIONumber *GPIO `json:"gpio_number" xml:"gpio_number"`
SensorModel SensorModel `json:"sensor_model" xml:"sensor_model"`
SensorEnabled bool `json:"sensor_enabled" xml:"sensor_enabled"`
@ -46,6 +48,9 @@ func (s *Sensor) Name() string {
return s.SensorName
} else if s.WireID != nil {
return *s.WireID
} else if s.I2CAddress != nil &&
s.I2CBus != nil {
return fmt.Sprintf("%v/%v", *s.I2CBus, *s.I2CAddress)
}
return s.SensorID
}

View File

@ -5,7 +5,8 @@ import "fmt"
type SensorModel string
const (
DHT11 SensorModel = "DHT11"
BME280 SensorModel = "BME280"
DHT11 = "DHT11"
DHT22 = "DHT22"
DS18B20 = "DS18B20"
)
@ -13,6 +14,8 @@ const (
// SelectSensorModel converts a string into a constant
func SelectSensorModel(model string) (SensorModel, error) {
switch model {
case "BME280":
return BME280, nil
case "DHT11":
return DHT11, nil
case "DHT22":

View File

@ -47,6 +47,10 @@ func (t *Temperature) GetMeasuredValueType() MeasuredValueType {
return MeasuredValueTypeTemperature
}
func (t *Temperature) SetValue(value float64) {
t.TemperatureValue = value
}
func (t *Temperature) SetTillDate(date time.Time) {
t.TemperatureTillDate = date
}