Server Products
Data Center Products including boards, integrated systems, Intel® Xeon® Processors, RAID Storage; and Intel® Xeon® Processors
4397 Discussions

Use Edsion as a server to print a webpage

GGuan
Beginner
1,021 Views

Dear developers,

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

# include

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("");

 

server.println("");

 

server.println("Intel Edison");

 

server.println("");

 

server.println("");

 

server.println("HTML TEST");

 

server.println("Edison");

 

server.println("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1492625839609&di=eebffbc30e08cf6...\"/>");

 

server.println("");

 

server.println("");

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

0 Kudos
3 Replies
KMill10
Valued Contributor II
144 Views

From the reference for WiFiServer.available: (which is https://www.arduino.cc/en/Reference/WiFiServerAvailable here)

"if no Client has data available for reading, this object will evaluate to false in an if-statement"

Therefore I think you need to do the server.available() inside a loop, so that it will keep looping until a client (web browser) connects.

GGuan
Beginner
144 Views

Hello,

Thank you so much for your reply!

I have already include server.avaliable() inside a loop by writing

void loop() {

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

//other codes

}

Could you please tell me is there anything wrong with these part of codes?

Regards,

Guan

idata
Community Manager
144 Views

Hello Guan,

 

 

I was wondering if you still need assistance in this case. Could you please share the current state of your project, and tell me if you are using the latest firmware version?

 

 

Do you experience the same issue with the default WiFiWebServer example from the Arduino IDE?

 

 

If you have any other question or update, don't hesitate to contact us.

 

 

Regards,

 

Andres V.
Reply