So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By M3-L7
#74662 Hello guys, Im wondering how to change the IP of AP from 192, 168, 4, 1 to whatever I want i would welcome every suggestion of what to change in my code


#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <WiFiUdp.h>
const char *ssid = "M3-L7";
const char *password = "Lukas";
ESP8266WebServer server(80);

WiFiUDP Udp;
unsigned int localUdpPort = 8899; // local port to listen on
char incomingPacket[255]; // buffer for incoming packets
char replyPacket[] = "Hi there! Got the message :-)"; // a reply string to send back

void handleRoot()
{
server.send(200, "text/html", "<h1>You are connected</h1>");
}

void setup() {
delay(1000);
Serial.begin(115200);
Serial.println();
Serial.print("Configuring access point...");
WiFi.softAP(ssid, password);


IPAddress Ip(192, 168, 4, 1);
IPAddress NMask(10,10,100,254);
WiFi.softAPConfig(Ip, Ip, NMask);
IPAddress myIP = WiFi.softAPIP();


Serial.print("AP IP address: ");
Serial.println(myIP);
server.on("/", handleRoot);
server.begin();
Serial.println("HTTP server started");

Udp.begin(localUdpPort);
Serial.printf("Now listening at IP %s, UDP port %d\n", WiFi.softAPIP().toString().c_str(), localUdpPort);
}
void loop() {
server.handleClient();
int packetSize = Udp.parsePacket();
if (packetSize)
{
// receive incoming UDP packets
Serial.printf("Received %d bytes from %s, port %d\n", packetSize, Udp.remoteIP().toString().c_str(), Udp.remotePort());
int len = Udp.read(incomingPacket, 255);
if (len > 0)
{
incomingPacket[len] = 0;
}
Serial.printf("UDP packet contents: %s\n", incomingPacket);

// send back a reply, to the IP address and port we got the packet from
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Udp.write(replyPacket);
Udp.endPacket();
Serial.println("MAM TO");
}
}