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!