1 Reply Latest reply on Apr 24, 2014 5:43 PM by JPMontero_Intel

    HTML to LCD

    khairol21

      hi. im try to make html to lcd like this code [C] Arduino: HTML to LCD v1.1 - Pastebin.com . i have modified the code so that it can be use in intel galileo. when i upload the code, the webpage will be served. however if the submit button entered it will served an error. can someone help me..thanks., this is my code

       

       

      
      
      #include <SPI.h>
      #include <Ethernet.h>
      #include <string.h>
      #include <LiquidCrystal.h>
      
      
      
      
      byte mac[] = { 0x00, 0x13, 0x20, 0xFD, 0xF6, 0x73 };
      IPAddress ip(10, 207, 146, 100);
      LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
      
      
      
      
      EthernetServer server(80);
      
      
      String line1 = "              ";
      String line2 = "              ";
      
      
      
      
      
      
      void HtmlHeader(EthernetClient client)
      {
        client.println("HTTP/1.1 200 OK");
        client.println("Content-Type:text/html");
        client.println();
        client.println("<HTML>\n<HEAD>");
        client.println("<TITLE>Galileo HTML to LCD</TITLE>");
        client.println("</HEAD><BODY>");
      }
      
      
      void HtmlFooter(EthernetClient client)
      {
        client.println("</BODY></HTML>");
      }
      
      
      void ParseHttpHeader(EthernetClient &client) {
          char c;
          int i = 0;    //An integer use to limit the size of rawUrlText (prevents crashing due to running out of memory)
          String rawUrlText = "";
          String result;
      
          // Skip through until we hit a question mark (first one)
          while((c = client.read()) != '?' && client.available()) {
            // Debug - print data
            Serial.print(c);
          }
         
          // Are we here for a question mark or did we run out of data?
          if(client.available() > 2) {
      
            // Read the data and add it to our unmodified string rawURLText!
            // the incrementer limits the input to about 1 line of plain text and 1/2 line of symbols, more causes line2 to truncate
            while((c = client.read()) != ' ' && client.available() && i < 55) {
                result = rawUrlText;
                result += c;
                Serial.print(result);
                i++;
            }
           
            htmlToHuman(rawUrlText);            // Make it readable
            line1.setCharAt(line1.lastIndexOf('0'), ' '); // the lcd prints the 0's in the null terminator, so we remove them
            line2.setCharAt(line2.lastIndexOf('0'), ' '); //This has been revised to prevent remove of legit 0's
            lcd.clear();
            lcd.setCursor(0,0);                 // set cursor to column 0, row 0 (the first row), and print
            lcd.print(line1);
            lcd.setCursor(0,1);                 // set cursor to column 0, row 1 (the second row), and print
            lcd.print(line2);
          }  
        return;
      }
      
      
      void htmlToHuman(String URLstring) {
      
          int indexOfDelim = 0;  //This variable stores the location of our delimiter so we can find where line1 ends and line2 begins
         
          // The following array stores a list of ugly html codes, and the special charaters they represent (for changing them back)
          const String CHAR_CONVERSIONS[29][2] = {{"+"," "},{"%40","@"},{"%23","#"},{"%24","$"},{"%2B","+"},{"%21","!"},{"%7E","~"},
                                                  {"%3A",":"},{"%3B",";"},{"%2C",","},{"%3F","?"},{"%2F","/"},{"%7C","|"},{"%5E","^"},
                                                  {"%5C","\\"},{"%7B","{"},{"%7D","}"},{"%5B","["},{"%5D","]"},{"%3C","<"},{"%3E",">"},
                                                  {"%28","("},{"%29",")"},{"%27","'"},{"%22","\""},{"%3F","?"},{"%26","&"},{"%3D","="},
                                                  {"%25","%"}};
         
          URLstring.replace("L1=","");     // remove the unecessary field variable names
          URLstring.replace("&L2=","`");   // and turn this one into our delimiter character ` (The one on the ~ key)
         
          //A for loop that replaces all the html codes with the right symbols
          for (int i=0 ; i < 29; i++) {
            URLstring.replace(CHAR_CONVERSIONS[i][0],CHAR_CONVERSIONS[i][1]);
          }
         
          indexOfDelim = URLstring.indexOf("`");       // find the index of that delimiter
         
          line1 = URLstring.substring(0,indexOfDelim); // set line1 and line 2 using that knowlege
          line1 += NULL;                               // but add a null terminator to each to avoid some odd bugs
          line2 = URLstring.substring(indexOfDelim+1,URLstring.length());
          line2 += NULL;
         
          return;
      }
      
      
      void WebServerSetup()
      {
        Ethernet.begin(mac, ip);
        server.begin();
      }
      
      
      void WebServerLoop()
      {
        EthernetClient client = server.available();
        boolean bPendingHttpResponse = false;
        boolean bPreventSecondParse = false;
        char c;
        
        if(client)
        {
         while(client.connected())
         {
           if (client.available() && !bPreventSecondParse) 
           {
             bPendingHttpResponse = true;
             bPreventSecondParse = true;
             Serial.println("Connected!");
             ParseHttpHeader(client);
           }
           
           else {
             if(bPendingHttpResponse)
             {
               bPendingHttpResponse = false;
               bPreventSecondParse = false;
               
               HtmlHeader(client);
               
               client.println("<H2>Currently Displayed: </H2>");
               client.println("<b>Line 1: </b>");
               client.print(line1);
               client.println("<br/>");
               client.println("<b>Line 2: </b>");
               client.print(line2);
               client.println("<br/>");
               client.println("Change it");
               client.println("<form action =\"/?\" method=get>");
               client.println("<b>Line 1: </b><input type=\"text\" name=\"L1\" maxlengh=\"16\" size=\"16\" /><br />");
               client.println("<b>Line 2: </b><input type=\"text\" name=\"L2\" maxlengh=\"16\" size=\"16\" /><br />");
               client.println("<input type=\"submit\" value=\"Submit\" /> </form>");
               
               HtmlFooter(client);
               delay(1);
               client.stop();
             }
           }
         }
        }
      }
      
      
      void setup() {
        
        lcd.init(1,12,255,11,5,4,3,2,0,0,0,0);
        Serial.begin(9600);
        lcd.begin(16,2);
        lcd.clear();
        WebServerSetup();
      
      
      }
      
      
      void loop() {
      
        WebServerLoop();
        
      }
      

       

      webpae