ESP32-CAM Set Static IP and Streaming Address

Hi there,

I’ve been having a play with this ESP32-CAM and I’m quite impressed with such a cheap and small camera. I just wanted to share what changes I made to the File>>Examples>>ESP32>>Camera>>CameraWebServer example.

I changed the camera type to:

#define CAMERA_MODEL_AI_THINKER // Has PSRAM

and chose the ‘AI Thinker ESP32-Cam’ board.

I wanted a specific IP 192.168.0.151 so I added this bit of code under the SSID and PASSWORD values

// Set your Static IP address to 151
  IPAddress local_IP(192, 168, 0, 151);
  IPAddress gateway(192, 168, 0, 1);
  IPAddress subnet(255, 255, 255, 0);
  IPAddress primaryDNS(8, 8, 8, 8);   //optional
  IPAddress secondaryDNS(8, 8, 4, 4); //optional

I then added the following to before WiFi.begin(ssid, password); in the Setup

// Configures static IP address
  if (!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS)) {
    Serial.println("STA Failed to configure");
  }

This will now set the IP address of the camera to 192.168.0.151.

I then wanted to only view the stream without all the controls so I can embed the stream into a bespoke webpage. I eventually found that the stream uses port 81 so I just entered http://192.168.0.151:81/stream into the web browser and I had just the stream showing which was great but the default size of image was too small. If the image size is changed using the controls, it loses the setting when the camera is powered down. So looking through the code I noticed this:

if (config.pixel_format == PIXFORMAT_JPEG) {
    if (psramFound()) {
      config.jpeg_quality = 10;
      config.fb_count = 2;
      config.grab_mode = CAMERA_GRAB_LATEST;
    } else {
      // Limit the frame size when PSRAM is not available
      config.frame_size = FRAMESIZE_QVGA;
      config.fb_location = CAMERA_FB_IN_DRAM;
    }

I noticed that the QVGA(320x240) is hard coded as the default frame size (FRAMESIZE_QVGA). I wanted SVGA(800x600) so I changed one line to:

config.frame_size = FRAMESIZE_SVGA;

If you go to your camera page, mine being http://192.168.0.151, in the Resolution settings you can see a list of available sizes. I think you can just add the acronym instead of the actual frame size. i.e. FRAMESIZE_SVGA, FRAMESIZE_QVGA, FRAMESIZE_XGA etc

Well that’s all I’ve done so far and I thought I’d share some of what I’ve done with yourselves.

I am wondering if there isn’t another approach possible with the IP. Is it possible to either use or create a symbolic address like Camera.local or even better Camera-1.local so we can have multiple.

You could use DHCP instead of static IP by removing the static IP setup code. Add mDNS support in setup with MDNS.begin() and generate a unique hostname dynamically from each ESP32’s MAC address, for example "esp32cam_XXYY". This allows multiple devices to have distinct mDNS names automatically, accessible via URLs like http://esp32cam_XXYY.local:81/stream, making the code portable and scalable without manual changes per device.

The only challenge is discovering each device’s generated name. You can solve this by using a network scanner tool that lists mDNS devices, checking the serial output where the hostname is printed on startup, or implementing a simple HTTP endpoint on each device that returns its name for identification (or set the name for next boot).

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.