Go Down

Topic: Arduino Due Scheduler with Web Server (Read 199 times) previous topic - next topic

steinvb12

Jan 02, 2016, 02:38 am Last Edit: Jan 02, 2016, 03:18 am by steinvb12
I am currently using an Arduino Due with a RFID card reader and a Wifly used as a web server. Basically the RFID cards are scanned, and the web server displays all the cards that were scanned in a certain period.

I am using the Scheduler library with the RFID reader code in the main loop and the web server code in...
Scheduler.startLoop(webpage);.

The program works fine. RFID cards are scanned, and when the web request is sent from the browser, the cards are displayed.

The problem is the webserver code (below) takes 3-4 seconds to complete. If a card is scanned during that time it is serving the web page, the card is not scanned and is missed.

Can I use the scheduler to eliminate these missed scans? Is there another way?


Code: [Select]
void setup() {
Scheduler.startLoop(webpage);
}

void loop() {
  IdentifyRFIDCard();
}

void webpage() {
      WiFlyClient client = server.available();
  if (client) {
    // an http request ends with a blank line
    boolean current_line_is_blank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        // if we've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so we can send a reply
        if (c == '\n' && current_line_is_blank) {
          // send a standard http response header
          
          client.println(F("HTTP/1.1 200 OK"));
          client.println(F("Content-Type: text/html"));
          client.println();
          client.println(F("<!DOCTYPE html>"));
          client.println(F("<html>"));
          client.println(F("<body>"));

          client.println(card1);
          client.println(card2);
          client.println(card3);
                              
          break;
        }
        if (c == '\n') {
          // we're starting a new line
          current_line_is_blank = true;
        } else if (c != '\r') {
          // we've gotten a character on the current line
          current_line_is_blank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(200);
    client.stop();
  }

yield();
}

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!

Arduino
via Egeo 16
Torino, 10131
Italy