Ejemplo n.º 1
0
        public void serverThread() //SERVER for ESP8266
        {
            int  temp  = 0;
            int  hum   = 0;
            char count = 't';
            //setting up server
            UdpClient  udpClient        = new UdpClient(8080);
            IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 8080);

            while (pom)
            {
                Byte[] receiveBytes = udpClient.Receive(ref RemoteIpEndPoint);
                string returnData   = Encoding.ASCII.GetString(receiveBytes);

                //reading and saving to database
                this.Invoke(new MethodInvoker(delegate()
                {
                    switch (count)
                    {
                    case 't':
                        temp  = Int32.Parse(returnData);
                        count = 'h';
                        break;

                    case 'h':
                        hum   = Int32.Parse(returnData);
                        count = 's';
                        break;

                    case 's':
                        SQLquerry.insertvalues(temp, hum);
                        dataGridView1.DataSource = SQLquerry.refreshview();
                        count = 't';
                        break;

                    default:
                        break;
                    }
                }));
            }
            udpClient.Close();
        }
Ejemplo n.º 2
0
 public Form1()
 {
     InitializeComponent();
     dataGridView1.DataSource = SQLquerry.refreshview();
 }