Simplest ethernet shield example webclient...call url

Hi, I just got an Ethernet shield 28j60 and I am finding it impossible to locate a code example which just calls an url passing some parameters.

The idea is to call a php file and let this upload some data to a mysql database, howerver, I cant find a minimalistic example using the 28J60 which just does something like this...

http://www.mywebsite/power/upload.php?P=1023&V=230&I=4.8

Im amaze on the amount of webserver examples, but nothing as "simple" as this?
Please if anyone could help me out,
Thanks a lot

...because there is no simple to use arduino library for the enc28j60 shields, you should have get yourself a wiznet shield :wink:

this is the best library for enc28j60 i know: http://blog.thiseldo.co.uk/?p=504

haha yes thats what i am noticing !!! what a mistake.

I really thought that calling an URL would not be that complicated, but there seems to be no examples anywhere around the net.
its quite strange as i believe a webserver is more difficult, but yet there a quite a lot of examples on this, whereas no simple client code.

Ive checked that website, but there seems not to be any example as i need, thanks anyway.

Sergegsx:
haha yes thats what i am noticing !!! what a mistake.

I really thought that calling an URL would not be that complicated, but there seems to be no examples anywhere around the net.
its quite strange as i believe a webserver is more difficult, but yet there a quite a lot of examples on this, whereas no simple client code.

Ive checked that website, but there seems not to be any example as i need, thanks anyway.

I got exactly the same problem

http://arduino.cc/forum/index.php/topic,74998.0.html

Un saludo :wink:

ikaros:

Sergegsx:
haha yes thats what i am noticing !!! what a mistake.

I really thought that calling an URL would not be that complicated, but there seems to be no examples anywhere around the net.
its quite strange as i believe a webserver is more difficult, but yet there a quite a lot of examples on this, whereas no simple client code.

Ive checked that website, but there seems not to be any example as i need, thanks anyway.

I got exactly the same problem

http://arduino.cc/forum/index.php/topic,74998.0.html

Un saludo :wink:

did you manage to find a webclient example thats working? I have the same ethernet shield from ebay.

gracias

Sergegsx:

ikaros:

Sergegsx:
haha yes thats what i am noticing !!! what a mistake.

I really thought that calling an URL would not be that complicated, but there seems to be no examples anywhere around the net.
its quite strange as i believe a webserver is more difficult, but yet there a quite a lot of examples on this, whereas no simple client code.

Ive checked that website, but there seems not to be any example as i need, thanks anyway.

I got exactly the same problem

http://arduino.cc/forum/index.php/topic,74998.0.html

Un saludo :wink:

did you manage to find a webclient example thats working? I have the same ethernet shield from ebay.

gracias

Nope. So far I haven't made any progress.

Funny... I found plenty of information about how to use it as server, but not as client... which seems to me much easier. Weird.

I'll keep you up to date on how I'm doing... but I think i'll end up buying an arduino ethernet, or a right arduino WIZ eth-shield.

yes please keep me posted if you manage to find a simple example on calling an URL. I definitely let you know if I find it myself.

I bought this shield cause my WIZ shield stopped working for no apparent reason. but 2 days ago, for no apparent reason worked again when I uploaded exactly the same code I was using before.
Definitely the best thing is to buy a WIZ shield but lets try to make something useful out of this one.
cheers.

it drove me nuts but this works for me...
this code can bettered as i open the connection in the loop which must be bad (|)

I wanted to use the domain name not the ip address to post data to my drupal site.
The example below is on my local webserver but its the same case if you have a live server with a shared ip address.
I set up a simple test page on my local site http://arduino/arduino.php as a proof of concept which saved the data Arduino posted.

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

// Set the unique mac and ip address etc for the ethernet board
// the only bit i havent tested is the gateway on a remote server but it should be fine
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192,168,0,70 }; // just an ip address not being used on my local pc
byte server[] = { 192,168,0,50 }; // my local machines ip address from ifconfig
byte gateway[] = { 192,168,0,1 }; // my router
byte subnet[] = { 255,255,255,0 };

void setup() {
Serial.begin(9600);
}

// so far this is all standard stuff and should make sense.
// this next step was complete trial and error
// the key difference is that i seemed to have to connect in the loop not in setup

void loop()
{
Client client(server, 80);
Ethernet.begin(mac, ip, gateway, subnet);
delay(1000);
// read the pin values here and decide if to post it (edit to suit), i am only interested when i am being burgled.
//if (A0 >100) {
if (client.connect()) {
Serial.println("client connected OK");
client.print("GET http://arduino/");
// put your own values in here...
client.print("arduino.php?room=kitchen&motion=TRUE&temp=100\n");
client.print("HTTP/1.1\n");
//client.print("Host: arduino\n"); //hmm don't need to seem this anymore
client.print("User-Agent: Arduino (Arduino Test Code)");
client.println("\n");
}
//}

if (!client.connected()) {
Serial.println();
Serial.println("disconnected.");
//client.stop();
}
}

for my test i had a simple php script at http://arduino/arduino.php to store the sent values in a text file like this
// make sure www-data can write to test.txt
file_put_contents('test.txt', print_r( $_GET,1) ."\n", FILE_APPEND) ;

tidy the code as needed, prolly put the client connect inside the if(A0>100) statement for sure but it's late (again).

if stuck pls post

Isn't this code for the WIZ based shield?

By using new EtherCard library for enc28j60 it is also simple. Code is not tested (it's modified example):

#include <EtherCard.h>

byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
char website[] PROGMEM = "www.mywebsite.com";

byte Ethernet::buffer[700];
uint32_t timer;
Stash stash;

int value_P = 1023;
int value_V = 230;
float value_I = 4.8;
char tempS[10];


void setup () {
  Serial.begin(57600);
  Serial.println("\n[webClient]");

  if (ether.begin(sizeof Ethernet::buffer, mymac) == 0) 
    Serial.println( "Failed to access Ethernet controller");
  if (!ether.dhcpSetup())
    Serial.println("DHCP failed");


  if (!ether.dnsLookup(website))
    Serial.println("DNS failed");
    
}

void loop () {
  ether.packetLoop(ether.packetReceive());
  
  if (millis() > timer) {
    timer = millis() + 10000;
    
    // generate two fake values as payload - by using a separate stash,
    // we can determine the size of the generated message ahead of time
    byte sd = stash.create();
    stash.print("0,");
    stash.println((word) millis() / 123);
    stash.print("1,");
    stash.println((word) micros() / 456);
    stash.save();
    
    // generate the header with payload - note that the stash size is used,
    // and that a "stash descriptor" is passed in as argument using "$H"
    Stash::prepare(PSTR("PUT http://$F/power/upload.php?P=$D&V=$D&I=$D HTTP/1.0" "\r\n"
                        "Host: $F" "\r\n"
                        "Content-Length: $D" "\r\n"
                        "\r\n"
                        "$H"),
            website, value_P, value_V, dtostrf(value_I,4,2,tempS), website, stash.size(), sd);

    ether.tcpSend();
  }
}