private void HumidityAndTemperatureTimerProc(object state)
        {
            _led.Set(0, 128, 0);

            double humidity    = sensor.Humidity();
            double temperature = sensor.Temperature();

            Debug.Print(DateTime.UtcNow.ToString("hh:mm:ss") + " H:" + humidity.ToString("F1") + " T:" + temperature.ToString("F1"));

            rfm9XDevice.Send(fieldGatewayAddress, Encoding.UTF8.GetBytes("t " + temperature.ToString("F1") + ",H " + humidity.ToString("F0")));
        }
        private void HumidityAndTemperatureTimerProc(object state)
        {
            double humidity    = sensor.Humidity();
            double temperature = sensor.Temperature();

            Debug.WriteLine($"{DateTime.UtcNow:hh:mm:ss} TX-H:{humidity:F0}% T:{temperature:F1}°");

            rfm9XDevice.Send(fieldGatewayAddress, Encoding.UTF8.GetBytes($"T {temperature:F1},H {humidity:F0}"));

            led.Write(GpioPinValue.High);
        }
Esempio n. 3
0
        public static void Main()
        {
            try
            {
                Debug.WriteLine("devMobile.SiliconLabsSI7005TestHarness starting");

                // STM32F091RC: PA5 is LED_GREEN
                // nanoff --target ST_NUCLEO64_F091RC --update
                //GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('A', 5));

                // nanoff --target NETDUINO3_WIFI --update
                GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('A', 10));

                // nanoff --target ST_STM32F769I_DISCOVERY --update
                //GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('J', 5));

                led.SetDriveMode(GpioPinDriveMode.Output);

                Debug.WriteLine(I2cDevice.GetDeviceSelector());

                SiliconLabsSI7005 sensor = new SiliconLabsSI7005("I2C1");
                Debug.WriteLine(" while starting");

                while (true)
                {
                    double humidity    = sensor.Humidity();
                    double temperature = sensor.Temperature();

                    Debug.WriteLine($"{DateTime.UtcNow:hh:mm:ss} H:{humidity:f0} % T:{temperature:f1}°");

                    led.Toggle();

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

            Debug.WriteLine("Terminated");
            Thread.Sleep(Timeout.Infinite);
        }
        private void HumidityAndTemperatureTimerProc(object state)
        {
            led.Write(true);

            double humidity    = sensor.Humidity();
            double temperature = sensor.Temperature();

            Debug.Print("H:" + humidity.ToString("F1") + " T:" + temperature.ToString("F1"));
            string values = "T " + temperature.ToString("F1") + ",H " + humidity.ToString("F0");

            // Stuff the 2 byte header ( payload type & deviceIdentifierLength ) + deviceIdentifier into payload
            byte[] payload = new byte[1 + deviceIdentifier.Length + values.Length];
            payload[0] = (byte)((1 << 4) | deviceIdentifier.Length);
            Array.Copy(deviceIdentifier, 0, payload, 1, deviceIdentifier.Length);

            Encoding.UTF8.GetBytes(values, 0, values.Length, payload, deviceIdentifier.Length + 1);

            radio.SendTo(nRF24BaseStationAddress, payload);
        }