rpi

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2019 License: Apache-2.0 Imports: 13 Imported by: 0

README

rpi

This package helps you to develop software for the RaspberryPi that does IO operations on the RaspberryPi. It enables you to develop your code locally on any type of architecture, by using gRPC to control a Raspberry PI remotely. This is very convenient in conjunction with services like balena.io.

This makes developing applications for the RaspberryPi extremely easy. Once your software is ready, you have the option of continuing to use gRPC calls, or switch over to a local version of the interfaces to compile a binary that runs directly on the RaspberryPi.

If you have any suggestion or comments, please feel free to open an issue on this GitHub page.

Installing

Client / Server

There are 2 ways of installing the binaries:

  • Download the binaries latest release
  • Install from source: go get github.com/gbbirkisson/rpi
Pushing server to balena.io

Take a look at the rpi-balena project to see how to use balena.io

Configuration

Both server and client can be configured with:

  1. Flags
  2. Environment
  3. Configuration file

The presidence is in that order, i.e flags override environment that overrides the configuration file.

Flags

Use -h flag to see available flags for rpi-client and rpi-server.

Configuration files

Configuration files can be in the following formats:

  • json
  • toml
  • yaml
  • hcl

Locations of those files are:

  • Server: /etc/rpi-server/config.[format]
  • Client: ~/.rpi-client.[format]

To generate the default configuration files (yaml in this example) do:

# For server
$ touch /etc/rpi-server/config.yaml
$ rpi-server config write

# For client
$ touch ~/.rpi-client.yaml
$ rpi-client config write

The resulting client configuration file (~/.rpi-client.yaml) would be something like:

server:
  host: 127.0.0.1
  port: 8000
  timeout: 5000
picam:
  viewer:
  - feh
  - -x
  - '-'
Environmental variables

Environmental variables mirror the configuration files. All variables have the prefix RPI_. So for example if you want to set the client timeout you can set it with the environment variable RPI_SERVER_TIMEOUT=3000

Using another languages

Generate a client for your language of choice with protoc using ./pkg/proto/*.proto files.

Documentation

Overview

Package rpi helps you to develop software for the Raspberry Pi that does IO operations on the Raspberry PI. It enables you to develop your code locally on any type of architecture, by using gRPC to control a Raspberry PI remotely. This is very convenient in conjunction with services like balena.io.

This makes developing applications for the RaspberryPi extremely easy. Once your software is ready, you have the option of continuing to use gRPC calls, or switch over to a local version of the interfaces to compile a binary that runs directly on the RaspberryPi.

If you have any suggestion or comments, please feel free to open an issue on the projects GitHub page.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCommonServer

func NewCommonServer(common Common) proto.CommonServer

NewCommonServer creates a new common server using the common interface provided

func NewGpioServer

func NewGpioServer(gpio Gpio) proto.GpioServer

NewGpioServer creates a new gpio server that uses the gpio interface provided

func NewGrpcClientConnectionInsecure

func NewGrpcClientConnectionInsecure(host, port string) (*grpc.ClientConn, error)

NewGrpcClientConnectionInsecure creates a new insecure grpc client connection that can used by grpc clients

func NewGrpcServerInsecure

func NewGrpcServerInsecure(host, port string) (*grpc.Server, net.Listener, error)

NewGrpcServerInsecure creates a new insecure grpc server that can serve grpc services

func NewPicamServer

func NewPicamServer(cam PiCam) proto.PiCamServer

NewPicamServer creates a picam server that uses the picam interface provided

Types

type Common

type Common interface {
	GetVersion(ctx context.Context) (string, string, error)
	Modprobe(ctx context.Context, mod string) error
}

Common interface are the basic operations sometimes needed to use other the other interfaces

func NewCommonLocal

func NewCommonLocal() Common

NewCommonLocal creates a new common interface that operates locally

func NewCommonRemote

func NewCommonRemote(connection *grpc.ClientConn) Common

NewCommonRemote creates a new common interface that operates on a remote server

type Gpio

type Gpio interface {
	Open(ctx context.Context) error
	Close(ctx context.Context) error

	Input(ctx context.Context, pin Pin) error
	Output(ctx context.Context, pin Pin) error
	Clock(ctx context.Context, pin Pin) error
	Pwm(ctx context.Context, pin Pin) error
	PullUp(ctx context.Context, pin Pin) error
	PullDown(ctx context.Context, pin Pin) error
	PullOff(ctx context.Context, pin Pin) error

	High(ctx context.Context, pin Pin) error
	Low(ctx context.Context, pin Pin) error
	Toggle(ctx context.Context, pin Pin) error
	Write(ctx context.Context, pin Pin, state PinState) error
	Read(ctx context.Context, pin Pin) (PinState, error)

	Freq(ctx context.Context, pin Pin, freq int32) error
	DutyCycle(ctx context.Context, pin Pin, dutyLen, cycleLen int32) error
	Detect(ctx context.Context, pin Pin, edge PinEdge) error
	EdgeDetected(ctx context.Context, pin Pin) (bool, error)
}

Gpio interface provides a way to control and read from the GPIO pins on a RaspberryPi

func NewGpioLocal

func NewGpioLocal() Gpio

NewGpioLocal creates a new Gpio interface that uses local gpio pins

func NewGpioRemote

func NewGpioRemote(connection *grpc.ClientConn) Gpio

NewGpioRemote creates a new Gpio interface that uses remote gpio pins

type Ngrok

type Ngrok interface {
	Open(ctx context.Context) error
	Close(ctx context.Context) error
}

Ngrok interface provides a way to create an Ngrok tunnel to expose services to the internet

func NewNgrokLocal

func NewNgrokLocal(tunnelType, port, token, region string) (Ngrok, error)

NewNgrokLocal creates a new local Ngrok interface

type PiCam

type PiCam interface {
	Open(ctx context.Context) error
	Close(ctx context.Context) error
	GetFrame(ctx context.Context) ([]byte, error)
	GetFrames(ctx context.Context, byteCh chan<- []byte, errCh chan<- error) (<-chan struct{}, error)
}

PiCam interface provides a way to fetch frames from a PiCam connected to a RaspberryPi

func NewPiCamLocal

func NewPiCamLocal(args *PiCamArgs) (PiCam, error)

NewPiCamLocal creates a new local PiCam

func NewPiCamRemote

func NewPiCamRemote(connection *grpc.ClientConn) PiCam

NewPiCamRemote creates a new remote PiCam

type PiCamArgs

type PiCamArgs = picamera.RaspividArgs

PiCamArgs is a struct of arguments when initializing the PiCamera

func NewPiCamArgs

func NewPiCamArgs() *PiCamArgs

NewPiCamArgs creates the default arguments for the PiCam

type Pin

type Pin uint8

Pin is the raw BCM2835 pinout of a GPIO pin

type PinEdge

type PinEdge uint8

PinEdge is edge events detection modes

type PinMode added in v0.2.0

type PinMode uint8

PinMode is the mode of the pin, Input, Output, Clock, Pwm or Spi

const (
	// Input is the constant used to set a pin to input mode
	Input PinMode = iota
	// Output is the constant used to set a pin to output mode
	Output
)

type PinState

type PinState uint8

PinState is either high or low

const (
	// Low is the constant used to set a pin to low (0v)
	Low PinState = iota
	// High is the constant used to set a pin to high (+5v)
	High
)

Directories

Path Synopsis
cmd
pkg

Jump to

Keyboard shortcuts

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