WIFI - Ip Range

Hello

I would like to know if there is a way, in a WiFi connection, to limit a range of IPs that the arduino can pick up.

For example, I would like to get a Local IP address from 192.168.0.150 to 192.168.0.250.

I searched for this question but couldn't find it.

My code is still pretty simple:

#include <WiFi.h>
#include <WiFiClient.h>
#include <WebServer.h>

WiFiClient wifiClient;

const char* ssid = "Wifi-3AA3";
const char* password = "c152f5378aa3";

WebServer server(80);

void getHelloWord() {
  server.send(200, "text/json", "{\"name\": \"Hello world\"}");
}

// Define routing
void restServerRouting() {
  server.on("/", HTTP_GET, []() {
    server.send(200, F("text/html"),
                F("Welcome to the REST Web Server"));
  });
  server.on(F("/helloWorld"), HTTP_GET, getHelloWord);
}

// Manage not found URL
void handleNotFound() {
  String message = "File Not Found\n\n";
  message += "URI: ";
  message += server.uri();
  message += "\nMethod: ";
  message += (server.method() == HTTP_GET) ? "GET" : "POST";
  message += "\nArguments: ";
  message += server.args();
  message += "\n";
  for (uint8_t i = 0; i < server.args(); i++) {
    message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
  }
  server.send(404, "text/plain", message);
}


void setup() {
  Serial.begin(115200);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  Serial.println("");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.print(WiFi.localIP());
  // Set server routing
  restServerRouting();
  // Set not found response
  server.onNotFound(handleNotFound);
  // Start server
  server.begin();

}

void loop() {
  server.handleClient();

}

Thanks!

You'd do that via the WiFi Router's configuration web page, not in the Arduino.

But the arduino code has no way to do this?

The router controls the DHCP process. Perhaps the Arduino can ask for a specific IP address if available. It does beg the question of WHY you want to do this?

I was just thinking of a way to limit the Arduino, to make the Arduinos only connect in a certain range of IPs. But it was just a question.

I know that it is possible to determine a fixed IP on it, I just wanted to know if, if it is dynamic, I can limit an range.

In the DHCP server, ‘map’ a specific IP address to the Arduino’s network interface (the MAC address), then, even when using DHCP, it will always get that particular address.

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