Hi, I have problem with ethercard library and Ethernet module ENC28J60. Problem is with delay() function.
With delay(1000) it works fine and I see request in "/var/log/apache2/access.log" on server. When I set longer delay(), for example 10 seconds - delay(10000) server don't receive any requests.
I found similar question, but it is not helpful for me
There is my code:
#include <EtherCard.h>
static byte mymac[] = { 0x00, 0x00, 0x6C, 0x01, 0x02, 0x03 };
char website[] PROGMEM = "server.lan";
byte Ethernet::buffer[1000];
static uint32_t timer; // http://mbed.org/handbook/C-Data-Types (0 .. 4,294,967,295)
const int inputButton1 = 5;
const int inputButton2 = 7;
static void response_callback (byte status, word off, word len) {
Serial.print((const char*) Ethernet::buffer + off + 207);
}
void setup () {
Serial.begin(9600);
if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
Serial.println( "Failed to access Ethernet controller");
if (!ether.dhcpSetup())
Serial.println("DHCP failed");
ether.printIp("IP: ", ether.myip);
ether.printIp("Netmask: ", ether.mymask);
ether.printIp("GW: ", ether.gwip);
ether.printIp("DNS: ", ether.dnsip);
if (!ether.dnsLookup(website))
Serial.println("DNS failed");
else
Serial.println("DNS resolution done");
ether.printIp("SRV IP: ", ether.hisip);
Serial.println();
pinMode(inputButton1, INPUT);
pinMode(inputButton2, INPUT);
Serial.println("END SETUP");
}
void loop() {
delay(10000);
int buttonState1 = digitalRead(inputButton1);
int buttonState2 = digitalRead(inputButton1);
String stringData = String(50);
stringData = "?button1=";
if (digitalRead(inputButton1) == HIGH)
stringData += "ON";
else
stringData += "OFF";
stringData += "&button2=";
if (digitalRead(inputButton2) == HIGH)
stringData += "ON";
else
stringData += "OFF";
char stringToSend[50];
stringData.toCharArray(stringToSend, 50);
Serial.println(stringToSend);
ether.packetLoop(ether.packetReceive());
if (millis() > timer) {
timer = millis() + 5000;
ether.browseUrl(PSTR("/arduino.php/"), stringToSend, website, response_callback);
}
}
Thank you for help.