https://github.com/selfup/sinio
Sinatra Micro Service API for Raspberry Pi GPIO :smile:
https://github.com/selfup/sinio
api gpio gpio-pins microservice raspberrypi ruby sinatra
Last synced: 8 months ago
JSON representation
Sinatra Micro Service API for Raspberry Pi GPIO :smile:
- Host: GitHub
- URL: https://github.com/selfup/sinio
- Owner: selfup
- License: mit
- Created: 2017-05-24T07:09:19.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-09-07T00:00:14.000Z (over 8 years ago)
- Last Synced: 2025-03-16T02:27:16.644Z (about 1 year ago)
- Topics: api, gpio, gpio-pins, microservice, raspberrypi, ruby, sinatra
- Language: Ruby
- Homepage:
- Size: 66.4 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Sinatra GPIO API (sinio)
Must run on: Raspberry Pi 2 B or newer
Default is direction out on pin 17 only. You can mess around with the config :tada:
To be used as an internal node. Another application on the RPI should talk to this!
Have another app serve the api/webpage from the same raspberry pi and have it proxy via internal api calls.
*Because* we must use **sudo** to run this GPIO Server, it is best to have it as extracted as possible (micro/pico service).
### Requirements
**An up to date raspberry pi** To be sure, run `sudo apt-get update -y`
**ruby 2.3.4** *or greater* installed via `rbenv` or `rvm` on the raspberry pi
--
**rbenv sudo** [rbenv sudo](https://github.com/dcarley/rbenv-sudo)
OR
**rvmsudo** [rvmsudo](https://rvm.io/integration/sudo)
--
### Scripts (rpi only)
There is a production script that will run the app on `localhost:9292`
Run it like so: `./scripts/production.sh`
It will *run the app as a daemon* and set the RPI=true ENV VAR for you
--
There is a dev script that will not run as a daemon
It will run on the same host/port as the above script
Run it like so: `./scripts/development.sh`
--
*these scripts assume you are using `rbenv sudo` you may change them to use `rvmsudo` :rocket:*
### Options
* to set base ip: `bundle exec rackup --host 0.0.0.0`
* to set a port: `bundle exec rackup -p 8080`
* to run as daemon: `bundle exec rackup -D` (you can also use screen or tmux and detach instead of `-D`)
* to set all three (ip, port, daemon): `bundle exec rackup --host 0.0.0.0 -p 8080 -D`
**don't forget to use rbenv/rvm sudo!** ex: `rbenv sudo bundle exec rackup`
### Api
**GET (fetch pin state)**
GET -> `/pins`
**GET (update pin state)**
GET -> `/set?17=true`
*This will turn on GPIO 17*
GET -> `/set?17=false`
*This will turn off GPIO 17*