Ejemplo n.º 1
0
        // Callback function for bricklet callback
        private static async void BrickletCb(BrickletHumidity sender, int rawValue)
        {
            var value = CalculateValue(rawValue);

            _tinfluxWeatherStation.LastMeasuredHumidity = value;
            await _tinfluxWeatherStation.WriteToInfluxDb(SensorTyp, SensorUnit, SensorUnitName, value);
        }
Ejemplo n.º 2
0
        public Component()
        {
            client = new HttpClient();
            // Create connection object
            _ipConnection = new IPConnection();

            // Create device objects
            _dualButtonBricklet  = new BrickletDualButton(DualButtonUID, _ipConnection);
            _lcdBricklet         = new BrickletLCD20x4(DisplayUID, _ipConnection);
            _temperatureBricklet = new BrickletTemperature(TemperatureUID, _ipConnection);
            _humidityBricklet    = new BrickletHumidity(HumidityUID, _ipConnection);
            _linearPoti          = new BrickletLinearPoti(LinearPotiUID, _ipConnection);
            _rgbButton           = new BrickletRGBLEDButton(RGBButtonUID, _ipConnection);
            _rotaryPoti          = new BrickletRotaryPoti(RotaryPotiUID, _ipConnection);
            _segmentDisplay      = new BrickletSegmentDisplay4x7(SegmentUID, _ipConnection);
            _motionDetector      = new BrickletMotionDetectorV2(motionDetectorUID, _ipConnection);
            _multiTouch          = new BrickletMultiTouch(multiTouchUID, _ipConnection);

            //register listeners
            _dualButtonBricklet.StateChangedCallback += DualButtonStateChanged;

            //register callback
            _linearPoti.PositionCallback                += PositionCb;
            _rotaryPoti.PositionCallback                += PositionRCB;
            _motionDetector.MotionDetectedCallback      += MotionDetectedCB;
            _motionDetector.DetectionCycleEndedCallback += DetectionCycleEndedCB;
            _multiTouch.TouchStateCallback              += TouchStateCB;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initialize internal TF bricklet
        /// </summary>
        /// <param name="connection">Connection to master brick</param>
        /// <param name="UID">Sensor ID</param>
        public override void Init(IPConnection connection, string UID)
        {
            if (_Bricklet != null)
            {
                return;
            }

            _Bricklet = new BrickletHumidity(UID, connection);
        }
Ejemplo n.º 4
0
 static void HumidityCB(BrickletHumidity sender, int humidity)
 {
     if (brickletLCD != null)
     {
         string text = string.Format("Humidity   {0,6:###.00} %", humidity / 10.0);
         brickletLCD.WriteLine(1, 0, text);
         System.Console.WriteLine("Write to line 1: " + text);
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Initialize internal TF bricklet
 /// </summary>
 /// <param name="connection">Connection to master brick</param>
 /// <param name="UID">Sensor ID</param>
 /// <returns>true on successful init</returns>
 public override bool Init(IPConnection connection, string UID)
 {
     HumidityConfig.Instance.ShowConfig();
     if (Bricklet == null)
     {
         Bricklet = new BrickletHumidity(UID, connection);
     }
     return(true);
 }
Ejemplo n.º 6
0
        public HumiditySensor(IPConnection ipConnection, string uid, int sensorCallbackPeriod, Station station)
        {
            _tinfluxWeatherStation = station;
            var bricklet = new BrickletHumidity(uid, ipConnection);

            // Register callback to function BrickletCb
            bricklet.HumidityCallback += BrickletCb;

            // Note: The callback is only called every "sensorCallbackPeriod"
            // if the value has changed since the last call!
            bricklet.SetHumidityCallbackPeriod(sensorCallbackPeriod);
        }
Ejemplo n.º 7
0
    private static string UID = "XYZ"; // Change XYZ to the UID of your Humidity Bricklet

    #endregion Fields

    #region Methods

    static void Main()
    {
        IPConnection ipcon = new IPConnection(); // Create IP connection
        BrickletHumidity h = new BrickletHumidity(UID, ipcon); // Create device object

        ipcon.Connect(HOST, PORT); // Connect to brickd
        // Don't use device before ipcon is connected

        // Get current humidity (unit is %RH/10)
        int humidity = h.GetHumidity();
        Console.WriteLine("Humidity: " + humidity/10.0 + " %RH");

        Console.WriteLine("Press enter to exit");
        Console.ReadLine();
        ipcon.Disconnect();
    }
    static void Main()
    {
        IPConnection ipcon = new IPConnection(); // Create IP connection
        BrickletHumidity h = new BrickletHumidity(UID, ipcon); // Create device object

        ipcon.Connect(HOST, PORT); // Connect to brickd
        // Don't use device before ipcon is connected

        // Register humidity callback to function HumidityCB
        h.Humidity += HumidityCB;

        // Set period for humidity callback to 1s (1000ms)
        // Note: The humidity callback is only called every second
        //       if the humidity has changed since the last call!
        h.SetHumidityCallbackPeriod(1000);

        Console.WriteLine("Press enter to exit");
        Console.ReadLine();
        ipcon.Disconnect();
    }
    static void Main()
    {
        IPConnection ipcon = new IPConnection(); // Create IP connection
        BrickletHumidity h = new BrickletHumidity(UID, ipcon); // Create device object

        ipcon.Connect(HOST, PORT); // Connect to brickd
        // Don't use device before ipcon is connected

        // Get threshold callbacks with a debounce time of 10 seconds (10000ms)
        h.SetDebouncePeriod(10000);

        // Register humidity reached callback to function HumidityReachedCB
        h.HumidityReached += HumidityReachedCB;

        // Configure threshold for humidity "outside of 30 to 60 %RH" (unit is %RH/10)
        h.SetHumidityCallbackThreshold('o', 30*10, 60*10);

        Console.WriteLine("Press enter to exit");
        Console.ReadLine();
        ipcon.Disconnect();
    }
Ejemplo n.º 10
0
    static void EnumerateCB(IPConnection sender, string UID, string connectedUID, char position,
	                        short[] hardwareVersion, short[] firmwareVersion,
	                        int deviceIdentifier, short enumerationType)
    {
        if(enumerationType == IPConnection.ENUMERATION_TYPE_CONNECTED ||
           enumerationType == IPConnection.ENUMERATION_TYPE_AVAILABLE)
        {
            if(deviceIdentifier == BrickletLCD20x4.DEVICE_IDENTIFIER)
            {
                try
                {
                    brickletLCD = new BrickletLCD20x4(UID, ipcon);
                    brickletLCD.ClearDisplay();
                    brickletLCD.BacklightOn();
                    System.Console.WriteLine("LCD 20x4 initialized");
                }
                catch(TinkerforgeException e)
                {
                    System.Console.WriteLine("LCD 20x4 init failed: " + e.Message);
                    brickletLCD = null;
                }
            }
            else if(deviceIdentifier == BrickletAmbientLight.DEVICE_IDENTIFIER)
            {
                try
                {
                    brickletAmbientLight = new BrickletAmbientLight(UID, ipcon);
                    brickletAmbientLight.SetIlluminanceCallbackPeriod(1000);
                    brickletAmbientLight.Illuminance += IlluminanceCB;
                    System.Console.WriteLine("Ambient Light initialized");
                }
                catch(TinkerforgeException e)
                {
                    System.Console.WriteLine("Ambient Light init failed: " + e.Message);
                    brickletAmbientLight = null;
                }
            }
            else if(deviceIdentifier == BrickletAmbientLightV2.DEVICE_IDENTIFIER)
            {
                try
                {
                    brickletAmbientLightV2 = new BrickletAmbientLightV2(UID, ipcon);
                    brickletAmbientLightV2.SetConfiguration(BrickletAmbientLightV2.ILLUMINANCE_RANGE_64000LUX,
                                                            BrickletAmbientLightV2.INTEGRATION_TIME_200MS);
                    brickletAmbientLightV2.SetIlluminanceCallbackPeriod(1000);
                    brickletAmbientLightV2.Illuminance += IlluminanceV2CB;
                    System.Console.WriteLine("Ambient Light 2.0 initialized");
                }
                catch(TinkerforgeException e)
                {
                    System.Console.WriteLine("Ambient Light 2.0 init failed: " + e.Message);
                    brickletAmbientLightV2 = null;
                }
            }
            else if(deviceIdentifier == BrickletHumidity.DEVICE_IDENTIFIER)
            {
                try
                {
                    brickletHumidity = new BrickletHumidity(UID, ipcon);
                    brickletHumidity.SetHumidityCallbackPeriod(1000);
                    brickletHumidity.Humidity += HumidityCB;
                    System.Console.WriteLine("Humidity initialized");
                }
                catch(TinkerforgeException e)
                {
                    System.Console.WriteLine("Humidity init failed: " + e.Message);
                    brickletHumidity = null;
                }
            }
            else if(deviceIdentifier == BrickletBarometer.DEVICE_IDENTIFIER)
            {
                try
                {
                    brickletBarometer = new BrickletBarometer(UID, ipcon);
                    brickletBarometer.SetAirPressureCallbackPeriod(1000);
                    brickletBarometer.AirPressure += AirPressureCB;
                    System.Console.WriteLine("Barometer initialized");
                }
                catch(TinkerforgeException e)
                {
                    System.Console.WriteLine("Barometer init failed: " + e.Message);
                    brickletBarometer = null;
                }
            }
        }
    }
Ejemplo n.º 11
0
 static void HumidityCB(BrickletHumidity sender, int humidity)
 {
     if(brickletLCD != null)
     {
         string text = string.Format("Humidity   {0,6:###.00} %", humidity/10.0);
         brickletLCD.WriteLine(1, 0, text);
         System.Console.WriteLine("Write to line 1: " + text);
     }
 }
Ejemplo n.º 12
0
 static void EnumerateCB(IPConnection sender, string UID, string connectedUID, char position,
                         short[] hardwareVersion, short[] firmwareVersion,
                         int deviceIdentifier, short enumerationType)
 {
     if (enumerationType == IPConnection.ENUMERATION_TYPE_CONNECTED ||
         enumerationType == IPConnection.ENUMERATION_TYPE_AVAILABLE)
     {
         if (deviceIdentifier == BrickletLCD20x4.DEVICE_IDENTIFIER)
         {
             try
             {
                 brickletLCD = new BrickletLCD20x4(UID, ipcon);
                 brickletLCD.ClearDisplay();
                 brickletLCD.BacklightOn();
                 System.Console.WriteLine("LCD 20x4 initialized");
             }
             catch (TinkerforgeException e)
             {
                 System.Console.WriteLine("LCD 20x4 init failed: " + e.Message);
                 brickletLCD = null;
             }
         }
         else if (deviceIdentifier == BrickletAmbientLight.DEVICE_IDENTIFIER)
         {
             try
             {
                 brickletAmbientLight = new BrickletAmbientLight(UID, ipcon);
                 brickletAmbientLight.SetIlluminanceCallbackPeriod(1000);
                 brickletAmbientLight.Illuminance += IlluminanceCB;
                 System.Console.WriteLine("Ambient Light initialized");
             }
             catch (TinkerforgeException e)
             {
                 System.Console.WriteLine("Ambient Light init failed: " + e.Message);
                 brickletAmbientLight = null;
             }
         }
         else if (deviceIdentifier == BrickletAmbientLightV2.DEVICE_IDENTIFIER)
         {
             try
             {
                 brickletAmbientLightV2 = new BrickletAmbientLightV2(UID, ipcon);
                 brickletAmbientLightV2.SetConfiguration(BrickletAmbientLightV2.ILLUMINANCE_RANGE_64000LUX,
                                                         BrickletAmbientLightV2.INTEGRATION_TIME_200MS);
                 brickletAmbientLightV2.SetIlluminanceCallbackPeriod(1000);
                 brickletAmbientLightV2.Illuminance += IlluminanceV2CB;
                 System.Console.WriteLine("Ambient Light 2.0 initialized");
             }
             catch (TinkerforgeException e)
             {
                 System.Console.WriteLine("Ambient Light 2.0 init failed: " + e.Message);
                 brickletAmbientLightV2 = null;
             }
         }
         else if (deviceIdentifier == BrickletHumidity.DEVICE_IDENTIFIER)
         {
             try
             {
                 brickletHumidity = new BrickletHumidity(UID, ipcon);
                 brickletHumidity.SetHumidityCallbackPeriod(1000);
                 brickletHumidity.Humidity += HumidityCB;
                 System.Console.WriteLine("Humidity initialized");
             }
             catch (TinkerforgeException e)
             {
                 System.Console.WriteLine("Humidity init failed: " + e.Message);
                 brickletHumidity = null;
             }
         }
         else if (deviceIdentifier == BrickletHumidityV2.DEVICE_IDENTIFIER)
         {
             try
             {
                 brickletHumidityV2 = new BrickletHumidityV2(UID, ipcon);
                 brickletHumidityV2.SetHumidityCallbackConfiguration(1000, true, 'x', 0, 0);
                 brickletHumidityV2.HumidityCallback += HumidityV2CB;
                 System.Console.WriteLine("Humidity 2.0 initialized");
             }
             catch (TinkerforgeException e)
             {
                 System.Console.WriteLine("Humidity 2.0 init failed: " + e.Message);
                 brickletHumidityV2 = null;
             }
         }
         else if (deviceIdentifier == BrickletBarometer.DEVICE_IDENTIFIER)
         {
             try
             {
                 brickletBarometer = new BrickletBarometer(UID, ipcon);
                 brickletBarometer.SetAirPressureCallbackPeriod(1000);
                 brickletBarometer.AirPressure += AirPressureCB;
                 System.Console.WriteLine("Barometer initialized");
             }
             catch (TinkerforgeException e)
             {
                 System.Console.WriteLine("Barometer init failed: " + e.Message);
                 brickletBarometer = null;
             }
         }
     }
 }
Ejemplo n.º 13
0
 static void HumidityCB(BrickletHumidity sender, int humidity)
 {
     latestHumidity = humidity / 10.0;
 }
 static void HumidityCB(BrickletHumidity sender, int humidity)
 {
     latestHumidity = humidity/10.0;
 }
    private static string UID = "XYZ"; // Change XYZ to the UID of your Humidity Bricklet

    #endregion Fields

    #region Methods

    // Callback function for humidity reached callback (parameter has unit %RH/10)
    static void HumidityReachedCB(BrickletHumidity sender, int humidity)
    {
        Console.WriteLine("Humidity: " + humidity/10.0 + " %RH");
        Console.WriteLine("Recommended humiditiy for human comfort is 30 to 60 %RH.");
    }
    private static string UID = "XYZ"; // Change XYZ to the UID of your Humidity Bricklet

    #endregion Fields

    #region Methods

    // Callback function for humidity callback (parameter has unit %RH/10)
    static void HumidityCB(BrickletHumidity sender, int humidity)
    {
        Console.WriteLine("Humidity: " + humidity/10.0 + " %RH");
    }