Created
October 16, 2012 09:03
-
-
Save biskandar/3898180 to your computer and use it in GitHub Desktop.
Reading Arduino's Analog Pins with JSON Protocol by using WiFi Shield 2012101606
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 processHttpClient() { | |
// verify if there is new client connected | |
WiFiClient client = server.available() ; | |
if ( !client ) return ; | |
Serial.println( "Client connected" ) ; | |
// prepare for reading request data | |
boolean isBlankLine = true ; | |
// read and proces the client request data | |
while ( client.connected() ) { | |
if ( !client.available() ) break ; | |
// echoing for debug purpose | |
char ch = client.read() ; | |
// Serial.write( ch ) ; | |
// generate the response page | |
if ( ( ch == '\n' ) && ( isBlankLine ) ) { | |
client.println( "HTTP/1.1 200 OK" ) ; | |
client.println( "Content-Type: text/html" ) ; | |
client.println( "Connection: close" ) ; | |
client.println() ; | |
client.println( aJson.print( jsonAnalogs() ) ) ; | |
} | |
// 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() ; | |
Serial.println( "Client disconnected" ) ; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment