Jump to content

saschakp

Members
  • Gesamte Inhalte

    27
  • Benutzer seit

  • Letzter Besuch

Posts erstellt von saschakp

  1. Danke für eure antworten.

    Mit welcher Programmier sprache ist die anbindung an einer mySQL einfacher (ausser PHP)?

    Es soll eine anwendung sein die auf meinem Windows Server läuft,

    es sollen ja noch weitere Sensoren angeschlossen werden.

    In PHP habe ich das ganze hinbekommen, aber C# ist komplett neu für mich.

    Werde mal mich in anderen Sprachen einlesen ob da die anbindung besser klappt.

     

    mfg

    Sascha

     

     

  2. Hallo zusammen,

    ich habe heute ein bisschen mit C# rumgespielt,

    wollte ein kleines Programm schreiben was daten

    von einem Temperatur Sensor in die Datenbank schreibt.

    Bis jetzt ist es mir nicht gelungen.

    Werte werden schonmal in der Konsole ausgegeben und auf

    ein Text wird auf dem LCD display angezeigt.

    Vieleicht könnt Ihr mir Helfen.

     

    mfg

    Sascha

     

    using Tinkerforge;
    using MySql.Data.MySqlClient;
    
    
    class Example
    {
        private static string HOST = "localhost";
        private static int PORT = 4223;
        private static string UID = "9p19cLeYP8w"; // Change to your UID
        private static string UID2 = "b4A"; // Change to your UID
        private static string UID4 = "9LY"; // Change to your UID
    
      
    
        static void Main()
        {
            IPConnection ipcon = new IPConnection(HOST, PORT); // Create connection to brickd
            BrickMaster master = new BrickMaster(UID); // Create device object
            BrickletTemperature temp = new BrickletTemperature(UID2); // Create device object
            BrickletLCD20x4 lcd = new BrickletLCD20x4(UID4); // Create device object
    
            ipcon.AddDevice(lcd); // Add device to IP connection
            ipcon.AddDevice(master); // Add device to IP connection
            ipcon.AddDevice(temp); // Add device to IP connection
            // Don't use device before it is added to a connection
    
            
            
            for (int i = 1; i <= 5; i++)
               
            {
            // Get voltage and current from stack (in mV/mA)
            ushort voltage = master.GetStackVoltage();
            ushort current = master.GetStackCurrent();
            short temperature = temp.GetTemperature();
    
            lcd.BacklightOn();
            lcd.ClearDisplay();
            lcd.WriteLine(0, 0, "Test");
            System.Console.WriteLine("## TinkerForge (c) SK");
            System.Console.WriteLine("## Projekt Temperatur + MySQL Datenbank");
            System.Console.WriteLine("Stack Voltage: " + voltage / 1000.0 + " V");
            System.Console.WriteLine("Stack Current: " + current / 1000.0 + " A");
            System.Console.WriteLine("Temperature: " + temperature / 100.0 + " °C");
            System.Threading.Thread.Sleep(500);
            System.Console.Clear();
    
        public void InsertRow(string myConnectionString) 
       {
        // If the connection string is empty, use a default.
        if(myConnectionString == "") 
        {
            myConnectionString = "DATABASE=wetter;Data SERVER=localhost;
                                  UID=xxxxxxx; PASSWORD=xxxxxxxxxxxxxxx";
        }
    
        MySqlConnection myConnection = new MySqlConnection(myConnectionString);
        string myInsertQuery = "INSERT INTO wetter (sensor1, sensor2) 
                                Values(testwert1, testwert2)";
        MySqlCommand myCommand = new MySqlCommand(myInsertQuery);
        myCommand.Connection = myConnection;
        myConnection.Open();
        myCommand.ExecuteNonQuery();
        myCommand.Connection.Close();
       }
        }
            
            System.Console.WriteLine("Press key to exit");
            System.Console.ReadKey();
            ipcon.Destroy();
                
        }
    
    
    }
    

×
×
  • Neu erstellen...