Hi, I write simple http client with Ethernet module ENC28J60 and ethercard library. but I have problem.
I need send multiple HTTP GET requsts in for loop.
String will be temperature from sensor. Now I have 3 sensors.
for (byte i=0; i<3; i++) {
ether.browseUrl(PSTR("/arduino.php?"), "ABC", website, NULL);
ether.browseUrl(PSTR("/arduino.php?"), "DEF", website, NULL);
ether.browseUrl(PSTR("/arduino.php?"), "GHI", website, NULL);
}
but in webserver log is only last send message:
192.168.1.55 - - [19/Sep/2013:01:18:42 +0200] "GET /arduino.php?GHI HTTP/1.0" 200 212 "-" "-"
Where is problem? It is necessary to wait some time between send requst?
I do not need work with webserver response.
Thank you for help.
You are sending three requests three times?
I do not need work with webserver response.
Then you will never know what the problem is. It may be telling you, but you are not listening to it.
SurferTim:
Then you will never know what the problem is. It may be telling you, but you are not listening to it.
static void ethernet_callback(byte status, word off, word len) {
Serial.println(F(">>>"));
Ethernet::buffer[off+300] = 0;
Serial.print((const char*) Ethernet::buffer + off);
Serial.println(F("..."));
}
void setup() {
Serial.begin(9600);
if (ether.begin(sizeof Ethernet::buffer, mac) == 0)
Serial.println(F("Failed_to_access_Ethernet_controller"));
if (!ether.dhcpSetup()) {
Serial.println(F("DHCP_failed"));
} else {
Serial.println(F("DHCP_OK"));
}
ether.printIp(F("IP: "), ether.myip);
ether.printIp(F("GW: "), ether.gwip);
ether.printIp(F("DNS: "), ether.dnsip);
if (!ether.dnsLookup(website))
Serial.println(F("DNS failed"));
ether.printIp(F("SRV: "), ether.hisip);
Serial.println(F("Sending Ethernet requst..."));
for (byte i=0; i<3; i++) {
ether.browseUrl(PSTR("/arduino.php?"), "ABC", website, ethernet_callback);
ether.browseUrl(PSTR("/arduino.php?"), "DEF", website, ethernet_callback);
ether.browseUrl(PSTR("/arduino.php?"), "GHI", website, ethernet_callback);
}
}
At server arduino.php:
<?php
echo print_r($_GET);
?>
PHP script return array of GET requests. For /arduino.php?a=b print:
Array
(
[a] => b
)
1
After I turn on Arduino I see in webserver log only last message:
192.168.1.56 - - [19/Sep/2013:12:19:17 +0200] "GET /arduino.php?GHI HTTP/1.0" 200 238 "-" "-"
and Arduino print only last response too:
DHCP_OK
IP: 192.168.1.56
GW: 192.168.1.1
DNS: 192.168.1.1
SRV: 192.168.1.1
Sending Ethernet...
>>>
HTTP/1.1 200 OK
Date: Thu, 19 Sep 2013 10:19:17 GMT
Server: Apache/2.2.22 (Ubuntu)
X-Powered-By: PHP/5.3.10-1ubuntu3.8
Vary: Accept-Encoding
Content-Length: 26
Connection: close
Content-Type: text/html
Array
(
[GHI] =>
)
1
...
I do not have any idea 
The first thing I would do is drop the for() loop here. You are sending the three requests three times.
for (byte i=0; i<3; i++) {
ether.browseUrl(PSTR("/arduino.php?"), "ABC", website, ethernet_callback);
ether.browseUrl(PSTR("/arduino.php?"), "DEF", website, ethernet_callback);
ether.browseUrl(PSTR("/arduino.php?"), "GHI", website, ethernet_callback);
}
I'm a W5100 guy, so the rest you may have to wait for someone who is more familiar with the ENC28J60 IC and library. Since it does require a callback function, maybe you are not waiting long enough between requests, and the subsequent requests terminate the previous requests.
I delete for loop so I now have:
Serial.println(F("Sending Ethernet..."));
ether.browseUrl(PSTR("/arduino.php?"), "ABC", website, ethernet_callback);
ether.browseUrl(PSTR("/arduino.php?"), "DEF", website, ethernet_callback);
ether.browseUrl(PSTR("/arduino.php?"), "GHI", website, ethernet_callback);
But the problem is still the same. (With for loop requests must send three times.)
Wait between sending requsts - it has also occurred to me. But how can I do it? Delay() function cannot be possible use with Ethernet (delay freeze all for defined time).
I try read response before sending new request but problem is still the same:
Serial.println(F("Sending Ethernet..."));
ether.packetLoop(ether.packetReceive());
ether.browseUrl(PSTR("/arduino.php?"), "ABC", website, ethernet_callback);
ether.packetLoop(ether.packetReceive());
ether.browseUrl(PSTR("/arduino.php?"), "DEF", website, ethernet_callback);
ether.packetLoop(ether.packetReceive());
ether.browseUrl(PSTR("/arduino.php?"), "GHI", website, ethernet_callback);
ether.packetLoop(ether.packetReceive());
The way this normally works, no matter the ethernet controller, is the client opens a connection to the server, and if successful, sends one request. Then the client waits for the server to respond. The server responds, and when finished, closes the connection. The client then closes its end.
If you want to send two requests, you must open the connection, send the first request, get the first response, and close the connection after the server does. Then repeat that for a second request send. Then repeat that for a third send. And on...
Or send all the data in one request.
SurferTim:
If you want to send two requests, you must open the connection, send the first request, get the first response, and close the connection after the server does. Then repeat that for a second request send. Then repeat that for a third send. And on...
That's what I need. But how can I do it?
SurferTim:
Or send all the data in one request.
It is not possible. I read sensors status in for loop. I do not know number of connected sensors so I can't define size of array (and I do not have enough RAM).
Maybe I'll try to send requests over UDP. 
But HTTP is easy to work on server side.
That's what I need. But how can I do it?
You will have to wait for someone familiar with the ENC28J60 to answer that.
I found article Multiple browser request example. I do not tested.
But I will use UDP instead of TCP.