Categorygithub.com/gbbirkisson/rpi
modulepackage
0.2.0
Repository: https://github.com/gbbirkisson/rpi.git
Documentation: pkg.go.dev

# 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.

# Packages

No description provided by the author
No description provided by the author

# Functions

NewCommonLocal creates a new common interface that operates locally.
NewCommonRemote creates a new common interface that operates on a remote server.
NewCommonServer creates a new common server using the common interface provided.
NewGpioLocal creates a new Gpio interface that uses local gpio pins.
NewGpioRemote creates a new Gpio interface that uses remote gpio pins.
NewGpioServer creates a new gpio server that uses the gpio interface provided.
NewGrpcClientConnectionInsecure creates a new insecure grpc client connection that can used by grpc clients.
NewGrpcServerInsecure creates a new insecure grpc server that can serve grpc services.
NewNgrokLocal creates a new local Ngrok interface.
NewPiCamArgs creates the default arguments for the PiCam.
NewPiCamLocal creates a new local PiCam.
NewPiCamRemote creates a new remote PiCam.
NewPicamServer creates a picam server that uses the picam interface provided.

# Constants

High is the constant used to set a pin to high (+5v).
Input is the constant used to set a pin to input mode.
Low is the constant used to set a pin to low (0v).
Output is the constant used to set a pin to output mode.

# Interfaces

Common interface are the basic operations sometimes needed to use other the other interfaces.
Gpio interface provides a way to control and read from the GPIO pins on a RaspberryPi.
Ngrok interface provides a way to create an Ngrok tunnel to expose services to the internet.
PiCam interface provides a way to fetch frames from a PiCam connected to a RaspberryPi.

# Type aliases

PiCamArgs is a struct of arguments when initializing the PiCamera.
Pin is the raw BCM2835 pinout of a GPIO pin.
PinEdge is edge events detection modes.
PinMode is the mode of the pin, Input, Output, Clock, Pwm or Spi.
PinState is either high or low.