Skip to content

#158 Re-Calculate URLs on WiFi reconnect #159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 22 additions & 15 deletions esp32-cam-webserver.ino
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,26 @@ void printLocalTime(bool extraData=false) {
}
}

void calcURLs() {
// Set the URL's
#if defined(URL_HOSTNAME)
if (httpPort != 80) {
sprintf(httpURL, "http://%s:%d/", URL_HOSTNAME, httpPort);
} else {
sprintf(httpURL, "http://%s/", URL_HOSTNAME);
}
sprintf(streamURL, "http://%s:%d/", URL_HOSTNAME, streamPort);
#else
Serial.println("Setting httpURL");
if (httpPort != 80) {
sprintf(httpURL, "http://%d.%d.%d.%d:%d/", ip[0], ip[1], ip[2], ip[3], httpPort);
} else {
sprintf(httpURL, "http://%d.%d.%d.%d/", ip[0], ip[1], ip[2], ip[3]);
}
sprintf(streamURL, "http://%d.%d.%d.%d:%d/", ip[0], ip[1], ip[2], ip[3], streamPort);
#endif
}

void WifiSetup() {
// Feedback that we are now attempting to connect
flashLED(300);
Expand Down Expand Up @@ -389,6 +409,7 @@ void WifiSetup() {
Serial.printf("IP address: %d.%d.%d.%d\r\n",ip[0],ip[1],ip[2],ip[3]);
Serial.printf("Netmask : %d.%d.%d.%d\r\n",net[0],net[1],net[2],net[3]);
Serial.printf("Gateway : %d.%d.%d.%d\r\n",gw[0],gw[1],gw[2],gw[3]);
calcURLs();
// Flash the LED to show we are connected
for (int i = 0; i < 5; i++) {
flashLED(50);
Expand Down Expand Up @@ -434,6 +455,7 @@ void WifiSetup() {
gw = WiFi.gatewayIP();
strcpy(apName, stationList[0].ssid);
Serial.printf("IP address: %d.%d.%d.%d\r\n",ip[0],ip[1],ip[2],ip[3]);
calcURLs();
// Flash the LED to show we are connected
for (int i = 0; i < 5; i++) {
flashLED(150);
Expand Down Expand Up @@ -693,21 +715,6 @@ void setup() {
// Now we have a network we can start the two http handlers for the UI and Stream.
startCameraServer(httpPort, streamPort);

#if defined(URL_HOSTNAME)
if (httpPort != 80) {
sprintf(httpURL, "http://%s:%d/", URL_HOSTNAME, httpPort);
} else {
sprintf(httpURL, "http://%s/", URL_HOSTNAME);
}
sprintf(streamURL, "http://%s:%d/", URL_HOSTNAME, streamPort);
#else
if (httpPort != 80) {
sprintf(httpURL, "http://%d.%d.%d.%d:%d/", ip[0], ip[1], ip[2], ip[3], httpPort);
} else {
sprintf(httpURL, "http://%d.%d.%d.%d/", ip[0], ip[1], ip[2], ip[3]);
}
sprintf(streamURL, "http://%d.%d.%d.%d:%d/", ip[0], ip[1], ip[2], ip[3], streamPort);
#endif
if (critERR.length() == 0) {
Serial.printf("\r\nCamera Ready!\r\nUse '%s' to connect\r\n", httpURL);
Serial.printf("Stream viewer available at '%sview'\r\n", streamURL);
Expand Down