Pages: [1]   Go Down
Author Topic: What connection?  (Read 640 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Dear all,

I want to send some data (float, int) over ethernet to a pc.
what would be the best way to do this?

Any examples (not the webserver).

Best,
Stefan
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 631
Posts: 50115
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you want to send data to a specific PC, you are better off connecting the Arduino to that PC, using the USB cable, and skipping the ethernet shield.

Otherwise, you need something on the server that the Arduino client connects to to route the data to the right PC, which may not be easy/possible, depending on where the server and PC are with respect to a common network.
Logged

New River, Arizona
Offline Offline
God Member
*****
Karma: 19
Posts: 936
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

This may not be the best way to do it but I convert the ints, floats, whatever to ascii and send it as text.  This has the incredible advantage of being readable when debugging.  I usually format the data into comma separated values (CSV) and the do a get with the values.  Over the wire it would look like "Device1,128,36.4,12" and the receiving end would parse out the values it wanted.

On a pc you can do a split() to have the data values separated, on the arduino there are other techniques that you can use.

Does any of this make sense?
Logged

Trying to keep my house under control http://www.desert-home.com/

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the answers.

Ethernet is required, because the Arduino should get power with POE.

draythomp: Has you got an example? My problem when I changed the Webserverexample then it is not running probably. I have just added an object for my tempsensor. nothing else^^
would be nice if you can help me out.

Stefan
Logged

Arlington, MA, USA
Offline Offline
Sr. Member
****
Karma: 0
Posts: 259
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you want to send from the Arduino to the PC, you probably want to reverse things. Have a very simple TCP service listening at a particular port on the PC, and connect to it as a client from the Arduino.
Logged

italy
Offline Offline
Full Member
***
Karma: 3
Posts: 227
Muuuuu
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think an easy way is to use get or post. Act in this way:

Code:
client.print("GET /nomeScript.php?var1=");            // send this to apache on server to call the script "nomeScript.php"
      client.print(var1);
      client.println(" HTTP/1.1");                  //
      //Serial.println(" HTTP/1.1");                  //
      client.println("Host: www.myHost.com");    //
      //Serial.println("Host: www.myHost.com");    //
      client.println("User-Agent: Arduino");        // ethernet related stuff
      //Serial.println("User-Agent: Arduino");        //
      client.println("Accept: text/html");          //
      //Serial.println("Accept: text/html");          //
      //client.println("Connection: close");        //
      //Serial.println("Connection: close");        //
      client.println();                             //
      Serial.println();




After on a php srcipt you can save the variable in a text file or in a database as you need.
Logged

New River, Arizona
Offline Offline
God Member
*****
Karma: 19
Posts: 936
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

cantore's technique is exactly what I use as well.  If you want to send several values just separate each of them with a comma from the last one and then the server can parse them out.
Logged

Trying to keep my house under control http://www.desert-home.com/

Pages: [1]   Go Up
Jump to: