コード例 #1
0
        private void btnInitCom_Click(object sender, EventArgs e)
        {
            string COMPort = toolStripComboBoxCOMPort.Text;

            lblCOMPort.Text   = COMPort;
            lblSerialDat.Text = "";
            userSerialData    = "comInit#";
            comInit           = true;

            if (!ESP8266Serial.IsOpen)
            {
                if (string.IsNullOrEmpty(toolStripComboBoxCOMPort.Text))
                {
                    MessageBox.Show("Bitte COM-Port auswählen!");
                }
                else
                {
                    ESP8266Serial.PortName = Convert.ToString(toolStripComboBoxCOMPort.SelectedItem);
                    ESP8266Serial.BaudRate = 9600;
                    ESP8266Serial.Open();
                }
            }

            if (ESP8266Serial.IsOpen)
            {
                String init = "comInit#";
                ESP8266Serial.Write(init);
            }
        }
コード例 #2
0
 private void ZaehlerkopfKonfigurator_Load(object sender, EventArgs e)
 {
     foreach (string s in SerialPort.GetPortNames())
     {
         toolStripComboBoxCOMPort.Items.Add(s);
     }
     if (toolStripComboBoxCOMPort.Items.Count == 0)
     {
         MessageBox.Show("Bitte COM-Port wählen.");
     }
     else
     {
         toolStripComboBoxCOMPort.SelectedIndex = 0;
         if (!ESP8266Serial.IsOpen)
         {
             if (string.IsNullOrEmpty(toolStripComboBoxCOMPort.Text))
             {
                 MessageBox.Show("Bitte COM-Port auswählen!");
             }
             else
             {
                 ESP8266Serial.PortName = Convert.ToString(toolStripComboBoxCOMPort.SelectedItem);
                 ESP8266Serial.BaudRate = 9600;
                 ESP8266Serial.Open();
             }
         }
     }
     panelSerial.BringToFront();
     panelSerial.Show();
     panelThingSpeak.SendToBack();
     //panelThingSpeak.Hide();
     panelWLANconfig.SendToBack();
     //panelWLANconfig.Hide();
 }
コード例 #3
0
 private void btnWLANssid_Click(object sender, EventArgs e)
 {
     if (!ESP8266Serial.IsOpen)
     {
         if (string.IsNullOrEmpty(toolStripComboBoxCOMPort.Text))
         {
             MessageBox.Show("Bitte COM-Port auswählen!");
         }
         else
         {
             ESP8266Serial.PortName = Convert.ToString(toolStripComboBoxCOMPort.SelectedItem);
             ESP8266Serial.BaudRate = 9600;
             ESP8266Serial.Open();
         }
     }
     else //(ESP8266Serial.IsOpen)
     {
         userSerialData = "WLANSSID";
         if (cmbboxWLANSSID.Text == "")
         {
             MessageBox.Show("bitte Netzwerk aus Liste auswählen");
         }
         else
         {
             userSerialData += cmbboxWLANSSID.Text;
             ESP8266Serial.Write(userSerialData);
             tsSSIDSent = true;
         }
     }
 }
コード例 #4
0
 private void btnWLANscan_Click(object sender, EventArgs e)
 {
     lblSerialDat.Text = "Suche WLAN Netzwerk";
     if (!ESP8266Serial.IsOpen)
     {
         if (string.IsNullOrEmpty(toolStripComboBoxCOMPort.Text))
         {
             MessageBox.Show("Bitte COM-Port auswählen!");
         }
         else
         {
             ESP8266Serial.PortName = Convert.ToString(toolStripComboBoxCOMPort.SelectedItem);
             ESP8266Serial.BaudRate = 9600;
             ESP8266Serial.Open();
         }
     }
     else //(ESP8266Serial.IsOpen)
     {
         userSerialData  = "WLSEARCH";
         userSerialData += txtboxChnlID.Text;
         ESP8266Serial.Write(userSerialData);
     }
 }
