RestPi is a django restful project. It developed for remote controlling to Raspberry Pi. It has front-end for pin controlling. Front-end developed with angularjs.
 
 
 
 
 
Go to file
ahmetkotan fce2e4b878 added postman tests -2 2019-02-03 16:29:11 +03:00
picontrol
pins
postman_tests added postman tests -2 2019-02-03 16:29:11 +03:00
restpi added installation and production settings 2019-02-02 03:19:03 +03:00
statics/static_dirs
templates cleaned small bugs 2019-02-03 15:35:37 +03:00
.gitignore added installation and production settings 2019-02-02 03:19:03 +03:00
README.md added README 2019-02-03 16:24:26 +03:00
install.sh cleaned small bugs 2019-02-03 15:35:37 +03:00
manage.py
requirements.txt cleaned small bugs 2019-02-03 15:35:37 +03:00
screenshot-pinview.png added README 2019-02-03 16:24:26 +03:00

README.md

RestPi

RestPi is a django restful project. It developed for remote controlling to Raspberry Pi. It has front-end for pin controlling. Front-end developed with angularjs.

Installation

git clone https://github.com/ahmetkotan/restpi.git
cd restpi/
./install.sh

RestPi is running on production mode. For development mode;

cp restpi/settings/local.py.sample restpi/settings/local.py

And starting;

python manage.py runserver 0.0.0.0:8000
# or
nohup python manage.py runserver 0.0.0.0:8000 &

Screenshot

pinview

API Usage for Developers

All users can view pin statuses. But just registered users can change pin statuses.

Login/Logout

Token's expiration time is 3 days.

curl -X POST -d '{"username": "<username>", "password":"<password>"}' -H "Content-Type: application/json" <raspi-url>/tokens/
{
    "token": "<a-f0-9>{64}"
}
curl -X DELETE -H "Content-Type: application/json" -H "Authorization: Bearer <token>" <raspi-url>/tokens/
# status code 204 (No Content)

See also for login/logout; ahmetkotan/tokenauth

Get All Pin Statuses

curl -X GET -H "Content-Type: application/json" <raspi-url>/pins/api
{
    "count": 40,
    "next": null,
    "previous": null,
    "results": [
	    ...
        {
            "BCM": null,
            "name": "3.3v",
            "value": null,
            "mode": null,
            "is_gpio": false,
            "physical": 1
        },
        ...
    ]
}

Get Single Pin Status

curl -X GET -H "Content-Type: application/json" <raspi-url>/pins/api/<pin_physical_no>
{
    "BCM": 17,
    "hr_mode": "IN",
    "name": "GPIO.0",
    "hr_value": "LOW",
    "value": 0,
    "mode": 1,
    "is_gpio": true,
    "physical": 11
}

Change Pin Mode and Value

curl -X POST -d '{"mode": 0/1}' -H "Content-Type: application/json" -H "Authorization: Berarer <token>" <raspi-url>/pins/api/<pin_physical_no>
curl -X POST -d '{"value": 0/1}' -H "Content-Type: application/json" -H "Authorization: Berarer <token>" <raspi-url>/pins/api/<pin_physical_no>
curl -X POST -d '{"mode": 0/1, "value": 0/1}' -H "Content-Type: application/json" -H "Authorization: Berarer <token>"  <raspi-url>/pins/api/<pin_physical_no>
{
    "operation": true,
    "pin": {
        "BCM": 17,
        "hr_mode": "OUT",
        "name": "GPIO.0",
        "hr_value": "HIGH",
        "value": 1,
        "mode": 0,
        "is_gpio": true,
        "physical": 11
    }
}

See also; postman_tests/