lightwavego

package module
v0.0.0-...-66ee831 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2015 License: MIT Imports: 1 Imported by: 0

README

lightwavego

GoDoc Build Status

LightwaveRF library for the Raspberry Pi written in Go.

See my C library for the Raspberry Pi from which this is based.

Connecting your modules

TX
  • Connect the data pin (to the default) Broadcom pin 22. This is GPIO pin 15 on the Pi.
  • Connect the VCC to the Pi's 3.3V and GND to the Pi's GND.
  • For best performance add an antenna to your TX module. This can just be a quarter-wavelength wire soldered to the module. 433 MHz quarter wavelength is 173 mm but I found best performance with my module using a length of 165 mm.

Installation

  • pigpio: This is required to control the GPIO pins on the Raspberry Pi
  • go get github.com/jimjibone/lightwavego
  • go get github.com/ant0ine/go-json-rest/rest (required for lwserver only)
  • go install github.com/jimjibone/lightwavego/examples/...
  • lwblink and lwserver will now both be in your PATH

Examples

This is basically the blink example we all know from microelectronics except that this time it's using your houses lights and it is able to dim them.

  • git clone https://github.com/jimjibone/lightwavego.git
  • cd lightwavego
  • go get github.com/jimjibone/lightwavego (if not done already)
  • go install github.com/jimjibone/lightwavego (if not done already)
  • go build examples/lwblink/lwblink.go
  • sudo ./lwblink (sudo required for GPIO access)
Server

This sets up a simple RESTful JSON server that is able to receive byte buffers of pre-compiled commands and use the library to broadcast them over your transmitter.

  • Follow the instructions above for the Blink example, but now do:
  • go build examples/lwserver/lwserver.go
  • sudo ./lwserver (sudo also required here for the GPIO access)
  • curl -i -d '{"Buffer":"090f0301050903000102"}' http://localhost:8080/send will turn a light on to max brightness

Development

For development there are some other requirements. Don't worry about these if you are just building to run.

go generate

To automatically create a nice human friendly representation of the various constants within types.go we will use stringer along with go generate. When we call go generate on the command line, generate will automatically find the stringer command within the types.go file and execute it. It will create a new go file that will help translate the constants into strings, easy.

  • go get golang.org/x/tools/cmd/stringer
  • go generate
  • Build away.

Documentation

Overview

Package lightwavego is a LightwaveRF package for the Raspberry Pi.

Basic usage:

import (
    "github.com/jimjibone/lightwavego"
    "fmt"
)

func main() {
    lwtx := lightwavego.NewLwTx()
    lightOn, err := lightwavego.NewMessage([]byte{0x9,0xf,0x3,0x1,0x5,0x9,0x3,0x0,0x1,0x2}, 2, time.Millisecond * 500)
    if err != nil {
        fmt.Error(err)
    }
    lwtx.Send(lightOn)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Shutdown

func Shutdown()

Types

type Command

type Command int
const (
	On Command = iota
	Off
	Dim
	Increase
	Decrease
	Mood
	AllOn
	AllOff
)

func (Command) String

func (i Command) String() string

type LwBuffer

type LwBuffer [10]byte

LwBuffer contains the command you wish to send along with repeat configuration.

func NewBuffer

func NewBuffer(bytebuffer []byte) (LwBuffer, error)

func (LwBuffer) Command

func (buffer LwBuffer) Command() (LwCommand, error)

Convert the LwBuffer to a LwCommand.

func (LwBuffer) Raw

func (buffer LwBuffer) Raw() []byte

Raw returns the raw byte buffer stored within the LwBuffer.

func (LwBuffer) String

func (buffer LwBuffer) String() string

String gives you a human friendly version of the LwBuffer.

type LwCommand

type LwCommand struct {
	Command Command
	Value   int // 0-31 dim levels (TODO: Moods)
	Device  int
	Address []byte
	Room    int
}

LwCommand is a helper struct to pull out the meaning of a LwBuffer, useful for logging.

func (LwCommand) Buffer

func (cmd LwCommand) Buffer() LwBuffer

Convert the LwCommand to a LwBuffer.

func (LwCommand) String

func (command LwCommand) String() string

String gives you a human friendly version of the LwCommand.

type LwTx

type LwTx struct {
	Pin       int  // 22
	Repeats   int  // 10
	Invert    bool // false
	Translate bool // true
	Period    int  // 140 (us)
}

LwTx contains the configuration of your LightwaveRF setup. The best way to create this struct, with all appropriate defaults, is to do the following e.g:

lwtx := lightwavego.NewLwTx()

func NewLwTx

func NewLwTx() *LwTx

NewLwTx returns a pointer to a LwTx struct initialised with the recommended defaults.

func (*LwTx) SendBuffer

func (lw *LwTx) SendBuffer(buffer LwBuffer) error

Send a constructed LwBuffer via the 433 MHz module.

func (*LwTx) SendCommand

func (lw *LwTx) SendCommand(command LwCommand) error

Send a constructed LwCommand via the 433 MHz module.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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