Esempio n. 1
0
        public static CameraConfiguration CreateFromEnvironmentVariables()
        {
            var result = new CameraConfiguration();

            var storageAccountEnv = Environment.GetEnvironmentVariable("storageaccount");

            if (!string.IsNullOrEmpty(storageAccountEnv))
            {
                result.StorageAccount = storageAccountEnv;
                Logger.Log($"Using storage account {result.StorageAccount}");
            }

            var storageKeyEnv = Environment.GetEnvironmentVariable("storagekey");

            if (!string.IsNullOrEmpty(storageKeyEnv))
            {
                result.StorageKey = storageKeyEnv;
            }

            result.DeviceId = Environment.GetEnvironmentVariable("IOTEDGE_DEVICEID");
            if (string.IsNullOrEmpty(result.DeviceId))
            {
                result.DeviceId = Environment.MachineName;
            }

            result.ModuleId = Environment.GetEnvironmentVariable("IOTEDGE_MODULEID");
            if (string.IsNullOrEmpty(result.ModuleId))
            {
                result.ModuleId = "camera";
            }

            var outputEventsEnv = Environment.GetEnvironmentVariable("outputevents");

            if (bool.TryParse(outputEventsEnv, out var parsedOutputEventsEnv))
            {
                result.OutputEvents = parsedOutputEventsEnv;
                Logger.Log($"Outputting events: {result.OutputEvents}");
            }


            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes the ModuleClient and sets up the callback to receive
        /// messages containing temperature information
        /// </summary>
        static async Task <int> InitAsync()
        {
            configuration = CameraConfiguration.CreateFromEnvironmentVariables();

            camera = new Camera(configuration);
            if (!camera.Initialize())
            {
                return(-1);
            }

            var transportSettings = new AmqpTransportSettings(TransportType.Amqp_Tcp_Only);

            ITransportSettings[] settings = { transportSettings };

            // Open a connection to the Edge runtime
            ModuleClient ioTHubModuleClient = await ModuleClient.CreateFromEnvironmentAsync(settings);

            await ioTHubModuleClient.OpenAsync();

            Logger.Log("Initializing Pi camera module");

            var twin = await ioTHubModuleClient.GetTwinAsync();

            HandleTwinChanges(twin.Properties.Desired);

            await ioTHubModuleClient.SetMethodDefaultHandlerAsync(ModuleMethodHandlerAsync, ioTHubModuleClient);

            Logger.Log("Default method handler initialized");

            await ioTHubModuleClient.SetDesiredPropertyUpdateCallbackAsync((updatedTwin, _) => {
                HandleTwinChanges(updatedTwin);
                return(Task.FromResult(0));
            }, null);

            Logger.Log("Twin changes callback is set");
            Logger.Log("Ready!");
            return(0);
        }
Esempio n. 3
0
 public Camera(CameraConfiguration configuration)
 {
     this.configuration = configuration;
 }