gorfxtrx

package module
v0.0.0-...-22f3b09 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2022 License: MIT Imports: 11 Imported by: 2

README

gorfxtrx

Build Status GoDoc

Go library for the RFXcom RFXtrx433 USB transceiver:

http://www.rfxcom.com/store/Transceivers/12103

The RFXtrx433 is great for home automation. It's affordable, both receives and transmits, and it supports a huge variety of devices.

Supported transmitter / receivers

  • Oregon weather devices (THGR810, WTGR800, THN132N, PCR800, etc.)
  • X10 RF devices (Domia Lite, HE403, etc.)
  • HomeEasy devices (HE300, HE301, HE303, HE305, etc.)

RFXcom devices tested

  • RFXcom RFXtrx433 USB Transceiver

Installation

Run:

go get github.com/barnybug/gorfxtrx

Usage

Example:

import (
    "fmt"
    "github.com/barnybug/gorfxtrx"
)

func main() {
    dev, err := gorfxtrx.Open("/dev/serial/by-id/usb-RFXCOM-...", true)
    if err != nil {
        panic("Error opening device")
    }

    for {
        packet, err := dev.Read()
        if err != nil {
            continue
        }

        fmt.Println("Received", packet)
    }
    dev.Close()
}

Changelog

0.1.0

  • First release

Documentation

Overview

Package gorfxtrx is a library for the RFXcom RFXtrx433 USB transceiver.

http://www.rfxcom.com/store/Transceivers/12103

Supported transmitter / receivers:

- Oregon weather devices (THGR810, WTGR800, THN132N, PCR800, etc.)

- X10 RF devices (Domia Lite, HE403, etc.)

- HomeEasy devices (HE300, HE301, HE303, HE305, etc.)

RFXcom devices tested:

- RFXcom RFXtrx433 USB Transceiver

Example usage:

import (
    "fmt"
    "github.com/barnybug/gorfxtrx"
)

func main() {
    dev, err := gorfxtrx.Open("/dev/serial/by-id/usb-RFXCOM-...", true)
    if err != nil {
        panic("Error opening device")
    }

    for {
        packet, err := dev.Read()
        if err != nil {
            continue
        }

        fmt.Println("Received", packet)
    }
    dev.Close()
}

Index

Examples

Constants

This section is empty.

Variables

View Source
var PacketTypes = map[byte]PacketType{
	0x1:  PacketType{20, "Status", func() Packet { return &Status{} }},
	0x2:  PacketType{4, "TransmitAck", func() Packet { return &TransmitAck{} }},
	0x10: PacketType{7, "LightingX10", func() Packet { return &LightingX10{} }},
	0x11: PacketType{11, "LightingHE", func() Packet { return &LightingHE{} }},
	0x16: PacketType{7, "Chime", func() Packet { return &Chime{} }},
	0x50: PacketType{8, "Temp", func() Packet { return &Temp{} }},
	0x52: PacketType{10, "TempHumid", func() Packet { return &TempHumid{} }},
	0x55: PacketType{11, "Rain", func() Packet { return &Rain{} }},
	0x59: PacketType{13, "Elec1", func() Packet { return &Elec1{} }},
	0x56: PacketType{16, "Wind", func() Packet { return &Wind{} }},
	0x5a: PacketType{17, "Elec3", func() Packet { return &Elec3{} }},
}
View Source
var States = map[uint8]string{
	0:   "ACK",
	1:   "ACK_DELAYED",
	2:   "NACK",
	3:   "NACK_INVALID_AC_ADDRESS",
	255: "UNKNOWN",
}

Functions

This section is empty.

Types

type Chime

type Chime struct {
	SequenceNumber byte

	Chime   byte
	Battery byte
	Rssi    byte
	// contains filtered or unexported fields
}

Struct for the Chime packets.

Example
x, _ := Parse([]byte{0x07, 0x16, 0x00, 0x06, 0x00, 0x7a, 0x01, 0x70})
chime := *x.(*Chime)
fmt.Printf("%+v\n", chime)
fmt.Printf("%+v\n", chime.Id())
fmt.Printf("%+v\n", chime.Type())
Output:
{typeId:0 SequenceNumber:6 id:122 Chime:1 Battery:0 Rssi:7}
00:7a
Byron SX

func NewChime

func NewChime(typeId byte, id string, chime byte) (*Chime, error)

func (*Chime) Id

func (self *Chime) Id() string

Id of the device.

func (*Chime) Receive

func (self *Chime) Receive(data []byte)

func (*Chime) Send

func (self *Chime) Send() []byte

func (*Chime) Type

func (self *Chime) Type() string

Type of the device.

type Device

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

Device representing the serial connection to the USB device.

func Open

func Open(path string, debug bool) (*Device, error)

Open the device at the given path.

func (*Device) Close

func (self *Device) Close()

Close the device.

func (*Device) Read

func (self *Device) Read() (Packet, error)

Read a packet from the device. Blocks until data is available.

func (*Device) Send

func (self *Device) Send(p OutPacket) error

Send (transmit) a packet.

type Elec1

type Elec1 struct {
	Subtype  uint8
	SeqNr    uint8
	SensorId uint16
	Count    uint8
	Current1 float64
	Current2 float64
	Current3 float64
	Signal   uint8
	Battery  byte
}

Elec1 devices: OWL CM113, cent-a-meter, Electrisave

func (*Elec1) Receive

func (self *Elec1) Receive(data []byte)

func (*Elec1) String

func (self *Elec1) String() string

type Elec3

type Elec3 struct {
	Subtype  uint8
	SeqNr    uint8
	SensorId uint16
	Power    uint32
	Total    float64
	Signal   uint8
	Battery  byte
}

Elec3 devices: OWL CM180

func (*Elec3) Receive

func (self *Elec3) Receive(data []byte)

func (*Elec3) String

func (self *Elec3) String() string

type LightingHE

type LightingHE struct {
	SequenceNumber byte
	HouseCode      uint32
	UnitCode       byte

	Level byte
	// contains filtered or unexported fields
}

Struct for Homeeasy lighting packets.

Example
x, _ := Parse([]byte{0x0b, 0x11, 0x00, 0x2a, 0x01, 0x23, 0x45, 0x67, 0x05, 0x02, 0x08, 0x70})
lighting := *x.(*LightingHE)
fmt.Printf("%+v\n", lighting)
fmt.Println(lighting.Type())
fmt.Println(lighting.Id())
fmt.Println(lighting.Command())
Output:
{typeId:0 SequenceNumber:42 HouseCode:19088743 UnitCode:5 command:2 Level:8}
AC
12345675
set level

func NewLightingHE

func NewLightingHE(typeId byte, id string, command string) (*LightingHE, error)

func (*LightingHE) Command

func (self *LightingHE) Command() string

Command transmitted.

func (*LightingHE) Id

func (self *LightingHE) Id() string

Id of the device.

func (*LightingHE) Receive

func (self *LightingHE) Receive(data []byte)

func (*LightingHE) Send

func (self *LightingHE) Send() []byte

func (*LightingHE) Type

func (self *LightingHE) Type() string

Type of the device.

type LightingX10

type LightingX10 struct {
	SequenceNumber byte
	HouseCode      byte
	UnitCode       byte
	// contains filtered or unexported fields
}

Struct for X10 Lighting packets.

Example
x, _ := Parse([]byte{0x07, 0x10, 0x00, 0x2a, 0x45, 0x05, 0x01, 0x70})
lighting := *x.(*LightingX10)
fmt.Printf("%+v\n", lighting)
fmt.Println(lighting.Type())
fmt.Println(lighting.Id())
fmt.Println(lighting.Command())
Output:
{typeId:0 SequenceNumber:42 HouseCode:69 UnitCode:5 command:1}
X10 lighting
e05
on

func NewLightingX10

func NewLightingX10(typeId byte, id string, command string) (*LightingX10, error)

func (*LightingX10) Command

func (self *LightingX10) Command() string

Command transmitted.

func (*LightingX10) Id

func (self *LightingX10) Id() string

Id of the device.

func (*LightingX10) Receive

func (self *LightingX10) Receive(data []byte)

func (*LightingX10) Send

func (self *LightingX10) Send() []byte

func (*LightingX10) Type

func (self *LightingX10) Type() string

Type of the device.

type LogReadWriteCloser

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

A logging ReadWriteCloser for debugging

func (LogReadWriteCloser) Close

func (self LogReadWriteCloser) Close() error

func (LogReadWriteCloser) Read

func (self LogReadWriteCloser) Read(b []byte) (int, error)

func (LogReadWriteCloser) Write

func (self LogReadWriteCloser) Write(b []byte) (int, error)

type MockSerialPort

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

func NewMockSerialPort

func NewMockSerialPort(replay [][]byte) *MockSerialPort

func (*MockSerialPort) Close

func (self *MockSerialPort) Close() error

func (*MockSerialPort) Read

func (self *MockSerialPort) Read(b []byte) (int, error)

func (*MockSerialPort) Write

func (self *MockSerialPort) Write(b []byte) (int, error)

type OutPacket

type OutPacket interface {
	// Serialize packet to wire format
	Send() []byte
}

Interface representing a transmittable packet.

type Packet

type Packet interface {
	// Deserialize packet from wire format
	Receive(data []byte)
}

Interface representing a received packet.

func Parse

func Parse(data []byte) (Packet, error)

Parse a packet from a byte array.

type PacketType

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

type Rain

type Rain struct {
	SequenceNumber byte

	RainRate  float64
	RainTotal float64
	Battery   byte
	Rssi      byte
	// contains filtered or unexported fields
}

Struct for the Rain packets.

Example
x, _ := Parse([]byte{0x0b, 0x55, 0x02, 0x03, 0x12, 0x34, 0x02, 0x50, 0x01, 0x23, 0x45, 0x57})
rain := *x.(*Rain)
fmt.Printf("%+v\n", rain)
fmt.Println(rain.Id())
fmt.Println(rain.Type())
Output:
{typeId:2 SequenceNumber:3 id:4660 RainRate:5.92 RainTotal:7456.5 Battery:70 Rssi:5}
12:34
PCR800

func (*Rain) Id

func (self *Rain) Id() string

Id of the device.

func (*Rain) Receive

func (self *Rain) Receive(data []byte)

func (*Rain) Type

func (self *Rain) Type() string

Type of the device.

type Reset

type Reset struct {
}

Struct for the Reset packet type.

func NewReset

func NewReset() (*Reset, error)

Reset packet constructor.

func (*Reset) Send

func (self *Reset) Send() []byte

type SetMode

type SetMode struct {
	AeBlyss          bool
	Rubicson         bool
	FineoffsetViking bool
	Lighting4        bool
	Rsl              bool
	ByronSX          bool
	Rfu6             bool
	Edisplay         bool
	Mertik           bool
	Lightwarerf      bool
	Hideki           bool
	Lacrosse         bool
	Fs20             bool
	Proguard         bool
	Blindst0         bool
	Blindst1         bool
	X10              bool
	Arc              bool
	Ac               bool
	Homeeasy         bool
	Ikeakoppla       bool
	Oregon           bool
	Ati              bool
	Visonic          bool
}

Struct for the SetMode packet type.

func NewSetMode

func NewSetMode() (*SetMode, error)

SetMode packet constructor

func (*SetMode) Send

func (self *SetMode) Send() []byte

type Status

type Status struct {
	TransceiverType byte
	FirmwareVersion byte
	// contains filtered or unexported fields
}

Struct for the Status packet type.

Example
pkt, err := Parse([]byte{0x14, 0x01, 0x00, 0x01, 0x03, 0x53, 0x09, 0x20, 0x00, 0x2f, 0x00, 0x01, 0x01, 0x1c, 0x01, 0x00, 0x049, 0x00, 0x00, 0x00, 0x00})
fmt.Printf("%v\n", pkt)
fmt.Println(err)
Output:
Status: type: 433.92MHz transceiver: 83 firmware: 9 protocols: ac, arc, byron sx, homeeasy, oregon, x10
<nil>

func (*Status) Protocols

func (self *Status) Protocols() []string

Protocols enabled for the device.

func (*Status) Receive

func (self *Status) Receive(data []byte)

func (*Status) Send

func (self *Status) Send() []byte

func (*Status) String

func (self *Status) String() string

func (*Status) TypeString

func (self *Status) TypeString() string

Type of connected device.

type Temp

type Temp struct {
	SequenceNumber byte

	Temp    float64
	Battery byte
	Rssi    byte
	// contains filtered or unexported fields
}

Struct for the Temp packets.

Example
x, _ := Parse([]byte{0x08, 0x50, 0x02, 0x2a, 0x96, 0x03, 0x81, 0x41, 0x79})
temp := *x.(*Temp)
fmt.Printf("%+v\n", temp)
fmt.Printf("%+v\n", temp.Id())
fmt.Printf("%+v\n", temp.Type())
Output:
{typeId:2 SequenceNumber:42 id:38403 Temp:-32.1 Battery:90 Rssi:7}
96:03
THC238/268,THN132,THWR288,THRN122,THN122,AW129/131

func (*Temp) Id

func (self *Temp) Id() string

Id of the device.

func (*Temp) Receive

func (self *Temp) Receive(data []byte)

func (*Temp) Type

func (self *Temp) Type() string

Type of the device.

type TempHumid

type TempHumid struct {
	TypeId         byte
	SequenceNumber byte

	Temp           float64
	Humidity       byte
	HumidityStatus byte
	Battery        byte
	Rssi           byte
	// contains filtered or unexported fields
}

Struct for the TempHumid packets

Example
x, _ := Parse([]byte{0x0a, 0x52, 0x01, 0x2a, 0x96, 0x03, 0x81, 0x41, 0x60, 0x03, 0x79})
temp := *x.(*TempHumid)
fmt.Printf("%+v\n", temp)
fmt.Printf("%+v\n", temp.Id())
fmt.Printf("%+v\n", temp.Type())
Output:
{TypeId:1 SequenceNumber:42 id:38403 Temp:-32.1 Humidity:96 HumidityStatus:3 Battery:90 Rssi:7}
96:03
THGN122/123, THGN132, THGR122/228/238/268

func (*TempHumid) Id

func (self *TempHumid) Id() string

Id of the device.

func (*TempHumid) Receive

func (self *TempHumid) Receive(data []byte)

func (*TempHumid) Type

func (self *TempHumid) Type() string

Type of the device.

type TransmitAck

type TransmitAck struct {
	Subtype uint8
	SeqNr   uint8
	State   uint8
}

Struct for the TransmitAck packets.

Example
pkt, err := Parse([]byte{0x04, 0x02, 0x01, 0x00, 0x00})
fmt.Printf("%v\n", pkt)
fmt.Println(err)
Output:
TransmitAck: ACK
<nil>

func (*TransmitAck) OK

func (self *TransmitAck) OK() bool

func (*TransmitAck) Receive

func (self *TransmitAck) Receive(data []byte)

func (*TransmitAck) String

func (self *TransmitAck) String() string

type Unknown

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

Struct for an Unknown packet type.

Example
pkt, _ := Parse([]byte{0x01, 0xFF})
fmt.Printf("%+v\n", pkt)
Output:
Unknown: 01ff

func (*Unknown) Receive

func (self *Unknown) Receive(data []byte)

func (*Unknown) Send

func (self *Unknown) Send() []byte

func (*Unknown) String

func (self *Unknown) String() string

type Wind

type Wind struct {
	SequenceNumber byte

	Direction    uint16
	AverageSpeed float64
	Gust         float64
	Battery      byte
	Rssi         byte
	// contains filtered or unexported fields
}

Struct for the Wind packets.

Example
x, _ := Parse([]byte{0x10, 0x56, 0x01, 0x03, 0x2F, 0x00, 0x00, 0xF7, 0x00, 0x20, 0x00, 0x24, 0x01, 0x60, 0x00, 0x00, 0x59})
wind := *x.(*Wind)
fmt.Printf("%+v\n", wind)
fmt.Println(wind.Id())
fmt.Println(wind.Type())
Output:
{data:[16 86 1 3 47 0 0 247 0 32 0 36 1 96 0 0 89] typeId:1 SequenceNumber:3 id:12032 Direction:247 AverageSpeed:3.2 Gust:3.6 Battery:90 Rssi:5}
2f:00
WTGR800

func (*Wind) Id

func (self *Wind) Id() string

Id of the device.

func (*Wind) Receive

func (self *Wind) Receive(data []byte)

func (*Wind) Type

func (self *Wind) Type() string

Type of the device.

Jump to

Keyboard shortcuts

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