Go Down

Topic: Simple arduino ethernet communication for beginner (Read 17 times) previous topic - next topic

bgree15

zoomkat,

Thanks for the code! I've been searching on and off for WEEKS and I finally got it working!  You have no idea how much trouble I've spent trying to figure all this out haha. 

Aliende


It seems pretty simple, and I've been reading and searching how to do it, but I'm just not really getting it


Thank you very much for creating this thread :D, havent tested the solution yet, but I was on the same situation, every time I searched for "arduino receive data through ethernet" I found arduino hosting pages or accessing them, but never reading data from the request (POST and GET parameters).

Although, I found this very interesting library called RESTduino wich I am using on my project, it´s really awesome and works like a charm.


zoomkat

Quote
I searched for "arduino receive data through ethernet" I found arduino hosting pages or accessing them, but never reading data from the request (POST and GET parameters).


That would be an ethernet client function, which has has a good bit of code posted on the board. Below is some client test code.

Code: [Select]

//zoomkat 9-22-12
//simple client test
//for use with IDE 1.0.1
//with DNS, DHCP, and Host
//open serial monitor and send an e to test
//for use with W5100 based ethernet shields

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

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address

char serverName[] = "web.comporium.net"; // zoomkat's test web page server
EthernetClient client;

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

void setup(){

  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    while(true);
  }

  Serial.begin(9600);
  Serial.println("Better client test 9/22/12"); // so I can keep track of what is loaded
  Serial.println("Send an e in serial monitor to test"); // what to do to test
}

void loop(){
  // check for serial input
  if (Serial.available() > 0) //if something in serial buffer
  {
    byte inChar; // sets inChar as a byte
    inChar = Serial.read(); //gets byte from buffer
    if(inChar == 'e') // checks to see byte is an e
    {
      sendGET(); // call sendGET function below when byte is an e
    }
  } 
}

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

void sendGET() //client function to send/receive GET request data.
{
  if (client.connect(serverName, 80)) {  //starts client connection, checks for connection
    Serial.println("connected");
    client.println("GET /~shb/arduino.txt HTTP/1.0"); //download text
    client.println("Host: web.comporium.net");
    client.println(); //end of get request
  }
  else {
    Serial.println("connection failed"); //error message if no client connect
    Serial.println();
  }

  while(client.connected() && !client.available()) delay(1); //waits for data
  while (client.connected() || client.available()) { //connected or data available
    char c = client.read(); //gets byte from ethernet buffer
    Serial.print(c); //prints byte to serial monitor
  }

  Serial.println();
  Serial.println("disconnecting.");
  Serial.println("==================");
  Serial.println();
  client.stop(); //stop client

}

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   8)

alacosta

Hi All  also a new comer!  - trying to get my head round Arduino / Ethernet .
Need some help
I can use "get" to turn on / off led but need to be able to read an analogue  digital value to control the brightness / speed  of a light or motor.
I would  appreciate some sample code to read /convert the http value (string?)  to  control the arduino analogue pin. Keep searching but can seem to find what I am looking for so any help guidance would be appreciated.

Go Up