コード例 #5
0
 private void btnChnlID_Click(object sender, EventArgs e)
 {
     if (!ESP8266Serial.IsOpen)
     {
         if (string.IsNullOrEmpty(toolStripComboBoxCOMPort.Text))
         {
             MessageBox.Show("Bitte COM-Port auswählen!");
         }
         else
         {
             ESP8266Serial.PortName = Convert.ToString(toolStripComboBoxCOMPort.SelectedItem);
             ESP8266Serial.BaudRate = 9600;
             ESP8266Serial.Open();
         }
     }
     else //(ESP8266Serial.IsOpen)
     {
         userSerialData  = "chnlID##";
         userSerialData += txtboxChnlID.Text;
         ESP8266Serial.Write(userSerialData);
         tsChnlIDSent = true;
     }
 }
コード例 #6
0
        private void ESP8266Serial_DataReceived1(object sender, SerialDataReceivedEventArgs e)
        {
            //throw new NotImplementedException();
            string data = ESP8266Serial.ReadTo("\x03");                                                           //Read until the EOT code

            string[] dataArray = data.Split(new string[] { "\x02", ";" }, StringSplitOptions.RemoveEmptyEntries); //, "$"

            foreach (string dataItem in dataArray.ToList())
            {
                checkData = dataItem;
                //receivedDataESP.Add(dataItem);
            }

            string checkDataSSID = dataArray[0];

            //MessageBox.Show(dataArray[0]);
            if (checkDataSSID == "WLSEARCH")
            {
                cmbboxWLANSSID.Items.Clear();
                //MessageBox.Show("combo box ssids eintragen");
                foreach (string dataItem in dataArray.ToList())
                {
                    cmbboxWLANSSID.Items.Add(dataItem);
                }
                cmbboxWLANSSID.Items.RemoveAt(0);
                //MessageBox.Show("WLAN Suche erfolgreich");
            }



            if (checkData == "#PCMode#")
            {
                if (!ESP8266Serial.IsOpen)
                {
                    if (string.IsNullOrEmpty(toolStripComboBoxCOMPort.Text))
                    {
                        MessageBox.Show("Bitte COM-Port auswählen!");
                    }
                    else
                    {
                        ESP8266Serial.PortName = Convert.ToString(toolStripComboBoxCOMPort.SelectedItem);
                        ESP8266Serial.BaudRate = 9600;
                        ESP8266Serial.Open();
                    }
                }
                else //(ESP8266Serial.IsOpen)
                {
                    lblSerialDat.Text = "Desktop Modus aktiv";
                    ESP8266Serial.Write("#PCMode#");
                }
            }

            if ((checkData == userSerialData))
            {
                //userDataCheck = true;
                if (passwortSent)
                {
                    btnWLANPSWD.BackColor = Color.LightGreen;
                    passwortSent          = false;
                }
                if (mqttPasswortSent)
                {
                    btnMQTTPass.BackColor = Color.LightGreen;
                    mqttPasswortSent      = false;
                }
                if (mqttApiKeySent)
                {
                    btnMQTTAPIK.BackColor = Color.LightGreen;
                    mqttApiKeySent        = false;
                }
                if (tsChnlIDSent)
                {
                    btnChnlID.BackColor = Color.LightGreen;
                    tsChnlIDSent        = false;
                }
                if (comInit)
                {
                    lblSerialDat.Text = "Verbindung zu Zählerkopf hergestellt.";
                }
                if (tsSSIDSent)
                {
                    btnWLANssid.BackColor = Color.LightGreen;
                    tsSSIDSent            = false;
                }
            }
            if ((checkData != userSerialData))
            {
                if ((checkData != "#PCMode#"))
                {
                    userDataCheck = false;
                    if (checkDataSSID == "WLSEARCH")
                    {
                        MessageBox.Show("WLAN Suche erfolgreich");
                        lblSerialDat.Text = "WLAN Suche erfolgreich";
                        checkDataSSID     = "";
                    }
                    else
                    {
                        MessageBox.Show("Bitte die Reset Taste betätigen und Passwort erneut eingeben");
                    }
                }
                else
                {
                    MessageBox.Show("PC Verbindung aktiv!");
                }
            }
        }