public RaspberryPiCameraTrap(string location, RaspberryPiCameraTrapSettings settings)
        {
            Location = location;
            Settings = settings;

            HueLights = new HueLights(settings.HueBridgeIp, settings.HueKey);

            // Connect to Azure IoT Hub
            DeviceClient             = DeviceClient.Create(settings.IotHubUri, new DeviceAuthenticationWithRegistrySymmetricKey(settings.IotHubDeviceId, settings.IotHubDeviceKey), TransportType.Mqtt);
            DeviceClient.ProductInfo = "MorrisCounter"; // I have no idea what this is

            // Turn on the IR spotlight
            Spotlight = new IrSpotlight(settings.SpotlightPin);
            Spotlight.SwitchOn();

            // Start the video stream
            Console.WriteLine("Opening video stream");
            Camera = new PiCamera(settings.CameraSettings, settings.VideoChunkDuration);
            Camera.StartVideoStream();

            // Enable the PIR Sensor and subscribe to the callback
            PirSensor sensor = new PirSensor(settings.SensorPin);

            sensor.MotionDetected += MotionDetected;
        }
Exemple #2
0
        static void Main(string[] args)
        {
            try
            {
                // Subscribe to the daemon service cancel/end events
                AssemblyLoadContext.Default.Unloading += SigTermEventHandler;
                Console.CancelKeyPress += CancelHandler;

                SetEnvVars();

                // Configure video settings
                var cameraSettings = new CameraVideoSettings()
                {
                    CaptureTimeoutMilliseconds = 0,
                    //CaptureQuantisation = 10,
                    CaptureDisplayPreview = false,
                    ImageFlipVertically   = false,
                    //CaptureFramerate = 25,
                    //CaptureKeyframeRate = 1,
                    CaptureExposure = CameraExposureMode.Night,
                    CaptureWidth    = 1280,
                    CaptureHeight   = 720,
                    //CaptureProfile = CameraH264Profile.High,
                    CaptureDisplayPreviewEncoded = false,
                    ImageAnnotationsText         = "Time %X",
                    ImageAnnotations             = CameraAnnotation.Time | CameraAnnotation.FrameNumber
                };

                // Configure trap settings
                RaspberryPiCameraTrapSettings trapSettings = new RaspberryPiCameraTrapSettings()
                {
                    ComputerVisionApiKey = Environment.GetEnvironmentVariable("computerVisionApiKey"),
                    HueBridgeIp          = Environment.GetEnvironmentVariable("hueBridgeIp"),
                    HueKey                      = Environment.GetEnvironmentVariable("hueKey"),
                    IotHubDeviceId              = Environment.GetEnvironmentVariable("iotHubDeviceId"),
                    IotHubUri                   = Environment.GetEnvironmentVariable("iotHubUri"),
                    IotHubDeviceKey             = Environment.GetEnvironmentVariable("iotHubDeviceKey"),
                    SensorPin                   = Pi.Gpio.Pin07,
                    SpotlightPin                = Pi.Gpio.Pin00,
                    TempProcessingBaseDirectory = "/home/pi/images",
                    TempProcessingImageFile     = "frame",
                    TempProcessingImageFileExt  = "jpg",
                    TempProcessingVideoFile     = "input",
                    TempProcessingVideoFileExt  = "h264",
                    VideoChunkDuration          = -8,
                    CameraSettings              = cameraSettings
                };

                // Do the needful
                cameraTrap = new RaspberryPiCameraTrap("frontdoor", trapSettings);

                while (true)
                {
                    Thread.Sleep(3000);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error: {ex.Message}: {ex.InnerException?.Message}");
                Console.WriteLine(ex.StackTrace);
            }
            finally
            {
                Console.WriteLine("Finally block");
                cameraTrap?.Dispose();
            }
        }