Beispiel #1
0
    // Callback handles device connections and configures possibly lost
    // configuration of lcd and temperature callbacks, backlight etc.
    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)
        {
            // Enumeration is for LCD Bricklet
            if(deviceIdentifier == BrickletLCD20x4.DEVICE_IDENTIFIER)
            {
                // Create lcd device object
                lcd = new BrickletLCD20x4(UID, ipcon);
                lcd.ButtonPressed += ButtonPressedCB;

                lcd.ClearDisplay();
                lcd.BacklightOn();
            }
            // Enumeration is for Temperature Bricklet
            if(deviceIdentifier == BrickletTemperature.DEVICE_IDENTIFIER)
            {
                // Create temperature device object
                temp = new BrickletTemperature(UID, ipcon);
                temp.Temperature += TemperatureCB;

                temp.SetTemperatureCallbackPeriod(50);
            }
        }
    }
Beispiel #2
0
    // Callback handles device connections and configures possibly lost
    // configuration of lcd and temperature callbacks, backlight etc.
    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)
        {
            // Enumeration is for LCD Bricklet
            if (deviceIdentifier == BrickletLCD20x4.DEVICE_IDENTIFIER)
            {
                // Create lcd device object
                lcd = new BrickletLCD20x4(UID, ipcon);
                lcd.ButtonPressed += ButtonPressedCB;

                lcd.ClearDisplay();
                lcd.BacklightOn();
            }
            // Enumeration is for Temperature Bricklet
            if (deviceIdentifier == BrickletTemperature.DEVICE_IDENTIFIER)
            {
                // Create temperature device object
                temp              = new BrickletTemperature(UID, ipcon);
                temp.Temperature += TemperatureCB;

                temp.SetTemperatureCallbackPeriod(50);
            }
        }
    }
Beispiel #3
0
        // Callback function for bricklet callback
        private static async void BrickletCb(BrickletTemperature sender, short rawValue)
        {
            var value = CalculateValue(rawValue);

            _tinfluxWeatherStation.LastMeasuredTemperature = value;
            await _tinfluxWeatherStation.WriteToInfluxDb(SensorTyp, SensorUnit, SensorUnitName, value);
        }
Beispiel #4
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;
        }
Beispiel #5
0
 // Callback updates temperature displayed on lcd
 static void TemperatureCB(BrickletTemperature sender, short temperature)
 {
     if (lcd != null)
     {
         lcd.ClearDisplay();
         string s = "Temperature: " + temperature / 100.0 + (char)0xdf + "C";
         lcd.WriteLine(0, 0, s);
     }
 }
Beispiel #6
0
        public TemperatureSensor(IPConnection ipConnection, string uid, int sensorCallbackPeriod, Station station)
        {
            _tinfluxWeatherStation = station;
            var bricklet = new BrickletTemperature(uid, ipConnection);

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

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

    #endregion Fields

    #region Methods

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

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

        // Get current temperature (unit is °C/100)
        short temperature = t.GetTemperature();
        Console.WriteLine("Temperature: " + temperature/100.0 + " °C");

        Console.WriteLine("Press enter to exit");
        Console.ReadLine();
        ipcon.Disconnect();
    }
Beispiel #8
0
    private static string UID  = "XYZ";    // Change XYZ to the UID of your Temperature Bricklet

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

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

        // Get current temperature (unit is °C/100)
        short temperature = t.GetTemperature();

        Console.WriteLine("Temperature: " + temperature / 100.0 + " °C");

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

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

        // Register temperature callback to function TemperatureCB
        t.TemperatureCallback += TemperatureCB;

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

        Console.WriteLine("Press enter to exit");
        Console.ReadLine();
        ipcon.Disconnect();
    }
    private static string UID = "XYZ"; // Change XYZ to the UID of your Temperature Bricklet

    #endregion Fields

    #region Methods

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

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

        // Register temperature callback to function TemperatureCB
        t.Temperature += TemperatureCB;

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

        Console.WriteLine("Press enter to exit");
        Console.ReadLine();
        ipcon.Disconnect();
    }
Beispiel #11
0
		public static bool init(ref IPConnection brick_connection) {
			
			// get UIDs of bricks and bricklets
			AppSettingsReader config = new AppSettingsReader();
			
			host = (string)config.GetValue("host", typeof(string));
			port = (int)config.GetValue("port", typeof(int));
			server_port = (int)config.GetValue("server_port", typeof(int));
			string master_brick_uid = (string)config.GetValue("master_brick_uid", typeof(string));
			string ambient_bricklet_uid = (string)config.GetValue("ambient_light_bricklet_uid", typeof(string));
			string temperature_bricklet_uid = (string)config.GetValue("temperature_bricklet_uid", typeof(string));
			string lcd_20x4_bricklet_uid = (string)config.GetValue("lcd_20x4_bricklet_uid", typeof(string));
			
#if DEBUG
			Console.WriteLine("Master Brick Host:Port ...: {0}:{1}", host, port);
			Console.WriteLine("Serverport (udp msgs).....: :{0}", server_port);
			Console.WriteLine("Master Brick UID .........: {0}", master_brick_uid);
			Console.WriteLine("Ambient Bricklet UID .....: {0}", ambient_bricklet_uid);
			Console.WriteLine("Temperature Bricklet UID .: {0}", temperature_bricklet_uid);
			Console.WriteLine("LCD 20x4 Bricklet UID ....: {0}", lcd_20x4_bricklet_uid);
#endif
			
			// setup connection to master und bricklets
			try {
				brick_connection = new IPConnection(host, port);
				
				ambient_light = new BrickletAmbientLight(ambient_bricklet_uid);
				temperature = new BrickletTemperature(temperature_bricklet_uid);
				lcd = new BrickletLCD20x4(lcd_20x4_bricklet_uid);
				displayHelper = new LCDisplayHelper(lcd);
			
				brick_connection.AddDevice(ambient_light);
				brick_connection.AddDevice(temperature);
				brick_connection.AddDevice(lcd);
			} catch (Tinkerforge.TimeoutException te) {
				Console.WriteLine(te.Message);
				return false;
			}
			
			return true;
		}
Beispiel #12
0
    static void Main()
    {
        IPConnection        ipcon = new IPConnection();                  // Create IP connection
        BrickletTemperature t     = new BrickletTemperature(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)
        t.SetDebouncePeriod(10000);

        // Register temperature reached callback to function TemperatureReachedCB
        t.TemperatureReachedCallback += TemperatureReachedCB;

        // Configure threshold for temperature "greater than 30 °C" (unit is °C/100)
        t.SetTemperatureCallbackThreshold('>', 30 * 100, 0);

        Console.WriteLine("Press enter to exit");
        Console.ReadLine();
        ipcon.Disconnect();
    }
    private static string UID = "XYZ"; // Change XYZ to the UID of your Temperature Bricklet

    #endregion Fields

    #region Methods

    static void Main()
    {
        IPConnection ipcon = new IPConnection(); // Create IP connection
        BrickletTemperature t = new BrickletTemperature(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)
        t.SetDebouncePeriod(10000);

        // Register temperature reached callback to function TemperatureReachedCB
        t.TemperatureReached += TemperatureReachedCB;

        // Configure threshold for temperature "greater than 30 °C" (unit is °C/100)
        t.SetTemperatureCallbackThreshold('>', 30*100, 0);

        Console.WriteLine("Press enter to exit");
        Console.ReadLine();
        ipcon.Disconnect();
    }
Beispiel #14
0
    private static string UID  = "XYZ";    // Change XYZ to the UID of your Temperature Bricklet

    // Callback function for temperature reached callback (parameter has unit °C/100)
    static void TemperatureReachedCB(BrickletTemperature sender, short temperature)
    {
        Console.WriteLine("Temperature: " + temperature / 100.0 + " °C");
        Console.WriteLine("It is too hot, we need air conditioning!");
    }
 // Callback function for temperature callback (parameter has unit °C/100)
 static void TemperatureCB(BrickletTemperature sender, short temperature)
 {
     Console.WriteLine("Temperature: " + temperature/100.0 + " °C");
 }
