Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <Ethernet.h>
- #define MaxHeaderLength 47 //maximum length of http header required
- #include <Wire.h>
- #include <Adafruit_MCP23017.h>
- #include <Adafruit_RGBLCDShield.h>
- Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();
- byte mac[] = {
- 0x90, 0xA2, 0xDA, 0x0D, 0x35, 0x70 }; //physical mac address
- byte ip[] = {
- 10,0,0, 26 };
- byte gateway[] = {
- 10,0,0, 1 };
- byte subnet[] = {
- 255, 255, 255, 0 };
- EthernetServer server(76); //arduino server port
- String HttpHeader = String(MaxHeaderLength);
- String displayText1 = "1";
- String displayText2 = "2";
- void setup(){
- //enable serial monitor
- Serial.begin(9600);
- //start Ethernet
- Ethernet.begin(mac, ip, gateway, subnet);
- //initialize variable
- HttpHeader="";
- displayText1="";
- displayText2="";
- lcd.begin(16,2);
- lcd.print("SystemOnline");
- Serial.print("System Online");
- }
- void loop(){
- // Create a client connection
- EthernetClient client = server.available();
- if (client) {
- while (client.connected()) {
- if (client.available()) {
- char c = client.read();
- //read MaxHeaderLength number of characters in the HTTP header
- //discard the rest until \n
- if (HttpHeader.length() < MaxHeaderLength){
- //store characters to string
- HttpHeader = HttpHeader + c;
- HttpHeader.replace("HTTP/1.1"," ");
- HttpHeader.replace("+", " ");
- if (HttpHeader.startsWith("GET /?text")){
- displayText1 = HttpHeader.substring(11,27);
- displayText2 = HttpHeader.substring(28,44);
- }
- }
- lcd.clear();
- lcd.print(displayText1);
- lcd.setCursor(1,1);
- lcd.print(displayText2);
- //if HTTP request has ended
- if (c == '\n') {
- // show the string on the monitor
- Serial.println(HttpHeader);
- // start of web page
- client.println("HTTP/1.1 200 OK");
- client.println("Content-Type: text/html");
- client.println("<html><head></head><body>");
- client.println();
- client.print("<form method=get>");
- client.print("Enter in a 16 character string");
- client.print("<input type='text' name=text><br>");
- client.print("<input type=submit value=submit></form>");
- client.print("</body></html>");
- //clearing string for next read
- HttpHeader="";
- //stopping client
- client.stop();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement