Ejemplo n.º 1
0
        private void sendMessage()
        {
            while (true)
            {
                if (ctsForStart.IsCancellationRequested)
                {
                    return;
                }
                if (sensorController.lockState)
                {
                    continue;
                }
                sensorController.lockState = true;
                GroveMessage groveMessage = sensorController.GetSensorValue();
                sensorController.lockState = false;

                groveMessage.DeviceId = deviceId;
                var messageSerialized = JsonConvert.SerializeObject(groveMessage);
                var encodedMessage    = new Microsoft.Azure.Devices.Client.Message(Encoding.ASCII.GetBytes(messageSerialized));
                try
                {
                    iotClient.SendDeviceToCloudMessagesAsync(encodedMessage).Wait();
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.Message);
                }
                SendMessageLoger(messageSerialized);
                Task.Delay(sendMessageDelay).Wait();
            }
        }
Ejemplo n.º 2
0
        public GroveMessage GetSensorValue()
        {
            BooleanGenerator boolGen = new BooleanGenerator();
            Random           rnd     = new Random();
            GroveMessage     message = new GroveMessage();

            message.Temp      = rnd.Next(10, 30);
            message.Hum       = rnd.Next(40, 100);
            message.Sound     = rnd.Next(100, 200);
            message.Light     = rnd.Next(100, 200);
            message.GasSO     = rnd.Next(10, 100);
            message.PIR       = boolGen.NextBoolean();
            message.Timestamp = DateTime.Now.ToString();

            return(message);
        }
Ejemplo n.º 3
0
        public GroveMessage GetSensorValue()
        {
            GroveMessage message = new GroveMessage();

            try
            {
                temphumiSensor.Measure();
                message.Temp      = temphumiSensor.TemperatureInCelsius;
                message.Hum       = temphumiSensor.Humidity;
                message.Sound     = soundSensor.SensorValue();
                message.Light     = lightSensor.SensorValue();
                message.GasSO     = gasSensor.SensorValue();
                message.PIR       = pirMotion.IsPeopleDetected();
                message.Timestamp = DateTime.Now.ToString();
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(message);
        }