Beispiel #16
0
        public void doSmth()
        {
            //Create IP Connection
            IPConnection ipcon = new IPConnection();

            // Connect to brickd
            ipcon.Connect(HOST, PORT);

            var BrickletLCD          = new BrickletLCD20x4(SECRET_LCD, ipcon);
            var BrickletAmbientLight = new BrickletAmbientLight(SECRET_AMBIENTLIGHT, ipcon);
            var BrickletCO2          = new BrickletCO2(SECRET_CO2, ipcon);
            var BrickletBarometer    = new BrickletBarometer(SECRET_BAROMETER, ipcon);
            var BrickletTemperature  = new BrickletTemperature(SECRET_TEMPERATURE, ipcon);

            int i = 100;

            var data = new Bricklet_Model();
            var tb   = new Thingsboard();


            while (true)
            {
                var co2value       = BrickletCO2.GetCO2Concentration();                          // unit ppm - parts per million
                var lightvalue     = BrickletAmbientLight.GetAnalogValue();                      // lcd
                var barometervalue = String.Format("{0:n}", BrickletBarometer.GetAirPressure()); // in mbar
                // var barometervalue = bV / 1000;

                double tempvalue = (Math.Round((double)BrickletTemperature.GetTemperature() * 100) / 10000) - 5; // in °c


                tb.LightValue  = lightvalue;
                tb.Barometer   = Convert.ToDouble(barometervalue) / 1000;
                tb.Temperature = tempvalue;
                tb.CO2         = co2value;
                //tb.LightValue = 100;
                //tb.Barometer = 99;
                //tb.Temperature = 98;
                //tb.CO2 = 97;
                c.PublishMessage(tb);

                /*
                 * var temperatur = new Temperatur();
                 * _context.Temperatur.Add(temperatur);
                 * _context.Entry(temperatur).CurrentValues.SetValues(new Temperatur { Datum = new DateTime(), Einheit = "Grad", Wert = CO2Value, idTemperatur = i++ });
                 * _context.SaveChanges();
                 */
                BrickletLCD.SetConfig(true, true);
                BrickletLCD.BacklightOn();
                Console.WriteLine(
                    " LightValue: " + lightvalue + " BarometerValue " +
                    barometervalue + "mbar " + " TempValue " + tempvalue.ToString() + "°C " + " CO2-Value: " + co2value);
                BrickletLCD.WriteLine(0, 0, "CO2 Value: " + co2value.ToString());
                BrickletLCD.WriteLine(1, 0, "LightValue: " + lightvalue.ToString());
                BrickletLCD.WriteLine(2, 0, "BarometerValue:" + barometervalue.ToString());
                BrickletLCD.WriteLine(3, 0, "Temperature " + tempvalue.ToString());

                Thread.Sleep(500);
            }

            ipcon.Disconnect();
        }
Beispiel #17
0
 // Callback updates temperature displayed on lcd
 static void TemperatureCB(BrickletTemperature sender, short temperature)
 {
     if(lcd != null)
     {
         lcd.ClearDisplay();
         string s = "Temperature: " + temperature/100.0 + (char)0xdf + "C";
         lcd.WriteLine(0, 0, s);
     }
 }
    private static string UID  = "XYZ";    // Change XYZ to the UID of your Temperature Bricklet

    // Callback function for temperature callback (parameter has unit °C/100)
    static void TemperatureCB(BrickletTemperature sender, short temperature)
    {
        Console.WriteLine("Temperature: " + temperature / 100.0 + " °C");
    }
 // Callback function for temperature reached callback (parameter has unit °C/100)
 static void TemperatureReachedCB(BrickletTemperature sender, short temperature)
 {
     Console.WriteLine("Temperature: " + temperature/100.0 + " °C");
     Console.WriteLine("It is too hot, we need air conditioning!");
 }