indoorclimate

package module
v1.6.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 4, 2022 License: MIT Imports: 20 Imported by: 5

README

Go Reference GitHub go.mod Go version GitHub release (latest by date) Go Report Card Actions Status

HomeDashboard Indoor Climate DataSource

Fetches indoor climate data from Bluetooth sensor devices, e.g. Xiaomi Mi Temperature and Humidity Monitor 2, and publishes this data to specified targets. Indooe climate data can be collected in two ways.

  • Running on a M5Stack Core2, using ESP32 Wifi and Bluetooth
  • Running on a host with Bluetooth device, e.g. a Raspberry PI

M5Stack

IndoorClimate provides a sketch which can be uploaded to a M5Stack Core2. With a few adjustements, e.g. skip LCD updates, this sketch can be uploaded to a lot of other ESP32 boards.

Config

You have to add AWS IOT settings at settings.h and necessary certificates to certs.h. For WiFi connections add you SSID and password to wifi_credentials.h.

AWS IOT Setup

To setup AWS IOT device, certificate, policy and rule have a look at AWS IOT Setup. A lambda function to process IOT events is available at lambda.

Sensor Data Collector

Collector can be compiled to a binary and executed as a deamon.

Define Devices and Characteristics

You've to add a list of devices and characteristics you want to observe in config.

indoorclimate:
  schedule: 10m
  devices:
    - id: "A4:XX:XX:XX:26:41"
  characteristics:
    - uuid: "00002a6e-0000-1000-8000-00805f9b34fb"
      type: "temperature"
    - uuid: "00002a6f-0000-1000-8000-00805f9b34fb"
      type: "humidity"
    - uuid: "00002a19-0000-1000-8000-00805f9b34fb"
      type: "battery"
Schedule

This value defines how often sensor data should be read. See Config for more details about supported values.

Devices

Provide a list of MAC addesses for Bluetooth environment sensors.

Characteristics

Define a list of observed characteristics by their UUID and specifiy a indoor cliamte data type.

Targets

By default a SensorDataCollector doesn't have any target assigned. This means your indoor climate date get lost. Targets package provides different publishers you can assign to a SensorDataCollector to send indoor climate data to a target.

Usage

After creating a new collector you can call it's Run method to start consuming new indoor climate data from MQTT broker. By default all received indoor climate data are send to default target which is a logger, only. Collector will run until you cancel passed context.


    import (
      "fmt"
      "context"

       indoorclimate "github.com/tommzn/hdb-datasource-indoorclimate"  
       targets "github.com/tommzn/hdb-datasource-indoorclimate(targets"  
       config "github.com/tommzn/go-config"
	     log "github.com/tommzn/go-log"
    )
    
    conf, _ := config.NewConfigSource().Load()
    if err != nil {
        panic(err)
    }
    logger := log.NewLoggerFromConfig(conf, nil)

    datacollector := indoorclimate.NewSensorDataCollector(conf, logger)
    if err != nil {
        panic(err)
    }

    datacollector.AppendTarget(targets.NewStdoutTarget())
    if err := datacollector.Run(context.Background()); err != nil {
      fmt.Println)err  
    }
    

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSensorDataCollector added in v1.3.0

func NewSensorDataCollector(conf config.Config, logger log.Logger) core.Collector

NewSensorDataCollector creates a new collector. Please note: No publisher tartget will be added. You've to do it by yourself using AppenTarget method.

Types

type Characteristic added in v1.3.0

type Characteristic struct {
	// contains filtered or unexported fields
}

Characteristic is a songle sensor value.

type IndoorClimateMeasurement added in v1.3.0

type IndoorClimateMeasurement struct {
	DeviceId  string
	Timestamp time.Time
	Type      MeasurementType
	Value     string
}

IndoorClimateMeasurement is a metric read from a sensor device.

type IndoorClimateSensor added in v1.3.0

type IndoorClimateSensor struct {
	// contains filtered or unexported fields
}

IndoorClimateSensor is used to fetch tem eprature, humidiy and bettery status from a Xiaomi Mijia (LYWSD03MMC) indoor climate sensor.

func (*IndoorClimateSensor) Connect added in v1.3.0

func (sensor *IndoorClimateSensor) Connect() error

Connect will try to connect to a device and will return with an error if failing.

func (*IndoorClimateSensor) Disconnect added in v1.3.0

func (sensor *IndoorClimateSensor) Disconnect() error

Disconnect will try to disconnect from current device and returns with an error if it fails.

func (*IndoorClimateSensor) Id added in v1.3.0

func (sensor *IndoorClimateSensor) Id() string

ID returns sensor device id.

func (*IndoorClimateSensor) ReadValue added in v1.3.0

func (sensor *IndoorClimateSensor) ReadValue(characteristicsId string) ([]byte, error)

ReadValue will try to read measurment value for given characteristics.

type LogPublisher added in v1.3.0

type LogPublisher struct {
	// contains filtered or unexported fields
}

LogPublisher will log indoor climate measuremnts.

type MeasurementType added in v1.6.0

type MeasurementType string

MeasurementType is a indoor climate date type, e.g. temperature.

const (
	MEASUREMENTTYPE_TEMPERATURE MeasurementType = "temperature"
	MEASUREMENTTYPE_HUMIDITY    MeasurementType = "humidity"
	MEASUREMENTTYPE_BATTERY     MeasurementType = "battery"
)

type Publisher added in v1.3.0

type Publisher interface {

	// SendMeasurement will start to transfer passed measurement to a target.
	SendMeasurement(IndoorClimateMeasurement) error
}

Publisher sends given measuremnts to different targets.

type SensorDataCollector added in v1.3.0

type SensorDataCollector struct {
	// contains filtered or unexported fields
}

SensorDataCollector will try to fetch temperature, humidity and bettery status from a given list of sensors.

func (*SensorDataCollector) AppendTarget added in v1.6.0

func (collector *SensorDataCollector) AppendTarget(newTarget Publisher)

AooendTarget will append passed target to internal publisher list.

func (*SensorDataCollector) Run added in v1.3.0

func (collector *SensorDataCollector) Run(ctx context.Context) error

Run will start collecting sensor data from all defined devices.

func (*SensorDataCollector) RunContinouous added in v1.4.3

func (collector *SensorDataCollector) RunContinouous(ctx context.Context)

RunContinouous will run in an endless loop and fetches device data in a defines schedule.

func (*SensorDataCollector) RunSingle added in v1.4.3

func (collector *SensorDataCollector) RunSingle(ctx context.Context)

RunSingle run indoor climate data fetch once for all devices.

type SensorDevice added in v1.3.0

type SensorDevice interface {

	// Returns the id of current sensor device.
	Id() string

	// Connect will try to connect to a device and will return with an error if failing.
	Connect() error

	// Disconnect will try to disconnect from current device and returns with an error if it fails.
	Disconnect() error

	// ReadValue will try to read measurment value for given characteristics.
	ReadValue(string) ([]byte, error)
}

SensorDevice represents a device to fetch indoor cliamte data.

func NewIndoorClimateSensor added in v1.3.0

func NewIndoorClimateSensor(adapterId, deviceId string) SensorDevice

NewIndoorClimateSensor returns a new indoor climate device.

Directories

Path Synopsis
bin module
k8s module
lambda module
plugins module
targets module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL