Help us shape the future of Go! Take the 2026 Go Developer Survey

sensors

package module
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: May 27, 2019 License: Apache-2.0 Imports: 5 Imported by: 0

README

Sensors

This repository contains sensor interfaces for hardware sensors which are interfaced through GPIO, SPI and/or I2C. There are also protocols for communicating between sensors and RPC microservices for accessing sensor data remotely.

In order to use these interfaces, the GOPI application framework (http://github.com/djthorpe/gopi) is used, and the associated set of modules for interfacing hardware and remote procedure calls.

The interfaces and definitions for the sensors are in the package root: sensors.go, rfm69.go, ads1x15.go, bme680.go, energenie.go and protocol.go. You can check the examples in the cmd directory for more information on using the drivers.

For more information on using the drivers, the documentation is in the doc folder:

  • For Bosch BME280 and BME680 temperature, humidity, pressure and air quality sensors please see doc/BMEx80.md;
  • For the TAOS TSL2561 luminosity sensor, please see doc/TSL2561.md;
  • For the HopeRF RFM69 radio transceiver series, please see doc/RFM69.md;
  • For the Texas Instruments ADS1015 and ADS1115 analog-to-digital converters, please see doc/ADS1x15.md;
  • For the ENER314 OOK transmitter and OOK/FSK transciever boards, please see doc/ENER314.md;
  • For the implementation of the wire protocol for Energenie MiHome series, please see doc/mihome.md.

Building the examples

There is a makefile which will test and make all the example commands for both MacOS and Raspberry Pi target. On MacOS, only the client command-line utility which allows you to connect to a remote mihome-service is built. On the Raspberry Pi, all the examples are built.

On MacOS:

% make -f Makefile.darwin

On Raspberry Pi:

% make -f Makefile.rpi

License

Copyright 2016-2019 David Thorpe All Rights Reserved

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Documentation

Index

Constants

View Source
const (
	RFM_RXBW_FREQUENCY_OOK_1P3   = RFM_RXBW_FREQUENCY_FSK_2P6
	RFM_RXBW_FREQUENCY_OOK_1P6   = RFM_RXBW_FREQUENCY_FSK_3P1
	RFM_RXBW_FREQUENCY_OOK_2P0   = RFM_RXBW_FREQUENCY_FSK_3P9
	RFM_RXBW_FREQUENCY_OOK_2P6   = RFM_RXBW_FREQUENCY_FSK_5P2
	RFM_RXBW_FREQUENCY_OOK_3P1   = RFM_RXBW_FREQUENCY_FSK_6P3
	RFM_RXBW_FREQUENCY_OOK_3P9   = RFM_RXBW_FREQUENCY_FSK_7P8
	RFM_RXBW_FREQUENCY_OOK_5P2   = RFM_RXBW_FREQUENCY_FSK_10P4
	RFM_RXBW_FREQUENCY_OOK_6P3   = RFM_RXBW_FREQUENCY_FSK_12P5
	RFM_RXBW_FREQUENCY_OOK_7P8   = RFM_RXBW_FREQUENCY_FSK_15P6
	RFM_RXBW_FREQUENCY_OOK_10P4  = RFM_RXBW_FREQUENCY_FSK_20P8
	RFM_RXBW_FREQUENCY_OOK_12P5  = RFM_RXBW_FREQUENCY_FSK_25P0
	RFM_RXBW_FREQUENCY_OOK_15P6  = RFM_RXBW_FREQUENCY_FSK_31P3
	RFM_RXBW_FREQUENCY_OOK_20P8  = RFM_RXBW_FREQUENCY_FSK_41P7
	RFM_RXBW_FREQUENCY_OOK_25P0  = RFM_RXBW_FREQUENCY_FSK_50P0
	RFM_RXBW_FREQUENCY_OOK_31P3  = RFM_RXBW_FREQUENCY_FSK_62P5
	RFM_RXBW_FREQUENCY_OOK_41P7  = RFM_RXBW_FREQUENCY_FSK_83P3
	RFM_RXBW_FREQUENCY_OOK_50P0  = RFM_RXBW_FREQUENCY_FSK_100P0
	RFM_RXBW_FREQUENCY_OOK_62P5  = RFM_RXBW_FREQUENCY_FSK_125P0
	RFM_RXBW_FREQUENCY_OOK_83P3  = RFM_RXBW_FREQUENCY_FSK_166P7
	RFM_RXBW_FREQUENCY_OOK_100P0 = RFM_RXBW_FREQUENCY_FSK_200P0
	RFM_RXBW_FREQUENCY_OOK_125P0 = RFM_RXBW_FREQUENCY_FSK_250P0
	RFM_RXBW_FREQUENCY_OOK_166P7 = RFM_RXBW_FREQUENCY_FSK_333P3
	RFM_RXBW_FREQUENCY_OOK_200P0 = RFM_RXBW_FREQUENCY_FSK_400P0
	RFM_RXBW_FREQUENCY_OOK_250P0 = RFM_RXBW_FREQUENCY_FSK_500P0
)
View Source
const (
	BME280_PRESSURE_SEALEVEL float64 = 103090 // in Pascals
)

Sealevel pressure approximation http://resource.npl.co.uk/pressure/pressure.html

Variables

View Source
var (
	ErrNoDevice           = errors.New("Missing or invalid hardware device")
	ErrSampleSkipped      = errors.New("Sampling skipped or not enabled")
	ErrUnexpectedResponse = errors.New("Unexpected response from sensor")
	ErrDeviceTimeout      = errors.New("Device timeout")
	ErrMessageCorruption  = errors.New("Message Corrupt")
	ErrMessageCRC         = errors.New("CRC Error")
)

Functions

This section is empty.

Types

type ADS1X15 added in v1.0.4

type ADS1X15 interface {
	gopi.Driver

	// Return product
	Product() ADS1X15Product
}

type ADS1X15Product added in v1.0.4

type ADS1X15Product uint
const (
	ADS1X15_PRODUCT_NONE ADS1X15Product = iota
	ADS1X15_PRODUCT_1015                // 12-bit ADC with 4 channels
	ADS1X15_PRODUCT_1115                // 16-bit ADC with 4 channels
	ADS1X15_PRODUCT_MAX  = ADS1X15_PRODUCT_1115
)

func (ADS1X15Product) String added in v1.0.4

func (p ADS1X15Product) String() string

type ADS1X15Rate added in v1.0.4

type ADS1X15Rate uint16
const (
	ADS1X15_RATE_NONE ADS1X15Rate = iota
	ADS1X15_RATE_8
	ADS1X15_RATE_16
	ADS1X15_RATE_32
	ADS1X15_RATE_64
	ADS1X15_RATE_128
	ADS1X15_RATE_250
	ADS1X15_RATE_475
	ADS1X15_RATE_490
	ADS1X15_RATE_860
	ADS1X15_RATE_920
	ADS1X15_RATE_1600
	ADS1X15_RATE_2400
	ADS1X15_RATE_3300
	ADS1X15_RATE_MAX = ADS1X15_RATE_3300
)

type ADS1015 added in v1.0.4

type ADS1015 interface {
	ADS1X15
}

type ADS1115 added in v1.0.4

type ADS1115 interface {
	ADS1X15
}

type BME280

type BME280 interface {
	gopi.Driver

	// Get Version
	ChipIDVersion() (uint8, uint8)

	// Get Mode
	Mode() BME280Mode

	// Return IIR filter co-officient
	Filter() BME280Filter

	// Return standby time
	Standby() BME280Standby

	// Return oversampling values osrs_t, osrs_p, osrs_h
	Oversample() (BME280Oversample, BME280Oversample, BME280Oversample)

	// Return current measuring and updating value
	Status() (bool, bool, error)

	// Return the measurement duty cycle (minimum duration between subsequent readings)
	// in normal mode
	DutyCycle() time.Duration

	// Reset
	SoftReset() error

	// Set BME280 mode
	SetMode(mode BME280Mode) error

	// Set Oversampling
	SetOversample(osrs_t, osrs_p, osrs_h BME280Oversample) error

	// Set Filter
	SetFilter(filter BME280Filter) error

	// Set Standby mode
	SetStandby(t_sb BME280Standby) error

	// Return raw sample data for temperature, pressure and humidity
	// Temperature in Celcius, Pressure in Pascals and humidity in
	// %age
	ReadSample() (float64, float64, float64, error)

	// Return altitude in meters for given pressure in Pascals
	AltitudeForPressure(atmospheric, sealevel float64) float64
}

type BME280Filter

type BME280Filter uint8
const (
	BME280_FILTER_OFF BME280Filter = 0x00
	BME280_FILTER_2   BME280Filter = 0x01
	BME280_FILTER_4   BME280Filter = 0x02
	BME280_FILTER_8   BME280Filter = 0x03
	BME280_FILTER_16  BME280Filter = 0x04
	BME280_FILTER_MAX BME280Filter = 0x07
)

BME280 Filter Co-efficient

func (BME280Filter) String

func (f BME280Filter) String() string

type BME280Mode

type BME280Mode uint8
const (
	BME280_MODE_SLEEP   BME280Mode = 0x00
	BME280_MODE_FORCED  BME280Mode = 0x01
	BME280_MODE_FORCED2 BME280Mode = 0x02
	BME280_MODE_NORMAL  BME280Mode = 0x03
	BME280_MODE_MAX     BME280Mode = 0x03
)

BME280 Mode

func (BME280Mode) String

func (m BME280Mode) String() string

type BME280Oversample

type BME280Oversample uint8
const (
	BME280_OVERSAMPLE_SKIP BME280Oversample = 0x00
	BME280_OVERSAMPLE_1    BME280Oversample = 0x01
	BME280_OVERSAMPLE_2    BME280Oversample = 0x02
	BME280_OVERSAMPLE_4    BME280Oversample = 0x03
	BME280_OVERSAMPLE_8    BME280Oversample = 0x04
	BME280_OVERSAMPLE_16   BME280Oversample = 0x05
	BME280_OVERSAMPLE_MAX  BME280Oversample = 0x07
)

BME280 Oversampling value

func (BME280Oversample) String

func (o BME280Oversample) String() string

type BME280Standby

type BME280Standby uint8
const (
	BME280_STANDBY_0P5MS  BME280Standby = 0x00
	BME280_STANDBY_62P5MS BME280Standby = 0x01
	BME280_STANDBY_125MS  BME280Standby = 0x02
	BME280_STANDBY_250MS  BME280Standby = 0x03
	BME280_STANDBY_500MS  BME280Standby = 0x04
	BME280_STANDBY_1000MS BME280Standby = 0x05
	BME280_STANDBY_10MS   BME280Standby = 0x06
	BME280_STANDBY_20MS   BME280Standby = 0x07
	BME280_STANDBY_MAX    BME280Standby = 0x07
)

BME280 Standby time

func (BME280Standby) String

func (t BME280Standby) String() string

type BME680 added in v1.0.2

type BME680 interface {
	gopi.Driver

	// Get ChipID
	ChipID() uint8

	// Reset
	SoftReset() error
}

type Database added in v1.0.3

type Database interface {
	gopi.Driver

	// Return an array of all sensors
	Sensors() []Sensor

	// Register a sensor from a message
	Register(Message) (Sensor, error)

	// Lookup an existing sensor based on namespace and key
	Lookup(ns, key string) Sensor

	// Write a message to the database
	Write(Sensor, Message) error
}

type ENER314

type ENER314 interface {
	gopi.Driver

	// Send on signal - when no sockets specified then
	// sends to all sockets
	On(sockets ...uint) error

	// Send off signal - when no sockets specified then
	// sends to all sockets
	Off(sockets ...uint) error
}

type ENER314RT added in v1.0.4

type ENER314RT interface {
	gopi.Driver

	// Receive payloads with radio until context deadline exceeded or cancel,
	// this blocks sending
	Receive(ctx context.Context, mode MiHomeMode, payload chan<- []byte) error

	// Send a raw payload with radio
	Send(payload []byte, repeat uint, mode MiHomeMode) error

	// Measure device temperature
	MeasureTemperature(offset float32) (float32, error)

	// Reset radio device
	ResetRadio() error
}

type Message added in v1.0.3

type Message interface {
	gopi.Event

	// Return the timestamp for a decoded message
	Timestamp() time.Time

	// Return the data for the message, or nil if there
	// is no wire format for the data
	Data() []byte

	// IsDuplicate returns true if one message is equivalent of another,
	// regardless of timestamp, to help with de-duplication
	IsDuplicate(Message) bool
}

type MiHome

type MiHome interface {
	gopi.Driver
	gopi.Publisher

	// Reset the device
	Reset() error

	// Add a wire protocol which encodes/decodes messages
	AddProto(Proto) error

	// Return registered protocols
	Protos() []Proto

	// Measure Device Temperature
	MeasureTemperature() (float32, error)

	// Request Switch state for both monitor and control devices
	RequestSwitchOn(MiHomeProduct, uint32) error
	RequestSwitchOff(MiHomeProduct, uint32) error

	// Send a join message after a report is received
	SendJoin(MiHomeProduct, uint32) error

	// Note the eTRV messages below should be sent very shortly
	// after the temperature report is provided as that's when the
	// eTRV is awake to respond to the messages
	RequestIdentify(MiHomeProduct, uint32) error
	RequestDiagnostics(MiHomeProduct, uint32) error
	RequestExercise(MiHomeProduct, uint32) error
	RequestBatteryLevel(MiHomeProduct, uint32) error
	RequestTargetTemperature(MiHomeProduct, uint32, float64) error
	RequestReportInterval(MiHomeProduct, uint32, time.Duration) error
	RequestValveState(MiHomeProduct, uint32, MiHomeValveState) error
	RequestLowPowerMode(MiHomeProduct, uint32, bool) error
}

type MiHomeClient added in v1.0.5

type MiHomeClient interface {
	gopi.RPCClient
	gopi.Publisher

	// Ping the remote service instance
	Ping() error

	// Reset the device
	Reset() error

	// Send 'On' and 'Off' signals
	On(MiHomeProduct, uint32) error
	Off(MiHomeProduct, uint32) error

	// Send a join message after a join report is received
	SendJoin(MiHomeProduct, uint32) error

	// Request status
	RequestDiagnostics(MiHomeProduct, uint32) error
	RequestIdentify(MiHomeProduct, uint32) error
	RequestExercise(MiHomeProduct, uint32) error
	RequestBatteryLevel(MiHomeProduct, uint32) error

	// Set parameters
	SendTargetTemperature(MiHomeProduct, uint32, float64) error
	SendReportInterval(MiHomeProduct, uint32, time.Duration) error
	SendValveState(MiHomeProduct, uint32, MiHomeValveState) error
	SendPowerMode(MiHomeProduct, uint32, MiHomePowerMode) error

	// Receive messages
	StreamMessages(ctx context.Context) error
}

MiHome Client Stub

type MiHomeMode

type MiHomeMode uint
const (
	MIHOME_MODE_NONE    MiHomeMode = iota
	MIHOME_MODE_MONITOR            // FSK
	MIHOME_MODE_CONTROL            // OOK
	MIHOME_MODE_MAX     = MIHOME_MODE_CONTROL
)

func (MiHomeMode) String

func (m MiHomeMode) String() string

type MiHomePowerMode added in v1.0.3

type MiHomePowerMode byte
const (
	MIHOME_POWER_NONE MiHomePowerMode = iota
	MIHOME_POWER_NORMAL
	MIHOME_POWER_LOW
)

func (MiHomePowerMode) String added in v1.0.5

func (p MiHomePowerMode) String() string

type MiHomeProduct added in v1.0.3

type MiHomeProduct byte
const (
	// Monitor Products (FSK)
	MIHOME_PRODUCT_NONE    MiHomeProduct = 0x00
	MIHOME_PRODUCT_MIHO004 MiHomeProduct = 0x01 // Adaptor Monitor
	MIHOME_PRODUCT_MIHO005 MiHomeProduct = 0x02 // Adaptor Plus
	MIHOME_PRODUCT_MIHO013 MiHomeProduct = 0x03 // eTRV
	MIHOME_PRODUCT_MIHO006 MiHomeProduct = 0x05 // House Monitor
	MIHOME_PRODUCT_MIHO032 MiHomeProduct = 0x0C // Motion sensor
	MIHOME_PRODUCT_MIHO033 MiHomeProduct = 0x0D // Door sensor
	MIHOME_PRODUCT_MIHO089 MiHomeProduct = 0x13 // Click

	// Control Products (OOK)
	MIHOME_PRODUCT_CONTROL_ALL   MiHomeProduct = 0xF0 // OOK Switch All
	MIHOME_PRODUCT_CONTROL_ONE   MiHomeProduct = 0xF1 // OOK Switch 1
	MIHOME_PRODUCT_CONTROL_TWO   MiHomeProduct = 0xF2 // OOK Switch 2
	MIHOME_PRODUCT_CONTROL_THREE MiHomeProduct = 0xF3 // OOK Switch 3
	MIHOME_PRODUCT_CONTROL_FOUR  MiHomeProduct = 0xF4 // OOK Switch 4
)

func SocketProduct added in v1.0.5

func SocketProduct(socket uint) MiHomeProduct

SocketProduct maps from socket number to control product

func (MiHomeProduct) Mode added in v1.0.3

func (p MiHomeProduct) Mode() MiHomeMode

Mode returns the mode for a product

func (MiHomeProduct) Socket added in v1.0.4

func (p MiHomeProduct) Socket() uint

Socket returns the socket number of a control product

func (MiHomeProduct) String added in v1.0.3

func (p MiHomeProduct) String() string

type MiHomeValveState added in v1.0.3

type MiHomeValveState byte
const (
	MIHOME_VALVE_STATE_OPEN   MiHomeValveState = 0x00 // Valve fully open
	MIHOME_VALVE_STATE_CLOSED MiHomeValveState = 0x01 // Valve fully closed
	MIHOME_VALVE_STATE_NORMAL MiHomeValveState = 0x02 // Valve in normal state
)

func (MiHomeValveState) String added in v1.0.3

func (s MiHomeValveState) String() string

type OOKMessage added in v1.0.3

type OOKMessage interface {
	Message

	Addr() uint32 // 20-bit address
	Socket() uint // 0 = all or 1-4
	State() bool  // false = off or true = on
}

type OOKProto added in v1.0.3

type OOKProto interface {
	Proto

	// Create a new message
	New(addr uint32, socket uint, state bool, data []byte) (OOKMessage, error)
}

type OTDataType

type OTDataType uint8
const (
	// OTDataType
	OT_DATATYPE_UDEC_0  OTDataType = 0x00
	OT_DATATYPE_UDEC_4  OTDataType = 0x01
	OT_DATATYPE_UDEC_8  OTDataType = 0x02
	OT_DATATYPE_UDEC_12 OTDataType = 0x03
	OT_DATATYPE_UDEC_16 OTDataType = 0x04
	OT_DATATYPE_UDEC_20 OTDataType = 0x05
	OT_DATATYPE_UDEC_24 OTDataType = 0x06
	OT_DATATYPE_STRING  OTDataType = 0x07
	OT_DATATYPE_DEC_0   OTDataType = 0x08
	OT_DATATYPE_DEC_8   OTDataType = 0x09
	OT_DATATYPE_DEC_16  OTDataType = 0x0A
	OT_DATATYPE_DEC_24  OTDataType = 0x0B
	OT_DATATYPE_ENUM    OTDataType = 0x0C // Not supported
	OT_DATATYPE_FLOAT   OTDataType = 0x0F // Not supported
)

func (OTDataType) String

func (t OTDataType) String() string

type OTManufacturer

type OTManufacturer uint8
const (
	// OTManufacturer - see http://www.o-things.com/
	OT_MANUFACTURER_NONE        OTManufacturer = 0x00
	OT_MANUFACTURER_SENTEC      OTManufacturer = 0x01
	OT_MANUFACTURER_HILDERBRAND OTManufacturer = 0x02
	OT_MANUFACTURER_ENERGENIE   OTManufacturer = 0x04
	OT_MANUFACTURER_MAX                        = OT_MANUFACTURER_ENERGENIE
)

func (OTManufacturer) String

func (m OTManufacturer) String() string

type OTMessage

type OTMessage interface {
	Message

	// Return message information
	Manufacturer() OTManufacturer
	Product() uint8
	Sensor() uint32

	// Records returns an array of records for the message
	Records() []OTRecord

	// Append a record
	Append(...OTRecord) OTMessage
}

type OTParameter

type OTParameter uint8
const (
	// OTParameter
	OT_PARAM_NONE              OTParameter = 0x00
	OT_PARAM_ALARM             OTParameter = 0x21
	OT_PARAM_EXERCISE          OTParameter = 0x23
	OT_PARAM_LOW_POWER         OTParameter = 0x24
	OT_PARAM_VALVE_STATE       OTParameter = 0x25
	OT_PARAM_DIAGNOSTICS       OTParameter = 0x26
	OT_PARAM_DEBUG_OUTPUT      OTParameter = 0x2D
	OT_PARAM_IDENTIFY          OTParameter = 0x3F
	OT_PARAM_SOURCE_SELECTOR   OTParameter = 0x40
	OT_PARAM_WATER_DETECTOR    OTParameter = 0x41
	OT_PARAM_GLASS_BREAKAGE    OTParameter = 0x42
	OT_PARAM_CLOSURES          OTParameter = 0x43
	OT_PARAM_DOOR_BELL         OTParameter = 0x44
	OT_PARAM_ENERGY            OTParameter = 0x45
	OT_PARAM_FALL_SENSOR       OTParameter = 0x46
	OT_PARAM_GAS_VOLUME        OTParameter = 0x47
	OT_PARAM_AIR_PRESSURE      OTParameter = 0x48
	OT_PARAM_ILLUMINANCE       OTParameter = 0x49
	OT_PARAM_LEVEL             OTParameter = 0x4C
	OT_PARAM_RAINFALL          OTParameter = 0x4D
	OT_PARAM_CLICK             OTParameter = 0x4F
	OT_PARAM_APPARENT_POWER    OTParameter = 0x50
	OT_PARAM_POWER_FACTOR      OTParameter = 0x51
	OT_PARAM_REPORT_PERIOD     OTParameter = 0x52
	OT_PARAM_SMOKE_DETECTOR    OTParameter = 0x53
	OT_PARAM_TIME_AND_DATE     OTParameter = 0x54
	OT_PARAM_VIBRATION         OTParameter = 0x56
	OT_PARAM_WATER_VOLUME      OTParameter = 0x57
	OT_PARAM_WIND_SPEED        OTParameter = 0x58
	OT_PARAM_GAS_PRESSURE      OTParameter = 0x61
	OT_PARAM_BATTERY_LEVEL     OTParameter = 0x62
	OT_PARAM_CO_DETECTOR       OTParameter = 0x63
	OT_PARAM_DOOR_SENSOR       OTParameter = 0x64
	OT_PARAM_EMERGENCY         OTParameter = 0x65
	OT_PARAM_FREQUENCY         OTParameter = 0x66
	OT_PARAM_GAS_FLOW_RATE     OTParameter = 0x67
	OT_PARAM_RELATIVE_HUMIDITY OTParameter = 0x68
	OT_PARAM_CURRENT           OTParameter = 0x69
	OT_PARAM_JOIN              OTParameter = 0x6A
	OT_PARAM_RF_QUALITY        OTParameter = 0x6B
	OT_PARAM_LIGHT_LEVEL       OTParameter = 0x6C
	OT_PARAM_MOTION_DETECTOR   OTParameter = 0x6D
	OT_PARAM_OCCUPANCY         OTParameter = 0x6F
	OT_PARAM_REAL_POWER        OTParameter = 0x70
	OT_PARAM_REACTIVE_POWER    OTParameter = 0x71
	OT_PARAM_ROTATION_SPEED    OTParameter = 0x72
	OT_PARAM_SWITCH_STATE      OTParameter = 0x73
	OT_PARAM_TEMPERATURE       OTParameter = 0x74
	OT_PARAM_VOLTAGE           OTParameter = 0x76
	OT_PARAM_WATER_FLOW_RATE   OTParameter = 0x77
	OT_PARAM_WATER_PRESSURE    OTParameter = 0x78
	OT_PARAM_3PHASE_POWER1     OTParameter = 0x79
	OT_PARAM_3PHASE_POWER2     OTParameter = 0x7A
	OT_PARAM_3PHASE_POWER3     OTParameter = 0x7B
	OT_PARAM_3PHASE_POWER      OTParameter = 0x7C
	OT_PARAM_MAX                           = OT_PARAM_3PHASE_POWER
)

func (OTParameter) String

func (p OTParameter) String() string

type OTProto added in v1.0.3

type OTProto interface {
	Proto

	// Create a new message
	New(manufacturer OTManufacturer, product uint8, sensor uint32) (OTMessage, error)

	// Create a new record
	NewFloat(OTParameter, OTDataType, float64, bool) (OTRecord, error)
	NewBool(OTParameter, bool, bool) (OTRecord, error)
	NewUint(OTParameter, uint64, bool) (OTRecord, error)
	NewInt(OTParameter, int64, bool) (OTRecord, error)
	NewString(OTParameter, string, bool) (OTRecord, error)
	NewNull(OTParameter, bool) (OTRecord, error)
	NewUint8(OTParameter, uint8, bool) (OTRecord, error)
	NewUint16(OTParameter, uint16, bool) (OTRecord, error)
}

type OTRecord

type OTRecord interface {
	// Name is the parameter name
	Name() OTParameter

	// Type is the type of data
	Type() OTDataType

	// IsReport returns the report bit for the record
	IsReport() bool

	// Data returns the record encoded as data
	Data() ([]byte, error)

	// Value returns the value
	Value() interface{}

	// BoolValue returns the boolean value, when type is UDEC_0
	BoolValue() (bool, error)

	// StringValue returns the value for all types except FLOAT and ENUM
	StringValue() (string, error)

	// UintValue returns the value for UDEC_0 types
	UintValue() (uint64, error)

	// IntValue returns the value for DEC_0 types
	IntValue() (int64, error)

	// FloatValue returns the value for all UDEC and DEC types
	FloatValue() (float64, error)

	// Compares one record against another and returns true if identical
	IsDuplicate(OTRecord) bool
}

type Proto added in v1.0.3

type Proto interface {
	gopi.Driver

	// Return the mode in which the protocol operates
	Mode() MiHomeMode

	// Return name of the protocol
	Name() string

	// Encode a message into bytes
	Encode(Message) []byte

	// Decode a payload into a message
	Decode([]byte, time.Time) (Message, error)
}

Proto provides a wire interface for TX and RX

type ProtoMessage added in v1.0.4

type ProtoMessage interface {
	Message

	// Return sender information
	Protocol() string
	Product() uint8
	Sensor() uint32
}

type RFM69

type RFM69 interface {
	gopi.Driver

	// Reset Registers from device (after a reset)
	ResetRegisters() error

	// Mode, Data Mode and Modulation
	Mode() RFMMode
	DataMode() RFMDataMode
	SetMode(device_mode RFMMode) error
	SetDataMode(data_mode RFMDataMode) error
	Modulation() RFMModulation
	SetModulation(modulation RFMModulation) error

	// Bitrate & Frequency
	Bitrate() uint
	FreqCarrier() uint
	FreqDeviation() uint
	SetBitrate(bits_per_second uint) error
	SetFreqCarrier(hertz uint) error
	SetFreqDeviation(hertz uint) error

	// Listen Mode and Sequencer
	SetSequencer(enabled bool) error
	SequencerEnabled() bool
	SetListenOn(value bool) error
	ListenOn() bool

	// Packets
	PacketFormat() RFMPacketFormat
	PacketCoding() RFMPacketCoding
	PacketFilter() RFMPacketFilter
	PacketCRC() RFMPacketCRC
	SetPacketFormat(packet_format RFMPacketFormat) error
	SetPacketCoding(packet_coding RFMPacketCoding) error
	SetPacketFilter(packet_filter RFMPacketFilter) error
	SetPacketCRC(packet_crc RFMPacketCRC) error

	// Addresses
	NodeAddress() uint8
	BroadcastAddress() uint8
	SetNodeAddress(value uint8) error
	SetBroadcastAddress(value uint8) error

	// Payload & Preamble
	PreambleSize() uint16
	PayloadSize() uint8
	SetPreambleSize(preamble_size uint16) error
	SetPayloadSize(payload_size uint8) error

	// Encryption Key & Sync Words for Packet mode
	AESKey() []byte
	SetAESKey(key []byte) error
	SyncWord() []byte
	SetSyncWord(word []byte) error
	SyncTolerance() uint8
	SetSyncTolerance(bits uint8) error

	// AFC
	AFC() uint
	AFCMode() RFMAFCMode
	AFCRoutine() RFMAFCRoutine
	SetAFCRoutine(afc_routine RFMAFCRoutine) error
	SetAFCMode(afc_mode RFMAFCMode) error
	TriggerAFC() error

	// Low Noise Amplifier Settings
	LNAImpedance() RFMLNAImpedance
	LNAGain() RFMLNAGain
	LNACurrentGain() (RFMLNAGain, error)
	SetLNA(impedance RFMLNAImpedance, gain RFMLNAGain) error

	// Channel Filter Settings
	RXFilterFrequency() RFMRXBWFrequency
	RXFilterCutoff() RFMRXBWCutoff
	SetRXFilter(RFMRXBWFrequency, RFMRXBWCutoff) error

	// FIFO
	FIFOThreshold() uint8
	SetFIFOThreshold(fifo_threshold uint8) error
	ReadFIFO(ctx context.Context) ([]byte, error)
	WriteFIFO(data []byte) error
	ClearFIFO() error

	// ReadPayload listens for a packet and returns it. If the data is
	// read then it will also return true if the CRC value was
	// correct, or false otherwise
	ReadPayload(ctx context.Context) ([]byte, bool, error)

	// WritePayload writes a packet a number of times, with a delay between each
	// when the repeat is greater than zero
	WritePayload(data []byte, repeat uint, delay time.Duration) error

	// MeasureTemperature and return after calibration
	MeasureTemperature(calibration float32) (float32, error)
}

type RFMAFCMode

type RFMAFCMode uint8
const (
	// Automatic Frequency Correction Mode
	RFM_AFCMODE_OFF       RFMAFCMode = 0x00 // AFC is performed only when triggered
	RFM_AFCMODE_ON        RFMAFCMode = 0x01 // AFC register is not cleared before a new AFC phase
	RFM_AFCMODE_AUTOCLEAR RFMAFCMode = 0x03 // AFC register is cleared before a new AFC phase
	RFM_AFCMODE_MASK      RFMAFCMode = 0x03
)

func (RFMAFCMode) String

func (m RFMAFCMode) String() string

type RFMAFCRoutine

type RFMAFCRoutine uint8
const (
	// Automatic Frequency Correction Routine
	RFM_AFCROUTINE_STANDARD RFMAFCRoutine = 0x00 // Standard AFC Routine
	RFM_AFCROUTINE_IMPROVED RFMAFCRoutine = 0x01 // Improved AFC Routine
	RFM_AFCROUTINE_MASK     RFMAFCRoutine = 0x01
)

func (RFMAFCRoutine) String

func (r RFMAFCRoutine) String() string

type RFMDataMode

type RFMDataMode uint8
const (
	// RFM69 Data Mode
	RFM_DATAMODE_PACKET            RFMDataMode = 0x00
	RFM_DATAMODE_CONTINUOUS_NOSYNC RFMDataMode = 0x02
	RFM_DATAMODE_CONTINUOUS_SYNC   RFMDataMode = 0x03
	RFM_DATAMODE_MAX               RFMDataMode = 0x03
)

func (RFMDataMode) String

func (m RFMDataMode) String() string

type RFMLNAGain

type RFMLNAGain uint8
const (
	// Low Noise Amplifier Gain
	RFM_LNA_GAIN_AUTO RFMLNAGain = 0x00 // Gain set by internal AGC Loop
	RFM_LNA_GAIN_G1   RFMLNAGain = 0x01 // Highest gain
	RFM_LNA_GAIN_G2   RFMLNAGain = 0x02 // Highest gain minus 6dB
	RFM_LNA_GAIN_G3   RFMLNAGain = 0x03 // Highest gain minus 12dB
	RFM_LNA_GAIN_G4   RFMLNAGain = 0x04 // Highest gain minus 24dB
	RFM_LNA_GAIN_G5   RFMLNAGain = 0x05 // Highest gain minus 36dB
	RFM_LNA_GAIN_G6   RFMLNAGain = 0x06 // Highest gain minus 48dB
	RFM_LNA_GAIN_MAX  RFMLNAGain = 0x07 // Gain mask
)

func (RFMLNAGain) String

func (v RFMLNAGain) String() string

type RFMLNAImpedance

type RFMLNAImpedance uint8
const (
	// Low Noise Amplifier Impedance
	RFM_LNA_IMPEDANCE_50  RFMLNAImpedance = 0x00 // 50 Ohms
	RFM_LNA_IMPEDANCE_100 RFMLNAImpedance = 0x01 // 100 Ohms
	RFM_LNA_IMPEDANCE_MAX RFMLNAImpedance = 0x01
)

func (RFMLNAImpedance) String

func (v RFMLNAImpedance) String() string

type RFMMode

type RFMMode uint8
const (
	// RFM69 Mode
	RFM_MODE_SLEEP RFMMode = 0x00
	RFM_MODE_STDBY RFMMode = 0x01
	RFM_MODE_FS    RFMMode = 0x02
	RFM_MODE_TX    RFMMode = 0x03
	RFM_MODE_RX    RFMMode = 0x04
	RFM_MODE_MAX   RFMMode = 0x07
)

func (RFMMode) String

func (m RFMMode) String() string

type RFMModulation

type RFMModulation uint8
const (
	// RFM69 Modulation
	RFM_MODULATION_FSK        RFMModulation = 0x00 // 00000 FSK no shaping
	RFM_MODULATION_FSK_BT_1P0 RFMModulation = 0x01 // 01000 FSK Guassian filter, BT=1.0
	RFM_MODULATION_FSK_BT_0P5 RFMModulation = 0x02 // 10000 FSK Gaussian filter, BT=0.5
	RFM_MODULATION_FSK_BT_0P3 RFMModulation = 0x03 // 11000 FSK Gaussian filter, BT=0.3
	RFM_MODULATION_OOK        RFMModulation = 0x08 // 00001 OOK no shaping
	RFM_MODULATION_OOK_BR     RFMModulation = 0x09 // 01001 OOK Filtering with f(cutoff) = BR
	RFM_MODULATION_OOK_2BR    RFMModulation = 0x0A // 01010 OOK Filtering with f(cutoff) = 2BR
	RFM_MODULATION_MAX        RFMModulation = 0x0A
)

func (RFMModulation) String

func (m RFMModulation) String() string

type RFMPacketCRC

type RFMPacketCRC uint8
const (
	// RFM69 Packet CRC
	RFM_PACKET_CRC_OFF           RFMPacketCRC = 0x00 // CRC off
	RFM_PACKET_CRC_AUTOCLEAR_OFF RFMPacketCRC = 0x01 // CRC on
	RFM_PACKET_CRC_AUTOCLEAR_ON  RFMPacketCRC = 0x02 // CRC on
)

func (RFMPacketCRC) String

func (c RFMPacketCRC) String() string

type RFMPacketCoding

type RFMPacketCoding uint8
const (
	// RFM69 Packet coding
	RFM_PACKET_CODING_NONE       RFMPacketCoding = 0x00 // No Packet Coding
	RFM_PACKET_CODING_MANCHESTER RFMPacketCoding = 0x01 // Manchester
	RFM_PACKET_CODING_WHITENING  RFMPacketCoding = 0x02 // Whitening
	RFM_PACKET_CODING_MAX        RFMPacketCoding = 0x03 // Mask
)

func (RFMPacketCoding) String

func (c RFMPacketCoding) String() string

type RFMPacketFilter

type RFMPacketFilter uint8
const (
	// RFM69 Packet filtering
	RFM_PACKET_FILTER_NONE      RFMPacketFilter = 0x00 // Promiscious mode
	RFM_PACKET_FILTER_NODE      RFMPacketFilter = 0x01 // Matches Node
	RFM_PACKET_FILTER_BROADCAST RFMPacketFilter = 0x02 // Matches Node or Broadcast
	RFM_PACKET_FILTER_MAX       RFMPacketFilter = 0x03 // Mask
)

func (RFMPacketFilter) String

func (f RFMPacketFilter) String() string

type RFMPacketFormat

type RFMPacketFormat uint8
const (
	// RFM69 Packet format
	RFM_PACKET_FORMAT_FIXED    RFMPacketFormat = 0x00 // Fixed Packet Format
	RFM_PACKET_FORMAT_VARIABLE RFMPacketFormat = 0x01 // Variable Packet Format
)

func (RFMPacketFormat) String

func (f RFMPacketFormat) String() string

type RFMRXBWCutoff

type RFMRXBWCutoff uint8
const (
	RFM_RXBW_CUTOFF_16    RFMRXBWCutoff = 0x00
	RFM_RXBW_CUTOFF_8     RFMRXBWCutoff = 0x01
	RFM_RXBW_CUTOFF_4     RFMRXBWCutoff = 0x02
	RFM_RXBW_CUTOFF_2     RFMRXBWCutoff = 0x03
	RFM_RXBW_CUTOFF_1     RFMRXBWCutoff = 0x04
	RFM_RXBW_CUTOFF_0P5   RFMRXBWCutoff = 0x05
	RFM_RXBW_CUTOFF_0P25  RFMRXBWCutoff = 0x06
	RFM_RXBW_CUTOFF_0P125 RFMRXBWCutoff = 0x07
	RFM_RXBW_CUTOFF_MAX   RFMRXBWCutoff = RFM_RXBW_CUTOFF_0P125
)

func (RFMRXBWCutoff) String

func (v RFMRXBWCutoff) String() string

type RFMRXBWFrequency

type RFMRXBWFrequency uint8
const (
	RFM_RXBW_FREQUENCY_FSK_2P6   RFMRXBWFrequency = 2<<3 | 7
	RFM_RXBW_FREQUENCY_FSK_3P1   RFMRXBWFrequency = 1<<3 | 7
	RFM_RXBW_FREQUENCY_FSK_3P9   RFMRXBWFrequency = 0<<3 | 7
	RFM_RXBW_FREQUENCY_FSK_5P2   RFMRXBWFrequency = 2<<3 | 6
	RFM_RXBW_FREQUENCY_FSK_6P3   RFMRXBWFrequency = 1<<3 | 6
	RFM_RXBW_FREQUENCY_FSK_7P8   RFMRXBWFrequency = 0<<3 | 6
	RFM_RXBW_FREQUENCY_FSK_10P4  RFMRXBWFrequency = 2<<3 | 5
	RFM_RXBW_FREQUENCY_FSK_12P5  RFMRXBWFrequency = 1<<3 | 5
	RFM_RXBW_FREQUENCY_FSK_15P6  RFMRXBWFrequency = 0<<3 | 5
	RFM_RXBW_FREQUENCY_FSK_20P8  RFMRXBWFrequency = 2<<3 | 4
	RFM_RXBW_FREQUENCY_FSK_25P0  RFMRXBWFrequency = 1<<3 | 4
	RFM_RXBW_FREQUENCY_FSK_31P3  RFMRXBWFrequency = 0<<3 | 4
	RFM_RXBW_FREQUENCY_FSK_41P7  RFMRXBWFrequency = 2<<3 | 3
	RFM_RXBW_FREQUENCY_FSK_50P0  RFMRXBWFrequency = 1<<3 | 3
	RFM_RXBW_FREQUENCY_FSK_62P5  RFMRXBWFrequency = 0<<3 | 3
	RFM_RXBW_FREQUENCY_FSK_83P3  RFMRXBWFrequency = 2<<3 | 2
	RFM_RXBW_FREQUENCY_FSK_100P0 RFMRXBWFrequency = 1<<3 | 2
	RFM_RXBW_FREQUENCY_FSK_125P0 RFMRXBWFrequency = 0<<3 | 2
	RFM_RXBW_FREQUENCY_FSK_166P7 RFMRXBWFrequency = 2<<3 | 1
	RFM_RXBW_FREQUENCY_FSK_200P0 RFMRXBWFrequency = 1<<3 | 1
	RFM_RXBW_FREQUENCY_FSK_250P0 RFMRXBWFrequency = 0<<3 | 1
	RFM_RXBW_FREQUENCY_FSK_333P3 RFMRXBWFrequency = 2<<3 | 0
	RFM_RXBW_FREQUENCY_FSK_400P0 RFMRXBWFrequency = 1<<3 | 0
	RFM_RXBW_FREQUENCY_FSK_500P0 RFMRXBWFrequency = 0<<3 | 0
	RFM_RXBW_FREQUENCY_MAX       RFMRXBWFrequency = 0x1F
)

func (RFMRXBWFrequency) String

func (v RFMRXBWFrequency) String() string

type RFMTXStart

type RFMTXStart uint8
const (
	// RFM69 TX Start Condition
	RFM_TXSTART_FIFOLEVEL    RFMTXStart = 0x00 // When FIFO threshold is exceeded
	RFM_TXSTART_FIFONOTEMPTY RFMTXStart = 0x01 // When FIFO is not empty
	RFM_TXSTART_MAX          RFMTXStart = 0x01 // Mask
)

func (RFMTXStart) String

func (v RFMTXStart) String() string

type Sensor added in v1.0.4

type Sensor interface {
	// Return details of a sensor
	Namespace() string
	Key() string
	Description() string

	// Return product and sensor values or zero
	Product() uint8
	Sensor() uint32
}

type TSL2561

type TSL2561 interface {
	gopi.Driver

	// Get Version
	ChipIDVersion() (uint8, uint8)

	// Get Gain
	Gain() TSL2561Gain

	// Get Integrate Time
	IntegrateTime() TSL2561IntegrateTime

	// Set Gain
	SetGain(TSL2561Gain) error

	// Set Integrate Time
	SetIntegrateTime(TSL2561IntegrateTime) error

	// Read Luminosity Value in Lux
	ReadSample() (float64, error)
}

type TSL2561Gain

type TSL2561Gain uint8
const (
	TSL2561_GAIN_1   TSL2561Gain = 0x00
	TSL2561_GAIN_16  TSL2561Gain = 0x01
	TSL2561_GAIN_MAX TSL2561Gain = 0x01
)

func (TSL2561Gain) String

func (g TSL2561Gain) String() string

type TSL2561IntegrateTime

type TSL2561IntegrateTime uint8
const (
	TSL2561_INTEGRATETIME_13P7MS TSL2561IntegrateTime = 0x00
	TSL2561_INTEGRATETIME_101MS  TSL2561IntegrateTime = 0x01
	TSL2561_INTEGRATETIME_402MS  TSL2561IntegrateTime = 0x02
	TSL2561_INTEGRATETIME_MAX    TSL2561IntegrateTime = 0x03
)

func (TSL2561IntegrateTime) String

func (t TSL2561IntegrateTime) String() string

Directories

Path Synopsis
cmd
ads1015 command
Interacts with the ADS1015 ADC converter
Interacts with the ADS1015 ADC converter
bme280 command
Interacts with the BME280 sensor
Interacts with the BME280 sensor
bme680 command
Interacts with the BME680 sensor
Interacts with the BME680 sensor
ener314 command
Interacts with the Energenie ENER314 over GPIO
Interacts with the Energenie ENER314 over GPIO
mihome command
mihome-client command
mihome-reset command
Control Energenie MiHome devices
Control Energenie MiHome devices
mihome-service command
rfm69 command
Interacts with the RFM69 device
Interacts with the RFM69 device
sensordb-client command
tsl2561 command
Interacts with the TSL2561 sensor over the I2C bus
Interacts with the TSL2561 sensor over the I2C bus
protocol
ook
rpc
sys

Jump to

Keyboard shortcuts

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