Hello
Can anyone tell or show me how I can see the ip address on an esp01.
Thank you
Oliver
how do you configure your WiFi ?
Which IP address do you want to see, The Access Point IP address is 192.168.4.1
If you connect it in Station mode you can opt to assign a static IP address but the subnet mask will need to match.
Usually you get it printed over Serial
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
const char *ssid = "XXX";
const char *password = "xxxxxxxxr";
const char *apname = "esp8266";
const char *appass = "password"; // minimum length 8 characters
ESP8266WebServer server(80);
const int ledpin = 2; // I'm running this on an ESP-01
// i have a led connected to this active LOW
// i can't use the internal (pin 1) for the use of Serial
uint8_t ledstatus = 0; // this is keeping track of the state (of our statemachine)
const char // like this these lines are statically declared and const, so we can't change them at all
*pageheader = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">",
*htmlhead = "<html><head><title>ESPwebserver</title><meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" ></head>",
*bodystyle = "<body style=\"color: wheat; background-color: teal; font-size: 12pt; font-family: sans-serif;\">",
*accessIP = "http://192.168.4.1",
*htmlclose = "</body></html>";
String webIP;
void setup() {
webIP.reserve(30); // prevent fragments
digitalWrite(ledpin, HIGH);
pinMode(ledpin, OUTPUT);
Serial.begin(115200);
WiFi.softAP(apname, appass); // start AP mode
webIP = accessIP;
Serial.print("Started Access Point \"");
Serial.print(apname);
Serial.println("\"");
Serial.print("With password \"");
Serial.print(appass);
Serial.println("\"");
WiFi.begin(ssid, password); // attempt starting STA mode
Serial.println("Attempting to start Station mode");
uint32_t moment = millis();
while ((WiFi.status() != WL_CONNECTED) && (millis() < moment + 8000)) {
delay(500);
Serial.print(".");
}
Serial.println("");
if (WiFi.status() == WL_CONNECTED) {
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
if (MDNS.begin("esp8266")) { // type esp8266.local/ in your browser
Serial.println("MDNS responder started, type esp8266.local/ in your browser");
}
webIP = StationIP();
}
else if (WiFi.status() == WL_CONNECT_FAILED) {
Serial.print("Connecting to ");
Serial.print(ssid);
Serial.println(" Unsuccessful.");
}
else if (WiFi.status() == WL_NO_SSID_AVAIL) {
Serial.print("Network ");
Serial.print(ssid);
Serial.println(" not available.");
}
WiFi.reconnect(); // reconnect AP after attempting to connect STA
server.on("/", handleRoot);
server.begin();
Serial.println("HTTP server started");
}
void loop() {
server.handleClient();
checkLedStatus();
}
void checkLedStatus() { // our statemachine
switch (ledstatus) {
case 0: {
digitalWrite(ledpin, HIGH);
return;
}
case 1: {
digitalWrite(ledpin, LOW);
return;
}
case 2: {
if (ledBlink(500)) ; // here the return value (of ledBlink() ) gets discarded
return;
}
case 3: {
modulateLed();
return;
}
}
}
void modulateLed() {
static uint16_t ms = 100;
static bool increase = true;
if (!ledBlink(ms)) return;
if (ms > 250) increase = false;
if (ms < 20) increase = true;
if (increase) ms = (ms * 10) / 9;
else ms = (ms * 9) / 10;
}
bool ledBlink(uint32_t wait) {
static bool pinstate = false;
static uint32_t moment = millis();
if (millis() > moment + wait) {
pinstate = !pinstate;
moment = millis();
if (pinstate) digitalWrite(ledpin, LOW);
else digitalWrite(ledpin, HIGH);
return pinstate; // if pinstate is true and the pinstate has changed, the modulator will change speed
}
return false;
}
void handleRoot() {
String ledstatusupdate;
if (server.hasArg("led")) {
if (server.arg("led") == "off") {
ledstatus = 0;
ledstatusupdate = "The LED has been turned Off<br>";
}
else if (server.arg("led") == "on") {
ledstatus = 1;
ledstatusupdate = "The LED has been turned On<br>";
}
else if (server.arg("led") == "blink") {
ledstatus = 2;
ledstatusupdate = "The LED has been set to Blink<br>";
}
else if (server.arg("led") == "modulate") {
ledstatus = 3;
ledstatusupdate = "The LED has been set to Modulate<br>";
}
}
String s = "";
s += pageheader;
s += htmlhead;
s += bodystyle;
s += "<h1>Welcome to ESP webserver</h1><p>From here you can control your LED making it blink or just turn on or off. ";
s += "</p>";
s += ledstatusupdate;
s += "<br>";
s += "<form action=\"";
s += webIP;
s += "\" method=\"get\" name=\"button\">";
s += "<input type=\"hidden\" name=\"led\" value=\"on\">"; // the hidden parameter gets included
s += "<input type=\"submit\" value=\" LED ON \"></form><br>"; // the button simply submits the form
s += "<form action=\"";
s += webIP;
s += "\" method=\"get\" name=\"button\">";
s += "<input type=\"hidden\" name=\"led\" value=\"off\">";
s += "<input type=\"submit\" value=\" LED OFF\"></form><br>";
s += "<form action=\"";
s += webIP;
s += "\" method=\"get\" name=\"button\">";
s += "<input type=\"hidden\" name=\"led\" value=\"blink\">";
s += "<input type=\"submit\" value=\" BLINK \"></form><br>";
s += "<form action=\"";
s += webIP;
s += "\" method=\"get\" name=\"button\">";
s += "<input type=\"hidden\" name=\"led\" value=\"modulate\">";
s += "<input type=\"submit\" value=\"MODULATE\"></form><br>";
s += htmlclose;
yield(); // not stricktly neccesary, though the String class can be slow
server.send(200, "text/html", s); //Send web page
}
String StationIP() {
String stationIP = "http://";
stationIP += WiFi.localIP().toString();
return stationIP;
}
if you connect to a network you get it so
// attempt to connect to WiFi network
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network
status = WiFi.begin(ssid, pass);
}
IPAddress ip = WiFi.localIP();
ESP01 is very often used in AT command mode. I guess that's the question but needs clarification by the OP (AT+CIPSTA? or AT+CIPAP?)
I forgot about that, questionable if that still belongs on this forum in that way though.
well usually there is an Arduino in front of the ESP and you would have to issue Serial commands and listen to / parse the answer... So yes it's OK
(only if that's the case)
Thank you it worked
Ok, eh, just to clarify, what worked ?
Yes i know, it is and i also think so, I will keep assuming the other thing though if that's ok ?
I have the ip address
it would help future viewers if you were to share details about your question and what you did to get the answer
Ok so let me just clarify the request.
- Are you using AT-commands or not ?
- are you using the esp-01 as an access point or do you connect it to a network (Station mode) or both.
- Was it 192.168.4.1
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.