
ioshield-a, ioshield-k
- Web Server & LED Blink
A simple web server that shows and control the value of the LED Digital…
gr_WebLED.cpp - Web Server & LED Blink
Configuration of IP address
IPAddress ip(192,168,1,177);
Initalize the Port (port80 is default for HTTP)
EthernetServer server(80);
Parsing of HTTP GET Message
When web-page address is http://192.168.1.177/G0 to on the Green LEN,
the received HTTP GET Message is as below,
GET /G0 HTTP/1.1
Accept: text/html, application/xhtml+xml,....
So, 5th~7th data are parsed to control RGB LEDs.
//5th~7th data of HTTP GET Message is parsed as parse_arr
parse_arr[0] = '/'
parse_arr[1] = 'G'
parse_arr[2] = '0'
Contorl RGB LEDs as data pased from HTTP GET Message
if(parse_arr[0] == '/'){
switch(parse_arr[1]){
case('R') :
// http://192.168.1.177:R0 => Red LED OFF
if(parse_arr[2] == '0'){
digitalWrite(led_red, HIGH);
// http://192.168.1.177:R1 => Red LED ON
}else if(parse_arr[2] == '1'){
digitalWrite(led_red, LOW);
}
break;
...
Send a standard http response
Check current LED status as digitalRead() and Send http respoonse inclued the LED status.
int sensorReading = digitalRead(led_red);
client.print("digitalRead(LED_RED)");//client.print(led_red);
client.print(" is ");
client.print(sensorReading);
client.println("
");
...
Address Lists
http://192.168.1.177/G0 => Green OFF
http://192.168.1.177/G1 => Green ON
http://192.168.1.177/R0 => RED OFF
http://192.168.1.177/R1 => RED ON
http://192.168.1.177/B0 => BLUE OFF
http://192.168.1.177/B1 => BLUE ON
http://192.168.1.177/B3 => BLINK START
http://192.168.1.177/B3 => BLINK STOP