RESTful API (2)

This is part 2 of the Restful API project. Go to a previous part:

Step 4. Add Raspberry Pi Monitor Status Page

For each Raspberry Pi, click on link in step and follow directions

Step 5. Create a project directory

On the API server

Open a terminal window and login

Get a script to download and create the directories. Run the following commands:

$ cd ~/.

$ wget https://raw.githubusercontent.com/dumbo25/restful_api/master/getServer.sh

$ bash getServer.sh

On the client server:

Open a terminal window and login

Run the following commands to get the client server python script:

$ cd ~/.

$ mkdir api

$ cd api

$ wget https://raw.githubusercontent.com/dumbo25/restful_api_client/master/rest_client.py


Step 6. Download Server-side Script

This step and the next requires a Certificate Authority,

If this step was already run, then skip to the next step. Only one cert is required by the server.

Scripting cuts out many steps and sub-tasks.

Get the script.

$ cd ~/certs # /home/pi/certs was created during CA Setup

$ pwd

Note: There should be no need to wget private-data.sh because it was downloaded during the Certificate Authority Setup. Also, there should be no need to edit private-data.sh.

$ wget https://raw.githubusercontent.com/dumbo25/garage-door/main/home/pi/certs/server.sh

Once the script is downloaded, execute the script:

$ sudo bash server.sh

Take the defaults. You'll need to enter:

  • PEM-pass-phrase

  • key-pass-phrase

  • ♣export-password♣

Step 7. Download Client-side Script

The client script can be run multiple times; once for each device connecting to the web server

Get the script.

$ cd ~/certs

Note: There should be no need to wget private-data.sh because it was downloaded during the Certificate Authority Setup. Also, there should be no need to edit private-data.sh.

$ wget https://raw.githubusercontent.com/dumbo25/garage-door/main/home/pi/certs/client.sh

Once the script is downloaded, execute the script:

$ sudo bash client.sh

Take the defaults. You'll need to enter:

  • ♣device-or-user-name♣ for example, bobs-iphone, bobs-mac

  • PEM-pass-phrase

  • key-pass-phrase

  • ♣export-password♣

Step 8. Copy certs to client server

Logout of the server-side raspberry pi. Using scp, copy the server-crt.pem, client-key.pem and client-crt.pem to the laptop and then to the rest_client server

Example of an scp copy from server-side to laptop:

$ scp pi@♣server-hostname.local:/home/pi/client.crt .

Example of an scp copy from laptop to client-side:

$ scp client.crt pi@♣client-hostname.local:/home/pi/api/.

Go to the previous or next part of the RESTful API project