Example #1
0
        private async void SendDeviceToCloudMessagesAsync(DataSensor item)
        {
            var messageString = JsonConvert.SerializeObject(item);
            var message       = new Message(Encoding.ASCII.GetBytes(messageString));

            await deviceClient.SendEventAsync(message);

            WriteLog(string.Format("{0} > Sending message: {1}", DateTime.Now, messageString));
        }
Example #2
0
        private void OnTick(object sender, object e)
        {
            /*
             * double x, y, z;
             *
             * this.hat.GetAcceleration(out x, out y, out z);
             *
             * this.LightTextBox.Text = this.hat.GetLightLevel().ToString("P2");
             * this.TempTextBox.Text = this.hat.GetTemperature().ToString("N2");
             * this.AccelTextBox.Text = $"({x:N2}, {y:N2}, {z:N2})";
             * this.Button18TextBox.Text = this.hat.IsDIO18Pressed().ToString();
             * this.Button22TextBox.Text = this.hat.IsDIO22Pressed().ToString();
             * this.AnalogTextBox.Text = this.hat.ReadAnalog(GIS.FEZHAT.AnalogPin.Ain1).ToString("N2");
             *
             * if ((this.i++ % 5) == 0)
             * {
             *  this.LedsTextBox.Text = this.next.ToString();
             *
             *  this.hat.DIO24On = this.next;
             *  this.hat.D2.Color = this.next ? GIS.FEZHAT.Color.White : GIS.FEZHAT.Color.Black;
             *  this.hat.D3.Color = this.next ? GIS.FEZHAT.Color.White : GIS.FEZHAT.Color.Black;
             *
             *  this.hat.WriteDigital(GIS.FEZHAT.DigitalPin.DIO16, this.next);
             *  this.hat.WriteDigital(GIS.FEZHAT.DigitalPin.DIO26, this.next);
             *
             *  this.hat.SetPwmDutyCycle(GIS.FEZHAT.PwmPin.Pwm5, this.next ? 1.0 : 0.0);
             *  this.hat.SetPwmDutyCycle(GIS.FEZHAT.PwmPin.Pwm6, this.next ? 1.0 : 0.0);
             *  this.hat.SetPwmDutyCycle(GIS.FEZHAT.PwmPin.Pwm7, this.next ? 1.0 : 0.0);
             *  this.hat.SetPwmDutyCycle(GIS.FEZHAT.PwmPin.Pwm11, this.next ? 1.0 : 0.0);
             *  this.hat.SetPwmDutyCycle(GIS.FEZHAT.PwmPin.Pwm12, this.next ? 1.0 : 0.0);
             *
             *  this.next = !this.next;
             * }
             *
             * if (this.hat.IsDIO18Pressed())
             * {
             *  this.hat.S1.Position += 5.0;
             *  this.hat.S2.Position += 5.0;
             *
             *  if (this.hat.S1.Position >= 180.0)
             *  {
             *      this.hat.S1.Position = 0.0;
             *      this.hat.S2.Position = 0.0;
             *  }
             * }
             *
             * if (this.hat.IsDIO22Pressed())
             * {
             *  if (this.hat.MotorA.Speed == 0.0)
             *  {
             *      this.hat.MotorA.Speed = 0.5;
             *      this.hat.MotorB.Speed = -0.7;
             *  }
             * }
             * else
             * {
             *  if (this.hat.MotorA.Speed != 0.0)
             *  {
             *      this.hat.MotorA.Speed = 0.0;
             *      this.hat.MotorB.Speed = 0.0;
             *  }
             * }*/
            var item = new DataSensor()
            {
                Dev = "PiSensor", Utc = DateTime.Now.ToUniversalTime().ToString(), Celsius = hat.GetTemperature(), Light = hat.GetLightLevel()
            };

            SendDeviceToCloudMessagesAsync(item);
        }