Go Down

Topic: What connection? (Read 686 times) previous topic - next topic

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

PaulS

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.

draythomp

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?
Trying to keep my house under control http://www.desert-home.com/

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

tastewar

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.

cantore

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

Code: [Select]

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.

draythomp

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.
Trying to keep my house under control http://www.desert-home.com/

Go Up