Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ethercard web server #71

Closed
masterraf opened this issue Feb 4, 2013 · 2 comments
Closed

Ethercard web server #71

masterraf opened this issue Feb 4, 2013 · 2 comments

Comments

@masterraf
Copy link

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(
"<title>Ethernet Controller</title>"
"



IP Based Automated
Load Carrier with RFID Security
"
"



"
""
""
""
"
Room Destination
"
"


Mobot is

"
));
}
void http_Unauthorized(){
bfill.emit_p(PSTR("HTTP/1.0 401 Unauthorized\r\n"
"Content-Type: text/html\r\n\r\n"
"

401 Unauthorized

"
));
}

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?

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!

@fredycpu
Copy link
Contributor

you can look on my code that can send multiple packets, it's worksbut has limitations
issue #68
i wish you a good day
fred

@solarkennedy
Copy link
Contributor

This can be closed I believe. #68 is closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants