Go Down

Topic: TCP Software for Windows (solved) :) (Read 580 times) previous topic - next topic

Malibux

Apr 05, 2013, 08:43 pm Last Edit: Apr 06, 2013, 10:54 am by Malibux Reason: 1
Im not sure im posting this in the right place but I hope you can help me anyway. :)

I have thanks to some helpful people from this forum created a TCP script for my arduino. The code is below:
Code: [Select]
#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address, IP address and Portnumber for your Server below.
// The IP address will be dependent on your local network:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress serverIP(192,168,1,45);
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(5190); //server port

// Initialize the Ethernet server library
// with the IP address and port you want to use
int led = 8;


void setup()
{
 pinMode(led, OUTPUT);

 // start the serial for debugging
 Serial.begin(9600);
 // start the Ethernet connection and the server:
 Ethernet.begin(mac, serverIP, gateway, subnet);
 server.begin();
 Serial.println("Server started");//log
}

void loop()
{
 EthernetClient client = server.available();
 if (client) {
   while (client.connected()) {
     if (client.available()) {
       char ch = client.read();
// examine ch
       switch(ch)
       {
       case 'on':  // for example
        {
   digitalWrite(led, HIGH);
   client.println("The power is ON");
   break;
   delay(10);
   }
       case 'of':  // for example
   {
    digitalWrite(led, LOW);
    client.println("The power is OFF");
    break;
    delay(10);
   }    
       }            
     }
   }
 }
}


But now I need a free software for my computer(windows 7) which can connect to the Arduino and i can type in and send the commands to the arduino.
Can anyone help me?

Thanks in advance

SurferTim

That part is not a problem. Internet Explorer, Chrome, Safari, Firefox. Any web browser. Is that what you meant? In the address bar:
http://192.168.1.45:5190

I guess you want to establish the TCP connection from your PC? That is super easy: just use the browser! Try this line: "192.168.1.1:5190", the first part is the IP-Address of your arduino, the part after the colon is the port you are sending on.
KaiHeinz Software - http://kaiheinz.de

PeterH

#3
Apr 05, 2013, 10:09 pm Last Edit: Apr 05, 2013, 10:12 pm by PeterH Reason: 1

Code: [Select]
case 'on':  // for example
case 'of':  // for example


That isn't going to do what you expect. What you're doing there is reading one byte, and then comparing it to a multibyte character - which it won't match.

What you're trying to do needs you to read a string from the TCP stream, and then compare the string against your expected values. This is very similar to the technique used to receive commands over the serial port and you will find lots of examples of that.

For an easy life, use a web server instead of reading and processing the TCP input directly.

If you decide to stick to raw TCP, you can use something like telnet or PuTTY to connect and send arbitrary bytes over a TCP socket. If you use a browser as suggest, you'll be sending an HTTP request and you would then be back to needing a web server to parse that request - whether a standard one, or one you hack together for yourself.
I only provide help via the forum - please do not contact me for private consultancy.

Malibux

#4
Apr 06, 2013, 10:12 am Last Edit: Apr 06, 2013, 10:53 am by Malibux Reason: 1


Code: [Select]
case 'on':  // for example
case 'of':  // for example


That isn't going to do what you expect. What you're doing there is reading one byte, and then comparing it to a multibyte character - which it won't match.

What you're trying to do needs you to read a string from the TCP stream, and then compare the string against your expected values. This is very similar to the technique used to receive commands over the serial port and you will find lots of examples of that.

For an easy life, use a web server instead of reading and processing the TCP input directly.

If you decide to stick to raw TCP, you can use something like telnet or PuTTY to connect and send arbitrary bytes over a TCP socket. If you use a browser as suggest, you'll be sending an HTTP request and you would then be back to needing a web server to parse that request - whether a standard one, or one you hack together for yourself.


I would like to stick with the TCP raw because i already found an app for my mobile phone(TCP Client) which can work with this code.. and now i found a program which can do it.. thanks you all for the help

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy