Package: pinthesky
Pi In The Sky - DeviceThis is the Pi In The Sky (pits) device-side software.InstallationTo install the device software directly from GitHub, or build against it:pip3 install pintheskyYou can also use the guided install from your work station to remotely configure a RPi via ssh. Some pre-requisites are:Need to be able tosudoif selected to assume rootMake your life easier withssh-copy-id user@ipfor pub key authHave theawsCLI on your workstation with permission to create things, roles, S3 buckets, and policiesRunshlocally to enter the guide:mkdir -p $HOME/bin \
    && wget -O $HOME/bin/pitsctl https://raw.githubusercontent.com/philcali/pits-device/main/service/mainv2.sh \
    && chmod +x $HOME/bin/pitsctl \
    && pitsctl -hImportant NoteThe currentpintheskyapplication is still using the legacy camera module and is only compatible with:raspbian OS < 12 (bookworm)ArduCam 1.1 and 1.2 (< 1.3)Untilhttps://github.com/philcali/pits-device/issues/46is fixed, you must stick to the legacy OS and camera modules.ArchitectureThepintheskydaemon is very light-weight. The entirety of the application runs on 3 threads:Single thread to manage the cameraSingle thread to poll an event queueSingle thread to poll inotifyThe camera thread detects motion vectors in the recording. The buffer is flushed and an event is
signaled to combine the buffered video with the live stream. Theh264file triggers an event
to begin an upload to S3, if S3 was configured. The following camera configuration flags exists:--combine-dir COMBINE_DIR
                        the directory to combine video, defaults to
                        motion_videos
  --rotation ROTATION   rotate the video, valid arguments [0, 90, 180, 270]
  --resolution RESOLUTION
                        camera resolution, defaults 640x480
  --framerate FRAMERATE
                        framerate of the camera, defaults to 20
  --buffer BUFFER       buffer size in seconds, defaults to 15
  --sensitivity SENSITIVITY
                        sensitivity of the motion detection math, default 10Where doesinotifycome into play? An optional integration withaws-iot-device-clientexists to handle the MQTT related connections to AWS IoT. Through
theaws-iot-device-client, thepintheskycan read MQTT published messages from a file. These
events will populate the internal event queue. This is useful for manually triggering a video upload.Theaws-iot-device-clientcan also listen to AWS IoT Shadow Document updates. These updates
are written to a file whichpintheskycan read to reconfigure the camera (buffer, framerate, etc).
The follow configuration is used to pollinotifyfor changes:--event-input EVENT_INPUT
                        file representing external input, default input.json
  --event-output EVENT_OUTPUT
                        file representing external output, default output.json
  --configure-input CONFIGURE_INPUT
                        file for configuration input, default config-
                        input.json
  --configure-output CONFIGURE_OUTPUT
                        file for configuration output, default config-
                        output.jsonThe integration with AWS is entirely optional through AWS IoT device configuration.
Running the daemon with the following commands allow the device to exchange temporary
AWS V4 credentials with a X509 certificate:--thing-name THING_NAME
                        the AWS IoT ThingName for use in upload
  --thing-cert THING_CERT
                        the AWS IoT certificate associated to the Thing
  --thing-key THING_KEY
                        the AWS IoT certificate pair associated to the Thing
  --ca-cert CA_CERT     the root CA certificate to authenticate the
                        certificate
  --credentials-endpoint CREDENTIALS_ENDPOINT
                        the AWS IoT Credentials Provider endpoint
  --role-alias ROLE_ALIAS
                        the AWS IoT Role Alias to pull credentialsOnce credentials are obtained, thepintheskydaemon will attempt to upload to an S3 bucket
location. These values are configured with:--bucket-name BUCKET_NAME
                        the S3 bucket to upload motion detection files
  --bucket-prefix BUCKET_PREFIX
                        the prefix to upload the motion files to, default
                        motion_videosNote: These can be configured correctly for you if you follow the guidedpitsctlinstallation
wizard.UsageThepitsctlentry point can handle three targets:install: Installs or updates software and agents for running the camera controlremove: Removes all configuration, cloud resources, software and agentsview: Inpects the installation on the deviceUsage: pitsctl - v0.7.0: Install or manage pinthesky software
  -h,--help:    Prints out this help message
  -m,--host:    Client machine connection details
  -t,--text:    Enable a no color, text only view of the application
  -r,--root:    Assume root permission for management
  -l,--level:   Changes the logging verbosity for pitsctl
  -v,--version: Prints the version and existsOptimal SettingsAdjusting the bitrate, buffer, resolution, framerate, etc... It's a lot to take in.The default values work, but you will find the buffer doesn't quite mesh with a zero.resolution=640x480framerate=20bitrate=17000000 (17Mbps)profile=highlevel=4For a first gen PiZero, these settings might be too high. I've seen success withresolution=640x480framerate=15bitrate=5000000 (5Mbps)profile=highlevel=2.2This reduces the file size by 60% and aligns buffering to clock time a little more accurately.