Go Down

Topic: Anyone familiar with EtherCard.h or ENC28J60 Ethernet shield? (Read 1 time) previous topic - next topic


Good day guys! I'm currently working on a web server switch for my project and here is the code. So far it is working fine, its just having some timeouts after it has been open for more than 30 mins.

#include <EtherCard.h>

// Ethernet Part declaration
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
#define BUFFER_SIZE 800
BufferFiller bfill;
byte Ethernet::buffer[BUFFER_SIZE];
static byte myip[] = {192,168,1,15};
// Ethernet Part ends here

const int ledPin = 6;

void setup () {

//Ethernet Debugging

ether.begin(BUFFER_SIZE, mymac, 10);


//Ethernet Debugging Ends Here

  pinMode(10, OUTPUT);                       
digitalWrite(10, HIGH);

  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);

void homepage(){
"<!DOCTYPE html><html><title>Ethernet Controller</title>"
"<body><div id='content' style='background-color:lightgreen;width:1100px;height:900px;'><hr><h1><p><center><font size='28'><br>IP Based Automated <br>Load Carrier with RFID Security<br>"
"</p><hr><br><table bgcolor='#58D3F7' border='1'><tr><th colspan='4' >Room Destination</th></tr>"
"<tr><td><INPUT Type='BUTTON' VALUE='GV208' ONCLICK='window.location.href=\"/?cmd=GV208\"'></td><td>"
"<INPUT Type='BUTTON' VALUE='GV209' ONCLICK='window.location.href=\"/?cmd=GV209\"'></td>"
"<td><INPUT Type='BUTTON' VALUE='GV210' ONCLICK='window.location.href=\"/?cmd=GV210\"'></td>"
"<td><INPUT Type='BUTTON' VALUE='GV211' ONCLICK='window.location.href=\"/?cmd=GV211\"'></td></tr>"
"</table><br><hr>Mobot is</font><br><hr></div></body></html>"
void http_Unauthorized(){
      bfill.emit_p(PSTR("HTTP/1.0 401 Unauthorized\r\n"
    "Content-Type: text/html\r\n\r\n"
    "<h1>401 Unauthorized</h1>"   

void loop() {
  //checking for requesting client
  word len = ether.packetReceive();
  word pos = ether.packetLoop(len);

  if(pos) {
    bfill = ether.tcpOffset();
    //storing buffer on data variable
    char *data = (char *) Ethernet::buffer + pos;
    if (strncmp("GET /", data, 5) != 0) {
            // Unsupported HTTP request
            // 304 or 501 response would be more appropriate
    else {
        data += 5;
            if (data[0] == ' ') {
                // Return home page
            else if (strncmp("?cmd=GV208 ", data, 10) == 0) {
                Serial.println("Recieve ON");
               digitalWrite(ledPin, HIGH);

            else if (strncmp("?cmd=GV209 ", data, 10) == 0) {
                Serial.println("Recieve OFF");
                digitalWrite(ledPin, LOW);
            else if (strncmp("?cmd=GV210 ", data, 10) == 0) {
                Serial.println("Recieve HALF");
            else if (strncmp("?cmd=GV211 ", data, 10) == 0) {
                Serial.println("Recieve HALF");
            else {
                // Page not found

My problem is that when I want to create a better looking webpage, everything stops loading. I guess this is the limited RAM issues? (I'm thing of buying ATMEGA1280 to have more RAM, currently using ATMGE328)
While I still dont have a new mcu, is it possible to send the html on multiple packets instead of one so I can host a bigger html file? or is buying a new MCU the only solution for now? or is there any other way I can use a bigger HTML?

Also about the timeouts, is there a problem in my code which is causing the timeouts? Can i do anything to avoid these timeouts and high latency issues?

Another thing how is it possible to use an SD card with this library? I tried using the ETHER_28J60.h library and it is working fine with its ether.print command.
Im having problem using the data I read on my SD on bfill.emit_p command.
What I do is
while (sd.available()){
c= sd.read();
kinda like this.
this code works fine on other libraries( changing bfill.emit_p with the print command of the  other library) but it is not working on ethercard.h library. How do I use my SD right on this library?

THX GUYS and more power to the community!

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131