Pages: [1]   Go Down
Author Topic: Anyone familiar with EtherCard.h or ENC28J60 Ethernet shield?  (Read 1366 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 () {
 
  Serial.begin(9600);
 
//Ethernet Debugging
 
ether.begin(BUFFER_SIZE, mymac, 10);

ether.staticSetup(myip);

//Ethernet Debugging Ends Here

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



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


void homepage(){
      bfill.emit_p(PSTR(
"<!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
             http_Unauthorized();
        }
    else {
        data += 5;
           
            if (data[0] == ' ') {
                // Return home page
                homepage();
            }
            else if (strncmp("?cmd=GV208 ", data, 10) == 0) {
                homepage();
                Serial.println("Recieve ON");
               digitalWrite(ledPin, HIGH);


            }
            else if (strncmp("?cmd=GV209 ", data, 10) == 0) {
              homepage();
                Serial.println("Recieve OFF");
                digitalWrite(ledPin, LOW);
            }
            else if (strncmp("?cmd=GV210 ", data, 10) == 0) {
                homepage();
                Serial.println("Recieve HALF");
                analogWrite(ledPin,150);
            }
            else if (strncmp("?cmd=GV211 ", data, 10) == 0) {
                homepage();
                Serial.println("Recieve HALF");
                analogWrite(ledPin,10);
            }
            else {
                // Page not found
                http_Unauthorized();
            }
        }
    ether.httpServerReply(bfill.position());
  }
}

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();
bfillemit_p(c);
}
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!
Logged

Pages: [1]   Go Up
Jump to: