Skip to content

Latest commit

 

History

History

rpi-camera

RPi Camera REST

This is simple REST service daemon, which allows access camera on Raspberry PI devices remotely.

hw-arch

Hardware

Install on Raspberry PI

  1. Install Raspberry Pi OS Lite 2021-05-28
  2. Enable camera using sudo raspi-config
  3. Install software dependencies
    sudo apt install python-picamera python3-picamera
    sudo apt install python3-pip
    pip3 install RPi.GPIO
    
  4. Copy files on Raspberry Pi device into directory /opt/camera
  5. Edit configuration file camera-rest.json, set http listening port, user credentials, camera resolutions and default settings.
  6. Install and enable camera-rest as systemd service.
    sudo cp camera-rest.service /etc/systemd/system/
    sudo chown root:root /etc/systemd/system/camera-rest.service
    sudo systemctl daemon-reload
    sudo systemctl enable camera-rest
    
  7. Start | Stop camera-rest service.
    sudo systemctl start camera-rest
    sudo systemctl stop camera-rest
    sudo systemctl status camera-rest
    

REST APIs and Endpoints

  • HTTP basic authentication is required.

  • Get info about RPi Camera device.
    GET /system/info

    curl -u client-001:ex4oo \
    http://<ip-address>:<port>/system/info
    
  • Get current configuration
    GET /system/config

    curl -u client-001:ex4oo \ 
    http://<ip-address>:<port>/system/config
    
  • Set camera capture configuration
    POST /system/config
    Supported config parameters

    parameter type default description
    resolution string "R1" enum, "R1", R2", "R3", ...
    rotation int 0 enum, degrees "D0", "D90", "D180", "D270"
    framerate int 24 framerate
    curl -u client-001:ex4oo \
    --request POST \
    --url http://<ip-address>:<port>/system/config \
    --header 'Content-Type: application/json' \
    --data '{
      "resolution": "R1",
      "rotation": "D180",
      "framerate": 24
    }' 
    
  • Select connected camera for capture. This endpoint is only effective if camera controller uses hardware Camera Scheduler. Supported camera indexes: 0, 1.
    POST /system/camera

    curl -u client-001:ex4oo \
    --request POST \
    --url http://<ip-address>:<port>/system/camera \
    --header 'Content-Type: application/json' \
    --data '{  "camera": 1 }'
    
  • Get connected camera for capture.
    GET /system/camera

    curl -u client-001:ex4oo \
    http://<ip-address>:<port>/system/camera 
    
  • Get available camera resolutions.
    GET /system/resolutions

    curl -u client-001:ex4oo \
    http://<ip-address>:<port>/system/resolutions 
    
  • Get available camera rotations.
    GET /system/rotations

    curl -u client-001:ex4oo \
    http://<ip-address>:<port>/system/resolutions 
    
  • Capture single image and download it as attachment.
    GET /system/capture

    curl -u client-001:ex4oo \
    http://<ip-address>:<port>/system/capture --output snapshot.jpg
    
  • Capture video stream and download it as attachment.
    GET /system/stream.mjpg

    curl -u client-001:ex4oo \
    http://<ip-address>:<port>/system/stream.mjpg --output video.mjpg
    

Hardware Assembly

image-001

image-002

image-003

References

Enjoy !