I have an Arduino Mega I am using as a simple web server. Right now the web page is two simple lines of text. There is an XBee radio attached to the unit to receive data from another unit. However, when the server unit is receiving data the web page will not start up. There's a switch on the shield to switch it into Micro
for the radio, or USB
. If I reset, or power on, the server unit with the switch in USB
mode it loads fine; then once the web page loads I can flip it on Micro
and it will refresh fine even while receiving data. However, if I try to power on the unit, or reset the unit, with the switch on Micro
it will not load the web page. Any ideas on why this is happening?
Schematic:
Server Unit: Ethernet shield with HanRun HR911105A 13/15 ethernet jac placed on Mega ADK. There is a Wireless Proto Shield with XBee Pro 538 radio placed on the ethernet shield.
Remote Unit: There is a Wireless Proto Shield with XBee Pro 538 radio placed on the Mega ADK.
setup()
:
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);//, gateway, mask);
server.begin();
}
loop()
:
void loop() {
// Listen for incoming clients
client = server.available();
if (client) {
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// Send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
client.println("Refresh: 5"); // refresh the page automatically every 5 sec
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.println("<br>");
client.println("<BODY BGCOLOR=powderblue>");
client.println("<center>");
client.println("<b>My WebPage</b>");
client.println("<br>");
client.println("<b>Web Server and Radio Receiver </b>");
client.println("<br>");
client.println("version November 30, 2016");
client.println("<br>");
client.println("</center>");
client.println("</body>");
client.println("</html>");
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
} else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
}
setup()
andloop()
functions that will manage bothMicro
and 'USB` links ? – J. Piquard Dec 1 '16 at 21:10WebServer.ino
, you have assigned inloop()
theclient = server.available();
with certainlyEthernetClient client
declared beforesetup()
meaning that another client has been created before. Try to declareEthernetClient client = server.available();
inside theloop()
. – J. Piquard Dec 1 '16 at 22:22Serial.begin(9600)
to be the last line ofsetup()
and now the web page loads when reset while receiving data, but it still won't load while receiving data when first powered on – tpm900 Dec 2 '16 at 13:31