Esempio n. 1
0
        public async Task StartReading(SensorsData sensorsData)
        {
            Console.WriteLine("Read device to cloud messages. Ctrl-C to exit.\n");

            // Create an EventHubClient instance to connect to the
            // IoT Hub Event Hubs-compatible endpoint.
            var connectionString = new EventHubsConnectionStringBuilder(new Uri(s_eventHubsCompatibleEndpoint), s_eventHubsCompatiblePath, s_iotHubSasKeyName, s_iotHubSasKey);

            s_eventHubClient = EventHubClient.CreateFromConnectionString(connectionString.ToString());

            // Create a PartitionReciever for each partition on the hub.
            var runtimeInfo = await s_eventHubClient.GetRuntimeInformationAsync();

            var d2cPartitions = runtimeInfo.PartitionIds;

            CancellationTokenSource cts = new CancellationTokenSource();

            Console.CancelKeyPress += (s, e) =>
            {
                e.Cancel = true;
                cts.Cancel();
                Console.WriteLine("Exiting...");
            };

            var tasks = new List <Task>();

            foreach (string partition in d2cPartitions)
            {
                tasks.Add(ReceiveMessagesFromDeviceAsync(partition, cts.Token, sensorsData));
            }

            // Wait for all the PartitionReceivers to finsih.
            Task.WaitAll(tasks.ToArray());
        }
