{"id":22468518,"url":"https://github.com/projectweekend/raspberry-pi-io-api","last_synced_at":"2025-03-27T15:44:37.554Z","repository":{"id":27046814,"uuid":"30512023","full_name":"projectweekend/raspberry-pi-io-api","owner":"projectweekend","description":null,"archived":false,"fork":false,"pushed_at":"2015-04-11T16:07:17.000Z","size":280,"stargazers_count":0,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-01T19:29:46.785Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/projectweekend.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-02-09T00:49:31.000Z","updated_at":"2015-09-27T14:57:34.000Z","dependencies_parsed_at":"2022-08-31T19:40:09.720Z","dependency_job_id":null,"html_url":"https://github.com/projectweekend/raspberry-pi-io-api","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/projectweekend%2Fraspberry-pi-io-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/projectweekend%2Fraspberry-pi-io-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/projectweekend%2Fraspberry-pi-io-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/projectweekend%2Fraspberry-pi-io-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/projectweekend","download_url":"https://codeload.github.com/projectweekend/raspberry-pi-io-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245874196,"owners_count":20686724,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-06T11:17:02.229Z","updated_at":"2025-03-27T15:44:37.532Z","avatar_url":"https://github.com/projectweekend.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Deploy with Heroku\n\nTo deploy your own Raspberry Pi IO server first create a Heroku account and install the Heroku Command Line utility. This link has info about how to do that: [https://devcenter.heroku.com/articles/getting-started-with-nodejs#set-up](https://devcenter.heroku.com/articles/getting-started-with-nodejs#set-up). Once installed, follow these steps:\n\n* Clone this repo: `git clone git@github.com:exitcodezero/raspberry-pi-io-api.git`\n* Create a new Heroku app using the command line inside the cloned directory: `heroku create whatever-you-name-it`\n* Log into the [Heroku Dashboard](https://dashboard.heroku.com/apps/), click on the named app you just created and go to the **Settings** section. Find the **Congif Variables** area, click Edit and add the following variables.\n* `JWT_EXPIRES`: The number of minutes for an authentication token to remain valid.\n* `JWT_SECRET`: Any random string of characters. This is used to encrypt the authentication tokens.\n* `MONGO_URL`: The connection URL for a MongoDB. You can create a free MongoDB at [MongoLab](https://mongolab.com/login/) that will work with this API.\n* `NODE_ENV`: Set this to `production`.\n* `RABBIT_URL`: The connection URL for a RabbitMQ server. You can create a free RabbitMQ server at [CloudAMQP](http://www.cloudamqp.com/) that will support up to 3 concurrent connections. That's enough for one connection from the controller application and two Raspberry Pi devices.\n* `SYSTEM_API_KEY`: Any random string of characters. This will be the value used in the `SYSTEM-API-KEY` header (see below).\n* Deploy: `git push heroku master`\n\n\n## API General Info\n\n* All routes, with the exception of `/pin-config` require an API key be passed in the header `SYSTEM-API-KEY`\n* All routes, with the exception of `/pin-config`, `/register`, `/authenticate` require an auth token be passed in the `Authorization` header. The header value should be formatted `Bearer \u003ctoken\u003e`. A token can be obtained using the `/register` or `/authenticate` routes.\n* The `/pin-config` route requires special authentication using three headers. `io-user-email` is the email address of a registered user. `io-device-id` is the ID of a registered device and must also belong to the email in `io-user-email`. `io-user-key` is a secret key generated for a user on the `/user/key` route.\n\n\n## API Routes\n\n\n### Register a user\n\n**POST:** `/register`\n\n**Body:**\n```json\n{\n    \"email\": \"something@something.com\",\n    \"password\": \"$ecR3tP@ssw0rd\"\n}\n```\n\n**Response:**\n```json\n{\n    \"token\": \"somesuperlongauthtokenstring\"\n}\n```\n\n**Status Codes:**\n* `201` if successful\n* `400` if incorrect data provided\n* `409` if email already in use\n\n\n### Authenticate a user\n\n**POST:** `/authenticate`\n\n**Body:**\n```json\n{\n    \"email\": \"something@something.com\",\n    \"password\": \"$ecR3tP@ssw0rd\"\n}\n```\n\n**Response:**\n```json\n{\n    \"token\": \"somesuperlongauthtokenstring\"\n}\n```\n\n**Status Codes:**\n* `200` if successful\n* `400` if incorrect data provided\n* `401` if incorrect credentials provided\n\n\n### Get detail for the authenticated user\n\n**GET:** `/user`\n\n**Response:**\n```json\n{\n    \"email\": \"something@something.com\"\n}\n```\n\n**Status Codes:**\n* `200` if successful\n* `401` if not authenticated\n* `403` if `SYSTEM-API-KEY` is missing\n\n\n### Remove the authenticated user\n\n**DELETE:** `/user`\n\n**Response:** None\n\n**Status Codes:**\n* `204` if successful\n* `401` if not authenticated\n* `403` if `SYSTEM-API-KEY` is missing\n\n\n### Generate an `io-user-key` for the authenticated user\n\n**POST:** `/user/key`\n\n**Body:** None\n\n**Response:**\n```json\n{\n    \"key\": \"some-secret-user-key\"\n}\n```\n\n**Status Codes:**\n* `201` if successful\n* `401` if not authenticated\n* `403` if `SYSTEM-API-KEY` is missing\n\n\n### Register a new device\n\n**POST:** `/user/device`\n\n**Body:**\n```json\n{\n    \"type\": \"rpiA\"\n}\n```\n\n**Response:**\n```json\n{\n    \"_id\": \"device_id\",\n    \"userEmail\": \"something@something.com\",\n    \"type\": \"rpiA\",\n    \"pinConfig\": []\n}\n```\n\n**Status Codes:**\n* `201` if successful\n* `400` if incorrect data provided\n* `401` if not authenticated\n* `403` if `SYSTEM-API-KEY` is missing\n\n**Accepted `type` values:**\n* `rpiA`\n* `rpiB`\n* `rpiAPlus`\n* `rpiBPlus`\n* `rpi2B`\n\n\n### List devices\n\n**GET:** `/user/device`\n\n**Response:**\n```json\n[\n    {\n        \"_id\": \"device_id\",\n        \"userEmail\": \"something@something.com\",\n        \"type\": \"rpiA\",\n        \"pinConfig\": []\n    }\n]\n```\n\n**Status Codes:**\n* `200` if successful\n* `401` if not authenticated\n* `403` if `SYSTEM-API-KEY` is missing\n\n\n### View detail of a single device\n\n**GET:** `/user/device/:deviceId`\n\n**Response:**\n```json\n{\n    \"_id\": \"device_id\",\n    \"userEmail\": \"something@something.com\",\n    \"type\": \"rpiA\",\n    \"pinConfig\": []\n}\n```\n\n**Status Codes:**\n* `200` if successful\n* `401` if not authenticated\n* `403` if `SYSTEM-API-KEY` is missing\n* `404` if deviceId does not exist\n\n\n### Remove a device\n\n**DELETE:** `/user/device/:deviceId`\n\n**Response:** None\n\n**Status Codes:**\n* `204` if successful\n* `401` if not authenticated\n* `403` if `SYSTEM-API-KEY` is missing\n* `404` if deviceId does not exist\n\n\n### Add a pin configuration to a device\n\n**POST:** `/user/device/:deviceId/pin`\n\n**Body:**\n```json\n{\n    \"pin\": 18,\n    \"name\": \"Red LED\",\n    \"mode\": \"OUT\"\n}\n```\n\n**Response:**\n```json\n{\n    \"pin\": 18,\n    \"name\": \"Red LED\",\n    \"mode\": \"OUT\",\n    \"initial\": \"LOW\"\n}\n```\n\n**Required Body Properties:**\n* `pin` - Pin number (integer)\n* `name` - Custom text label for the pin\n* `mode` - `IN` or `OUT`\n\n**Optional Body Properties:**\n* `resistor` - `PUD_UP` or `PUD_DOWN`\n* `initial` - `HIGH` or `LOW`\n* `pinEvent` - `RISING`, `FALLING`, `BOTH`\n* `bounce` - Number of milliseconds (integer)\n\n\n**Status Codes:**\n* `201` if successful\n* `400` if invalid data\n* `401` if not authenticated\n* `403` if `SYSTEM-API-KEY` is missing\n* `409` if `pin` is not available for `device.type`\n\n\n### List pin configurations for a device\n\n**GET:** `/user/device/:deviceId/pin`\n\n**Response:**\n```json\n[\n    {\n        \"pin\": 18,\n        \"name\": \"Red LED\",\n        \"mode\": \"OUT\",\n        \"initial\": \"LOW\"\n    }\n]\n```\n\n**Status Codes:**\n* `200` if successful\n* `401` if not authenticated\n* `403` if `SYSTEM-API-KEY` is missing\n* `404` if deviceId does not exist\n\n\n### View detail for a single pin configuration\n\n**GET:** `/user/device/:deviceId/pin/:pinId`\n\n**Response:**\n```json\n{\n    \"pin\": 18,\n    \"name\": \"Red LED\",\n    \"mode\": \"OUT\",\n    \"initial\": \"LOW\"\n}\n```\n\n**Status Codes:**\n* `200` if successful\n* `401` if not authenticated\n* `403` if `SYSTEM-API-KEY` is missing\n* `404` if deviceId or pinId does not exist\n\n\n### Remove a pin configuration from a device\n\n**DELETE:** `/user/device/:deviceId/pin/:pinId`\n\n**Response:** None\n\n**Status Codes:**\n* `204` if successful\n* `401` if not authenticated\n* `403` if `SYSTEM-API-KEY` is missing\n* `404` if deviceId or pinId does not exist\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprojectweekend%2Fraspberry-pi-io-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprojectweekend%2Fraspberry-pi-io-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprojectweekend%2Fraspberry-pi-io-api/lists"}