rpirf

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2022 License: GPL-2.0 Imports: 5 Imported by: 1

README

rpirf

A library to send 433mhz signals from a Raspberry Pi

Protocol and logic ported from https://github.com/milaq/rpi-rf

Supported Hardware

Sender

Most generic 433/315MHz capable modules connected via GPIO to a Raspberry Pi

433mhz sender

Outlets / Sockets

Most generic 433mhz remote controlled outlets do work.

generic socket

The library has been tested on following outlets from a Raspberry Pi 3b and a Raspberry Pi 2b, both running Raspbian Lite.

Limitations

As of now (March 14 2022), the library does not support receiving (sniffing) signals in order to send them later.

However, I can strongly recommend a Python library by milaq/rpi-rf, which supports sending as well as receiving data.

The golang rpirf library focusses on production usecases where performance is critical.

Installation / Setup

To install the library in your current go project, go get it using following command:

go get github.com/MikMuellerDev/rpirf

You can then import the library in your project using following code

import "github.com/MikMuellerDev/rpirf"

Getting started

Creating a new instance

Before codes can be sent, the physical device must be set up and some basic parameters, for example pulselength or protocol must be set.

	device := rpirf.NewRF(17, 1, 10, 180, 24)

The following parameters describe

  • the BCM pin number
  • protocol to use
  • How ofter each code should be sent (as redundancy)
  • The pulselength
  • The content length

Sending codes

After the device has been set up, any int can be sent as a code.
The Send method encodes the provided code to binary and sends it using the previously configured hardware.

device.Send(5121438)

Cleaning up

After all codes have been sent, it is recommended to clean the device

device.Cleanup()

Make sure to implement proper error handling for the functions above.
For a complete reference, take a look at the Example

Example

package main

import (
	"github.com/MikMuellerDev/rpirf"
)

func main() {
	device, err := rpirf.NewRF(17, 1, 10, 180, 24)
	if err != nil {
		panic(err.Error())
	}
	if err := device.Send(123456); err != nil {
		panic(err.Error())
	}
	if err := device.Cleanup(); err != nil {
		panic(err.Error())
	}

}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotInitialized     = errors.New("cannot send code: device is not initialized. make sure to initialize the device first")
	ErrCleanWOInitialized = errors.New("cannot cleanup a non-initialized device")
	ErrCleanup            = errors.New("failed to cleanup: could not close rpio")
	ErrInitialize         = errors.New("failed to initialize device: could not open rpio")
	ErrNonArm             = errors.New("unsupported architecture: this library only works on the raspberry pi (arm)")
)

Functions

This section is empty.

Types

type Protocol

type Protocol struct {
	Pulselength uint16
	SyncHigh    uint8
	SyncLow     uint8
	ZeroHigh    uint8
	ZeroLow     uint8
	OneHigh     uint8
	OneLow      uint8
}

type RFDevice

type RFDevice struct {
	Pin           rpio.Pin
	TxEnabled     bool
	TxProto       uint8
	TxRepeat      uint8
	TxLength      uint8
	TxPulseLength uint16
}

func NewRF

func NewRF(pinNumber uint8, protocolIndex uint8, repeat uint8, pulseLength uint16, length uint8) (RFDevice, error)

Initializes the GPIO device Provide a pin number, a protocol, how often the signal should be sent, the pulse length and the data length The pin number will be the `BCM / bcm2835` pin, not the physical one

func (*RFDevice) Cleanup

func (device *RFDevice) Cleanup() error

Disables the transmitter and frees the allocated GPIO pin

func (*RFDevice) Send

func (device *RFDevice) Send(code int) error

Sends the provided decimal number as a binary code

Jump to

Keyboard shortcuts

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