Exemplo n.º 1
0
        private static void Main()
        {
            double setPoint = 130;

            IPConnection ipcon = new IPConnection(); // Create IP connection

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

            var light = new BrickletAmbientLight(UidAmbientLight, ipcon);

            ledStrip = new BrickletLEDStrip(UidLedStrip, ipcon);
            var pid = new PidCompute(0.3, 0.00001, 0);

            ledStrip.SetChannelMapping(6);

            var ledHandler = new LedHanlder(ledStrip);

            while (true)
            {
                var lux = light.GetIlluminance();
                Console.Out.WriteLine($"Lux: {lux}");
                var res = pid.Compute(setPoint, lux);
                Console.Out.WriteLine($"PID Result: {res}");
                ledHandler.SetLedStrip(res);
                Thread.Sleep(20);
            }

            Console.WriteLine("Press enter to exit");
            Console.ReadLine();
            ipcon.Disconnect();
        }
Exemplo n.º 2
0
 static void IlluminanceCB(BrickletAmbientLight sender, int illuminance)
 {
     if (brickletLCD != null)
     {
         string text = string.Format("Illuminanc {0,6:###.00} lx", illuminance / 10.0);
         brickletLCD.WriteLine(0, 0, text);
         System.Console.WriteLine("Write to line 0: " + text);
     }
 }
Exemplo 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 BrickletAmbientLight(UID, connection);
        }
Exemplo n.º 4
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)
 {
     AmbientLightConfig.Instance.ShowConfig();
     if (Bricklet == null)
     {
         Bricklet = new BrickletAmbientLight(UID, connection);
     }
     return(true);
 }
Exemplo n.º 5
0
        private static void Main()
        {
            double setPoint = 400;

            IPConnection ipcon = new IPConnection(); // Create IP connection

            ipcon.Connect(HOST, PORT);               // Connect to brickd
            var display    = new BrickletLCD20x4(UidLcdDisplay, ipcon);
            var displayPID = new BrickletLCD20x4(UidLcdDisplayPID, ipcon);
            var light      = new BrickletAmbientLight(UidAmbientLight, ipcon);

            ledStrip = new BrickletLEDStrip(UidLedStrip, ipcon);
            var pid = new PidCompute(0.3, 0.0001, 0.0000003);

            ledStrip.SetChannelMapping(6);
            var rotaryPotiP = new BrickletRotaryPoti(UiWheelP, ipcon);
            var rotaryPotiI = new BrickletRotaryPoti(UiWheelI, ipcon);
            var rotaryPotiD = new BrickletRotaryPoti(UiWheelD, ipcon);
            var linerPoti   = new BrickletLinearPoti("bxu", ipcon);

            display.BacklightOn();
            displayPID.BacklightOn();

            var    ledHandler = new LedHanlder(ledStrip);
            double P          = 0.15;
            double I          = 0.15;
            double D          = 0.15;

            while (true)
            {
                P        = rotaryPotiP.GetAnalogValue() / 100000.0;
                I        = rotaryPotiI.GetAnalogValue() / 1000000.0;
                D        = rotaryPotiD.GetAnalogValue() / 1000000.0;
                setPoint = linerPoti.GetAnalogValue() / 10;

                pid = new PidCompute(P, I, D);
                Console.WriteLine("Goal: " + setPoint);
                var lux = light.GetIlluminance();
                Console.Out.WriteLine($"Lux: {lux}");
                var res = 0.1 * pid.Compute(setPoint, lux);
                Console.Out.WriteLine($"PID Result: {res}");
                ledHandler.SetLedStrip(res);
                display.ClearDisplay();
                displayPID.ClearDisplay();
                display.WriteLine(0, 0, $"Setpoint: {setPoint}");
                display.WriteLine(1, 0, $"Lux: {lux}");
                display.WriteLine(2, 0, $"PID Result: {res}");
                displayPID.WriteLine(0, 0, $"P: {P}");
                displayPID.WriteLine(1, 0, $"I: {I}");
                displayPID.WriteLine(2, 0, $"D: {D}");
                Thread.Sleep(10);
            }

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

    #endregion Fields

    #region Methods

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

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

        // Get current illuminance (unit is Lux/10)
        int illuminance = al.GetIlluminance();
        Console.WriteLine("Illuminance: " + illuminance/10.0 + " Lux");

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

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

        // Register illuminance callback to function IlluminanceCB
        al.Illuminance += IlluminanceCB;

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

        Console.WriteLine("Press enter to exit");
        Console.ReadLine();
        ipcon.Disconnect();
    }
Exemplo n.º 8
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;
		}
    static void Main()
    {
        IPConnection ipcon = new IPConnection(); // Create IP connection
        BrickletAmbientLight al = new BrickletAmbientLight(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)
        al.SetDebouncePeriod(10000);

        // Register illuminance reached callback to function IlluminanceReachedCB
        al.IlluminanceReached += IlluminanceReachedCB;

        // Configure threshold for illuminance "greater than 200 Lux" (unit is Lux/10)
        al.SetIlluminanceCallbackThreshold('>', 200*10, 0);

        Console.WriteLine("Press enter to exit");
        Console.ReadLine();
        ipcon.Disconnect();
    }
Exemplo 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;
                }
            }
        }
    }
Exemplo n.º 11
0
 static void IlluminanceCB(BrickletAmbientLight sender, int illuminance)
 {
     if(brickletLCD != null)
     {
         string text = string.Format("Illuminanc {0,6:###.00} lx", illuminance/10.0);
         brickletLCD.WriteLine(0, 0, text);
         System.Console.WriteLine("Write to line 0: " + text);
     }
 }
Exemplo 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;
             }
         }
     }
 }
Exemplo n.º 13
0
 static void IlluminanceCB(BrickletAmbientLight sender, int illuminance)
 {
     latestIlluminance = illuminance / 10.0;
 }
 static void IlluminanceCB(BrickletAmbientLight sender, int illuminance)
 {
     latestIlluminance = illuminance/10.0;
 }
Exemplo n.º 15
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();
        }
    private static string UID = "XYZ"; // Change XYZ to the UID of your Ambient Light Bricklet

    #endregion Fields

    #region Methods

    // Callback function for illuminance reached callback (parameter has unit Lux/10)
    static void IlluminanceReachedCB(BrickletAmbientLight sender, int illuminance)
    {
        Console.WriteLine("Illuminance: " + illuminance/10.0 + " Lux");
        Console.WriteLine("Too bright, close the curtains!");
    }
    private static string UID = "XYZ"; // Change XYZ to the UID of your Ambient Light Bricklet

    #endregion Fields

    #region Methods

    // Callback function for illuminance callback (parameter has unit Lux/10)
    static void IlluminanceCB(BrickletAmbientLight sender, int illuminance)
    {
        Console.WriteLine("Illuminance: " + illuminance/10.0 + " Lux");
    }