Esempio n. 2
0
        public HttpResponseMessage GetSensorData(SensorsData data)
        {
            try
            {
                IDatabase cache = lazyConnection.Value.GetDatabase();

                if (data != null)
                {
                    cache.StringSet("Temperature", Math.Round((data.TemperatureDHT + data.TemperatureBMP) / 2.0, 2));
                    cache.StringSet("Humidity", Math.Round(data.Humidity, 2));
                    cache.StringSet("Pressure", Math.Round(data.Pressure, 2));
                    cache.StringSet("HeatIndex", Math.Round(data.HeatIndex, 2));

                    //cache.KeyExpire("Temperature", new TimeSpan(24, 0, 0));
                    //cache.KeyExpire("Humidity", new TimeSpan(24, 0, 0));
                    //cache.KeyExpire("Pressure", new TimeSpan(24, 0, 0));
                    //cache.KeyExpire("HeatIndex", new TimeSpan(24, 0, 0));
                }
                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
Esempio n. 3
0
        public SensorsBinder()
        {
            DispatcherTimer timer = new DispatcherTimer();

            timer.Interval = TimeSpan.FromSeconds(1);
            timer.Tick    += Timer_Tick;
            timer.Start();

            dt = App.LUCTDatabase.GetModelLast <SensorsData>();
            var d = App.LUCTDatabase.GetModel <SensorsData>();

            //var gpio = GpioController.GetDefault();
            //nRF_CE = gpio.OpenPin(26);
            try
            {
                //init_spi();

                //nrf = new nRF(nRF_CE, Spi_port);    //nrf object
                //nrf.init_nRF();
            }

            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

            _tankHelper = new TankHelper();
        }
Esempio n. 4
0
 public static void onSensorsData(SensorsData p9)
 {
     {
         var item = p9.values();
         for (int i = 0; i < item.len(); i++)
         {
             some_ushort = item.get(i);
         }
     }
 }
Esempio n. 5
0
        private void Worker_DoWork(object sender, DoWorkEventArgs e)
        {
            List <object> argumentList = e.Argument as List <object>;
            SensorsData   sensorsData  = (SensorsData)argumentList[0];

            if (sensorsData != null)
            {
                Console.WriteLine("Calling readMessage...");
                StartReading(sensorsData).GetAwaiter().GetResult();
                e.Result = "END";
            }
        }
Esempio n. 6
0
        public void run()
        {
            List <Object> args        = new List <Object>();
            Application   application = Program.getInstance();

            Console.WriteLine("Application " + application);
            SensorsData sensorsData = application.GetSensorsData();

            Console.WriteLine("SensorsData in AzureSensore: " + sensorsData);
            args.Add(sensorsData);
            _worker                     = new BackgroundWorker();
            _worker.DoWork             += Worker_DoWork;
            _worker.RunWorkerCompleted += Work_Completed;
            _worker.RunWorkerAsync(args);
        }
Esempio n. 7
0
        public async Task <string> GetSensorTemperatureAndHumidityString()
        {
            string returnString = Common.GetLocalizedText("SensorUnavailableText");

            if (SensorEnabled)
            {
                returnString = string.Empty;
                SensorsData data = await _sensorServer.GetSensorDataAsync();

                if (FahrenheitEnabled)
                {
                    returnString += data.tempF + "°F - ";
                }
                if (CelsiusEnabled)
                {
                    returnString += data.tempC + "°C - ";
                }
                returnString += data.humidity + "%";
            }
            return(returnString);
        }
Esempio n. 8
0
        static void Main(string[] args)
        {
            // Set configuration parameters
            InitParameters init_params = new InitParameters();

            init_params.resolution = RESOLUTION.HD1080;
            init_params.cameraFPS  = 30;
            Camera zed = new Camera(0);
            // Open the camera
            ERROR_CODE err = zed.Open(ref init_params);

            if (err != ERROR_CODE.SUCCESS)
            {
                Environment.Exit(-1);
            }

            SensorsData sensors_data       = new SensorsData();
            ulong       last_imu_timestamp = 0;

            RuntimeParameters runtimeParameters = new RuntimeParameters();

            while (zed.Grab(ref runtimeParameters) == ERROR_CODE.SUCCESS)
            {
                zed.GetSensorsData(ref sensors_data, TIME_REFERENCE.CURRENT);
                if (sensors_data.imu.timestamp > last_imu_timestamp)
                {
                    // Show Sensors Data
                    Console.WriteLine("IMU Orientation : " + sensors_data.imu.fusedOrientation);
                    Console.WriteLine("Angular Velocity : " + sensors_data.imu.angularVelocity);
                    Console.WriteLine("Magnetometer Magnetic field : " + sensors_data.magnetometer.magneticField);
                    Console.WriteLine("Barometer Atmospheric pressure : " + sensors_data.barometer.pressure);
                    last_imu_timestamp = sensors_data.imu.timestamp;
                    // Wait for the [ENTER] key to be pressed
                    Console.ReadLine();
                }
            }
            zed.Close();
        }
Esempio n. 9
0
        // Asynchronously create a PartitionReceiver for a partition and then start
        // reading any messages sent from the simulated client.
        private async Task ReceiveMessagesFromDeviceAsync(string partition, CancellationToken ct, SensorsData sensorsData)
        {
            // Create the receiver using the default consumer group.
            // For the purposes of this sample, read only messages sent since
            // the time the receiver is created. Typically, you don't want to skip any messages.
            var eventHubReceiver = s_eventHubClient.CreateReceiver("$Default", partition, EventPosition.FromEnqueuedTime(DateTime.Now));

            Console.WriteLine("Create receiver on partition: " + partition);
            while (true)
            {
                //if (ct.IsCancellationRequested) break;
                Console.WriteLine("Listening for messages on: " + partition);
                // Check for EventData - this methods times out if there is nothing to retrieve.
                var events = await eventHubReceiver.ReceiveAsync(100);

                // If there is data in the batch, process it.
                if (events == null)
                {
                    continue;
                }

                foreach (EventData eventData in events)
                {
                    string data = Encoding.UTF8.GetString(eventData.Body.Array);
                    Console.WriteLine("Message received on partition {0}:", partition);
                    Console.WriteLine("  {0}:", data);
                    Console.WriteLine("Application properties (set by device):");
                    foreach (var prop in eventData.Properties)
                    {
                        Console.WriteLine("  {0}: {1}", prop.Key, prop.Value);
                    }
                    Console.WriteLine("System properties (set by IoT Hub):");
                    foreach (var prop in eventData.SystemProperties)
                    {
                        Console.WriteLine("  {0}: {1}", prop.Key, prop.Value);
                    }
                    sensorsData.AddData(eventData);
                }
            }
        }
Esempio n. 10
0
        public static async void DecodeRespose(int slaveId, byte[] response)
        {
            if (slaveId == 8)
            {
                if (response[0] == 1)
                {
                    await App.LUCTGPIOService.CapturePhoto();

                    await I2cHelper.WriteRead(new Slave()
                    {
                        I2cAddress = 9
                    }, Mode.Mode1, 0, 0, new SmsSlaveModel()
                    {
                        Sflag = Sflag.BadKeyPadAttempts, SmsSend = 1, Switch1 = -1, Switch2 = -1
                    });
                }
                if (response[1] == 1 || response[2] == 1)
                {
                    App.LUCTGPIOService.ChangeLedState(true);
                }
            }
            else
            {
                SensorsData sensor = new SensorsData()
                {
                    TankLevel   = response[0],
                    Temperature = response[1],
                    Humidity    = response[2],
                    Current     = (((response[4] + response[5])) * 220 * 0.9) / 1000
                };
                Debug.WriteLine(response[0]);
                SensorsBinder.dt = sensor;
                _database.InsertModel <SensorsData>(sensor);
                if ((response[4]) * 220 * 0.9 > 4000)
                {
                    AppKeys.Switch1State = true;
                    //AppKeys.Switch1 = true ;
                }
                else
                {
                    AppKeys.Switch1State = false;
                    //AppKeys.Switch1 = false;
                }
                if ((response[5]) * 220 * 0.9 > 4000)
                {
                    AppKeys.Switch2State = true;
                    //AppKeys.Switch2 = true;
                }
                else
                {
                    AppKeys.Switch2State = false;
                    //AppKeys.Switch2 = false;
                }
                if (response[7] == 1)
                {
                    _database.InsertModel <Models.Database.PillsTaken>(new Models.Database.PillsTaken()
                    {
                        Time = DateTime.Now
                    });
                    AppKeys.PillState = true;
                }
                else
                {
                    AppKeys.PillState = false;
                }

                HandleRFlag(response[6]);

                Debug.WriteLine(response[4] * 220 * 0.9 + " From i2c switch 1");
                Debug.WriteLine(response[5] * 220 * 0.9 + "From i2c switch 2");
            }
        }
Esempio n. 11
0
 private void Init()
 {
     sensorsData = new SensorsData();
     receiver    = new ReceiveController();
     receiver.Init();
 }
Esempio n. 12
0
 public SensorsData_dst_adapter(SensorsData dst)
 {
     this.dst = dst;
 }
Esempio n. 13
0
 public void run()
 {
     sensorsData = new SensorsData();
     startCollectingData();
 }