Created
October 17, 2012 06:56
-
-
Save biskandar/3904101 to your computer and use it in GitHub Desktop.
Request Counter with Arduino Uno + Ethernet Shield + LCD Shield 2012101702
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void loop() { | |
// verify if there is new client connected | |
EthernetClient client = server.available() ; | |
if ( !client ) return ; | |
// prepare for reading request data | |
boolean isBlankLine = true ; | |
// read and proces the client request data | |
while ( client.connected() ) { | |
if ( !client.available() ) break ; | |
// reading all the request characters | |
char ch = client.read() ; | |
// generate the response page | |
if ( ( ch == '\n' ) && ( isBlankLine ) ) { | |
createResponse( client , "OK" , "OK" ) ; | |
} | |
// validation of looking for the blank line | |
if ( ch == '\n' ) { | |
isBlankLine = true ; | |
continue ; | |
} | |
if ( ch == '\r' ) { | |
continue ; | |
} | |
isBlankLine = false ; | |
continue ; | |
} // while ( client.connected() ) | |
// client disconnected | |
delay( 10 ) ; | |
client.stop() ; | |
// increase and display the total requestor | |
totalRequestor = totalRequestor + 1 ; | |
lcdPrint( 0 , 1 , String( totalRequestor ) ) ; | |
} | |
void createResponse( EthernetClient client, char *statusCode , char *statusDesc ) { | |
if ( !client ) return ; | |
client.println( "HTTP/1.1 200 OK" ) ; | |
client.println( "Content-Type: application/json" ) ; | |
client.println( "Connection: close" ) ; | |
client.println() ; | |
client.println( statusCode ) ; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment