Hello.
First sorry for my poor English.
I would like to change IP addresses in my arduino sketch. I use ESP8266WiFi.h to create a server.
It always is 192.168.4.1
If you could please help me.
Thanks.
Something like this is appropriate: Change IP 192.168.4.1 SOFT AP ?? · Issue #2208 · esp8266/Arduino · GitHub
Ray
Ray's Projects
Yes.
That is working now.
So much thank you.
sorry I have another problem.
When I define Ip in that way, My client doesn't connect to my website.
This is my code.
#include <ESP8266WiFi.h>
String WiFiName = "Esp8266AHF";
const char WiFiAPPSK[] = "1020304050";
WiFiServer server(80);//s
const char* ssid = "ABCDEF";//c
const char* password = "3335H5846";//c
const char* host = "mywebsite.com";//c
IPAddress Ip(192, 168, 1,5);;
IPAddress NMask(255, 255, 255, 0);
void setup()
{
Serial.begin(115200);
WiFi.mode(WIFI_AP_STA); // server and client
setupWiFi();//s
server.begin();//s
WiFi.softAPConfig(Ip, Ip, NMask);
WiFi.begin(ssid, password);//c
}
void loop()
{
myserver();
myclient();
}
void myserver()
{
WiFiClient client = server.available();
if (client)
{
String req = client.readStringUntil('\r');
String response = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\nOK\n";
client.flush();
client.print(response);
}
}
void myclient()
{
WiFiClient client;
const int httpPort = 80;
if (client.connect(host, httpPort))
{
String url = "/abc/index.php/";
client.print(String("GET ") + url + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Connection: close\r\n\r\n");
unsigned long timeout = millis();
while (client.available() == 0)
{
if (millis() - timeout > 3000)
{
Serial.println(">>> Client Timeout !");
client.stop();
}
}
while(client.available())
{
String line = client.readStringUntil('\r');
Serial.print(line);
}
client.stop();
}
}
void setupWiFi()
{
// Do a little work to get a unique-ish name. Append the
// last two bytes of the MAC (HEX'd) to "Thing-":
uint8_t mac[WL_MAC_ADDR_LENGTH];
WiFi.softAPmacAddress(mac);
String macID = String(mac[WL_MAC_ADDR_LENGTH - 2], HEX) +
String(mac[WL_MAC_ADDR_LENGTH - 1], HEX);
macID.toUpperCase();
char AP_NameChar[WiFiName.length() + 1];
memset(AP_NameChar, 0, WiFiName.length() + 1);
for (int i=0; i<WiFiName.length(); i++)
AP_NameChar[i] = WiFiName.charAt(i);
WiFi.softAP(AP_NameChar, WiFiAPPSK);
}
When I don't use "WiFi.softAPConfig(Ip, Ip, NMask);" , everything is OK, But Ip still is 192.168.4.1 .
Very thank you
I found it.
When I got connected to router, DHCP defines my IP.So I changed my IP to out of router IP ranges to 192.168.10.1 and everything went well.
Your router has a setting for each device, to pick whether you want it to get assigned an IP from the pool of alotted numbers or you can make it static/fixed.
If you didn't specifically choose fixed, but just chose the one it already had, it may change next time you reset your router.