https://github.com/smarthome-go/rpirf
A Go library for sending 433mhz signals from a Raspberry Pi
https://github.com/smarthome-go/rpirf
433mhz go golang gpio-library hardware-libraries radio-control raspberry-pi
Last synced: 2 months ago
JSON representation
A Go library for sending 433mhz signals from a Raspberry Pi
- Host: GitHub
- URL: https://github.com/smarthome-go/rpirf
- Owner: smarthome-go
- License: gpl-2.0
- Created: 2022-05-06T19:34:08.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2023-09-02T21:19:50.000Z (almost 3 years ago)
- Last Synced: 2024-11-15T01:55:03.309Z (over 1 year ago)
- Topics: 433mhz, go, golang, gpio-library, hardware-libraries, radio-control, raspberry-pi
- Language: Go
- Homepage: https://pkg.go.dev/github.com/smarthome-go/rpirf
- Size: 38.1 KB
- Stars: 4
- Watchers: 0
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rpirf
A library for sending `433mhz` signals via 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 will work with this library.
The picture below displays a unit which has been tested.

### Outlets / Sockets
Most generic 433mhz remote controlled outlets do work.
The picture below displays a outlet which works with the sender and library.

The library has been tested on following outlets using 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, a Python library by [milaq/rpi-rf](https://github.com/milaq/rpi-rf) is recommended, which supports sending as well as receiving data.
However, the go *rpirf* library is only supposed to support sending.
## Installation / Setup
To install the library in your current go project, *go get* it using following command:
```
go get github.com/smarthome-go/rpirf
```
You can then import the library in your project using following code
```go
import "github.com/smarthome-go/rpirf"
```
## Getting started
### Creating a *new instance*
Before data can be sent, the physical device must be set up, and some basic parameters, for example *pulselength* or *protocol* must be set.
```go
device := rpirf.NewRF(17, 1, 10, 180, 24)
```
The following parameters describe
- the `BCM` pin number
- Protocol to use
- How often each code should be sent (for 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.
```go
device.Send(5121438)
```
### Cleaning up
After all data has been sent, it is recommended to clean the device.
However, in a typical setup, this function is either `defered` or called on program exit.
```go
device.Cleanup()
```
Make sure to implement proper error handling for the functions above.
For a complete reference, take a look at the [Example](#example)
## Example
```go
package main
import (
"github.com/smarthome-go/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())
}
}
```