Best way to exchange data via internet

Hello guys,

I was wondering what would be the best way to exchange data between an arduino and a computer via internet? The main idea here is that I want to send data from arduino to a remote computer, that data will be fed into a matlab algorithm and finally the computer will send data back to arduino (just one int will do). I read that it is difficult to use arduino as server and client. Do u have any suggestions on how to approach this??


The ideal approach would be to make Matlab operate as a web service

In which case your Arduino could simply do a HTTP GET or HTTP POST to send the data to the web service, and the web service would computer the result and return it as data e.g. JSON or even CSV etc.

See this link

On the arduino end, you could run both client and server code on the arduino.

Thanks for the replies. RogerClark's link may be very helpfull with the matlab end! Zoomkat, I saw your server/client code but i'm not realy sure how I can use it, is there any documentation? I upload it on arduino but i see no results (i didnt change anything and probably thats the problem). I have a webpage, how would I be able to post the sensor data there and then get the resault?

Do you have a local web server running onto which you can install the exe into the cgibin folder?

I have a webpage, how would I be able to post the sensor data there and then get the resault?

This doesn't give us any information.

What web server are you running ? IIS. WAMP ??

Have you followed the instructions in that link i.e from here

Zoomkat, I saw your server/client code but i'm not realy sure how I can use it, is there any documentation? I upload it on arduino but i see no results (i didnt change anything and probably thats the problem). I have a webpage, how would I be able to post the sensor data there and then get the resault?

I checked the below code and it still makes a GET request to the web server and displays the result in the serial monitor. This is the mechanism for sending data from an arduino to a web server. A POST type of data sending could also be used.

//zoomkat 7-03-12, combined client and server
//simple button GET with iframe code
//for use with IDE 1.0
//open serial monitor and send an g to test client and
//see what the arduino client/server receives
//web page buttons make pins high/low
//use the ' in html instead of " to prevent having to escape the "
//address will look like when submited
//for use with W5100 based ethernet shields

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //assign arduino mac address
byte ip[] = {192, 168, 1, 102 }; // ip in lan assigned to arduino
byte gateway[] = {192, 168, 1, 1 }; // internet access via router
byte subnet[] = {255, 255, 255, 0 }; //subnet mask
EthernetServer server(84); //server port arduino server will use
EthernetClient client;
char serverName[] = ""; // (DNS) zoomkat's test web page server
//byte serverName[] = { 208, 104, 2, 86 }; // (IP) zoomkat web page server IP address

String readString; //used by server to capture GET request 


void setup(){

  pinMode(5, OUTPUT); //pin selected to control
  pinMode(6, OUTPUT); //pin selected to control
  pinMode(7, OUTPUT); //pin selected to control
  pinMode(8, OUTPUT); //pin selected to control

  //pinMode(5, OUTPUT); //pin 5 selected to control
  Serial.println(F("server/client 1.0 test 7/03/12")); // keep track of what is loaded
  Serial.println(F("Send an g in serial monitor to test client")); // what to do to test client

void loop(){
  // check for serial input
  if (Serial.available() > 0) 
    byte inChar;
    inChar =;
    if(inChar == 'g')
      sendGET(); // call client sendGET function

  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c =;

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

          //store characters to string 
          readString += c; 

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

          Serial.print(readString); //print to serial monitor for debuging 

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

            client.println(F("<TITLE>Arduino GET test page</TITLE>"));

            client.println(F("<H1>Zoomkat's simple Arduino 1.0 button</H1>"));

            // DIY buttons
            client.println(F("<a href=/?on2 target=inlineframe>ON</a>")); 
            client.println(F("<a href=/?off3 target=inlineframe>OFF</a>


            client.println(F("<a href=/?on4 target=inlineframe>ON</a>")); 
            client.println(F("<a href=/?off5 target=inlineframe>OFF</a>


            client.println(F("<a href=/?on6 target=inlineframe>ON</a>")); 
            client.println(F("<a href=/?off7 target=inlineframe>OFF</a>


            client.println(F("<a href=/?on8 target=inlineframe>ON</a>")); 
            client.println(F("<a href=/?off9 target=inlineframe>OFF</a>


            client.println(F("&nbsp;<a href=/?off2468 target=inlineframe>ALL ON</a>")); 
            client.println(F("&nbsp;<a href=/?off3579 target=inlineframe>ALL OFF</a>")); 

            client.println(F("<IFRAME name=inlineframe style='display:none'>"));          


          //stopping client

          ///////////////////// control arduino pin
          if(readString.indexOf('2') >0)//checks for 2
            digitalWrite(5, HIGH);    // set pin 5 high
            Serial.println(F("Led 5 On"));
          if(readString.indexOf('3') >0)//checks for 3
            digitalWrite(5, LOW);    // set pin 5 low
            Serial.println(F("Led 5 Off"));
          if(readString.indexOf('4') >0)//checks for 4
            digitalWrite(6, HIGH);    // set pin 6 high
            Serial.println(F("Led 6 On"));
          if(readString.indexOf('5') >0)//checks for 5
            digitalWrite(6, LOW);    // set pin 6 low
            Serial.println(F("Led 6 Off"));
          if(readString.indexOf('6') >0)//checks for 6
            digitalWrite(7, HIGH);    // set pin 7 high
            Serial.println(F("Led 7 On"));
          if(readString.indexOf('7') >0)//checks for 7
            digitalWrite(7, LOW);    // set pin 7 low
            Serial.println(F("Led 7 Off"));
          if(readString.indexOf('8') >0)//checks for 8
            digitalWrite(8, HIGH);    // set pin 8 high
            Serial.println(F("Led 8 On"));
          if(readString.indexOf('9') >0)//checks for 9
            digitalWrite(8, LOW);    // set pin 8 low
            Serial.println(F("Led 8 Off"));

          //clearing string for next read


void sendGET() //client function to send and receive GET data from external server.
  if (client.connect(serverName, 80)) {
    client.println(F("GET /~shb/arduino.txt HTTP/1.1"));
    client.println(F("Connection: close"));
  else {
    Serial.println(F("connection failed"));

  while(client.connected() && !client.available()) delay(1); //waits for data
  while (client.connected() || client.available()) { //connected or data available
    char c =;



Ok!! So i got Zoomkat's code to work!! i had to change the port to 80 instead of 84 (why is that???). Now, how can I get text from a form like this?

<form action="/login" method="POST"><input type="text" name="textf"><input type="submit" value="Go"></form>

I whould have post a foto but i dont know how... A bit embarrassed :roll_eyes:
it's a text field and a button to submit it!