Arduino control through Local IP from VB net application.

Hello everybody.

Something very strange happens in my code and I really need your help.

So, my stuff is an arduino uno with an ethernet shield and i vb net application. The idea is to give some orders to the arduino through the vb net app. It works but there is an issue. Sometimes i v got rapidly response from the arduino some others with a delay which is max approx 4 sec. I cant find why is that happen.

Here is my codes.

Arduino code :

//zoomkat 12-8-11
//simple button GET with iframe code
//for use with IDE 1.0
//open serial monitor to see what the arduino receives
//use the \ slash to escape the " in the html (or use ')
//address will look like http://192.168.1.102:84 when submited
//for use with W5100 based ethernet shields

#include <SPI.h>
#include <Ethernet.h>
#define HC12 Serial
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 102 }; // ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(84); //server port

String readString; 

//////////////////////

void setup(){

  pinMode(5, OUTPUT); //pin selected to control
  //start Ethernet
  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  server.begin();

  //enable serial data print 
  Serial.begin(9600); 
    HC12.begin(9600);
  Serial.println("server LED test 1.0"); // so I can keep track of what is loaded
}

void loop(){
  // Create a client connection
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

        //read char by char HTTP request
        if (readString.length() < 200) {

          //store characters to string 
          readString += c; 
          //Serial.print(c);
        } 

        //if HTTP request has ended
        if (c == '\n') {



/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//   

String stringOne = readString;
  //Serial.println(stringOne);
  // replace() changes all instances of one substring with another:
  // first, make a copy of the original string:
  String stringTwo = stringOne;
  // then perform the replacements:
  stringTwo.replace("HTTP/1.1", "");
  // print the original:
  //Serial.println("Original string: " + stringOne);
  // and print the modified string:
  //Serial.println("Modified string: " + stringTwo);


 // String stringOne = readString;
  //Serial.println(stringOne);
  // replace() changes all instances of one substring with another:
  // first, make a copy of the original string:
  String stringThree = stringTwo;
  // then perform the replacements:
  stringThree.replace("%20",  " ");
  // print the original:
  //Serial.println("Original string: " + stringOne);
  // and print the modified string:
  //Serial.println("Modified string: " + stringTwo);

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
          

          ///////////////
          HC12.println(stringThree); //print to serial monitor for debuging 

          //now output HTML data header
             if(readString.indexOf('?') >=0) { //don't send new page
               client.println("HTTP/1.1 ");
               client.println();
               client.println();  
             }
             else {
          client.println("HTTP/1.1 200 OK"); //send new page
          client.println("Content-Type: text/html");
         client.println();

          client.println("<HTML>");
          client.println("<HEAD>");
          client.println("<TITLE>Arduino GET test page</TITLE>");
          client.println("</HEAD>");
          client.println("<BODY>");

          client.println("<H1>Zoomkat's simple Arduino button</H1>");
          
          client.println("<a href=\"/?on1\" target=\"inlineframe\">ON</a>"); 
          client.println("<a href=\"/?off\" target=\"inlineframe\">OFF</a>"); 

          //client.println("<IFRAME name=inlineframe src=\"res://D:/WINDOWS/dnserror.htm\" width=1 height=1\">");
          client.println("<IFRAME name=inlineframe style=\"display:none\" >");          
          client.println("</IFRAME>");

          client.println("</BODY>");
          client.println("</HTML>");
             }

          delay(1);
          //stopping client
          client.stop();

          ///////////////////// control arduino pin
          if(readString.indexOf("on1") >0)//checks for on
          {
            digitalWrite(5, HIGH);    // set pin 4 high
            Serial.println("Led On");
          }
          if(readString.indexOf("off") >0)//checks for off
          {
            digitalWrite(5, LOW);    // set pin 4 low
            Serial.println("Led Off");
          }
          //clearing string for next read
          readString="";

        }
      }
    }
  }
}

vb net code :

Imports System.IO
Imports System.IO.Ports
Imports System.Threading

Public Class Form1
    
    


    Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
        If SerialPort1.IsOpen Then
            SerialPort1.WriteLine("m")
        End If
        TextBox10.Text = TextBox11.Text
        TextBox10.Text = TextBox10.Text & "m"
        WebBrowser1.Navigate(TextBox10.Text)
    End Sub

    Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
       

        TextBox10.Text = TextBox11.Text
        TextBox10.Text = TextBox10.Text & "c" & Label10.Text
        WebBrowser1.Navigate(TextBox10.Text)
        ' Threading.Thread.Sleep(20)
        TextBox10.Text = TextBox11.Text
        TextBox10.Text = TextBox10.Text & "a" & Label11.Text
        WebBrowser1.Navigate(TextBox10.Text)
        ' Threading.Thread.Sleep(20)
        TextBox10.Text = TextBox11.Text
        TextBox10.Text = TextBox10.Text & "k"
        WebBrowser1.Navigate(TextBox10.Text)
        ' Threading.Thread.Sleep(20)
    End Sub

   

    

    Private Sub TrackBar1_Scroll(sender As Object, e As EventArgs) Handles TrackBar1.Scroll
        Label8.Text = TrackBar1.Value
        If SerialPort1.IsOpen Then

            SerialPort1.WriteLine("z" & Val(Label8.Text))
        End If
        TextBox10.Text = TextBox11.Text
        TextBox10.Text = TextBox10.Text & "z" & Val(Label8.Text)
        WebBrowser1.Navigate(TextBox10.Text)
    End Sub

   

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Label5.Text = "ΕΞΕΛΙΞΗ"
        Label10.Text = TextBox1.Text * 3600 + TextBox2.Text * 60
       

        TextBox10.Text = TextBox11.Text
        TextBox10.Text = TextBox10.Text & "c" & Label10.Text
        WebBrowser1.Navigate(TextBox10.Text)


        If Label10.Text > 0 Then
            Timer2.Start()
        End If

    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Label15.Text = "ΕΞΕΛΙΞΗ"
        Label11.Text = TextBox3.Text * 3600 + TextBox4.Text * 60
      
        TextBox10.Text = TextBox11.Text
        TextBox10.Text = TextBox10.Text & "a" & Label11.Text
        WebBrowser1.Navigate(TextBox10.Text)



        'Label11.Text = Label11.Text + 1
        If Label11.Text > 0 Then
            Timer3.Start()
        End If
    End Sub
  

 
   

    Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click
       
       
        TextBox10.Text = TextBox11.Text
        TextBox10.Text = TextBox10.Text & "s" & RichTextBox1.Text
        WebBrowser1.Navigate(TextBox10.Text)
    End Sub

   

    
End Class

your help please !!!

Textbox10 is the default ip of my ethernet shield http://192.168.1.102:84/

When i use the web browser, for example http://192.168.1.102:84/sHello World it has rapidly response and works perfect. Also from my mobile, i have no delay at all. The only delay comes and not ever when i m usin the vb application.....

PALAVRAS:
The only delay comes and not ever when i m usin the vb application.....

Sounds like a problem with your VB.NET program.

This is not a place for debugging that.
The MSDN forums can help you.

.

          HC12.println(stringThree); //print to serial monitor for debuging

I seriously doubt that that is what that code does.

        Label10.Text = TextBox1.Text * 3600 + TextBox2.Text * 60

What does your calculator make of this equation? I can not even begin to imagine what multiplying some text by 3000 means.