3 Replies Latest reply on Apr 24, 2017 6:26 PM by Intel Corporation

    Use Edsion as a server to print a webpage

    doubleguan

      Dear developers,

       

      I try to use Intel Edison as a server to show a webpage, here are my codes:

       

      #include <WiFi.h>

      int status = WL_IDLE_STATUS;  //to save the connection conditon
      WiFiServer server(8080);     //define a server object,port 8080

      void setup() {
        Serial.begin(9600);

        while (status != WL_CONNECTED) {
          Serial.print("Attempting to connect to Network named: ");
          Serial.println("FAST_1001");
          status = WiFi.begin("FAST_1001", "guanlele");
          delay(10000);     //connect every 10 secconds
        }

          Serial.print("SSID: ");
          Serial.println(WiFi.SSID());
          IPAddress ip = WiFi.localIP();
          Serial.print("IP Address: ");
          Serial.println(ip);
          server.begin();    //start and listen to 8080

      }

       

      void loop() {
        WiFiClient client = server.available();  //listen if a client ask for service

        if(client)
        {
          Serial.println("new Client");
          String currentLine = "";         //to store the asked information
          while (client.connected()){
            if (client.available())
            {
              char c = client.read();
              Serial.write(c);

              if(c == '\n'){
                if(currentLine.length() == 0){
                  server.println("<html>");
                  server.println("<head>");
                  server.println("<title>Intel Edison</title>");
                  server.println("</head>");
                  server.println("<body>");
                  server.println("<h1>HTML TEST</h1>");
                  server.println("<h2>Edison</h2>");
                  server.println("<img src=\"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1492625839609&di=eebffbc30e08cf6bc51bbc4cc83eee22&imgtype=0&src=http%3A%2F%2Fd.ifengimg.com%2Fmw604%2Fy3.ifengimg.com%2Fifengimcp%2Fpic%2F20151112%2Ffc1cee98b0359d30e720_size220_w440_h409.jpg\"/>");
                  server.println("</body>");
                  server.println("</html>");

                  server.println();               //to end the response
                  break;

                  }
                else {
                  currentLine = "";
                }
              }
                else if ( c != '\r') {
                  currentLine += c;
                }
              }
            }
            client.stop();
            Serial.println("client disconnected");
          }
        }

       

      After compling my codes, Serial shows that the ip address distributed to my Intel Edison is 192.168.1.102, but after I entered "192.168.1.102:8080" to my IE url, it did not show the webpage I designed but jumped directly to Being telling me that the address could not be found.

       

      Could you please tell me what I can do to show my webpage?

       

      Regards,

      Guan Guan