Skip to content

Instantly share code, notes, and snippets.

@futechiot
Last active April 17, 2025 01:33
Show Gist options
  • Save futechiot/4e4244e6b5c8db17b44c6792d14b01eb to your computer and use it in GitHub Desktop.
Save futechiot/4e4244e6b5c8db17b44c6792d14b01eb to your computer and use it in GitHub Desktop.
ESP8266 in Both Mode AccesssPoint and Station mode, you can connect with esp8266 using your mobile and your ESP8266 connects to your another wifi connection(Home router,) both mode work simultaneously
/*
OUTCOME: Esp8266 Hotspot as well as Connecting your Esp8266 to any Wifi NETWORK(Mobile Hotspot,Home Route)
Author: Ankit Rana (Futechiot)
Board Used: Wemos d1 mini, Wemos d1 mini pro, Node MCU
Website: www.futechiot.com
GitHub: https://github.com/futechiot
Software:
Advanced IP Scanner: https://www.advanced-ip-scanner.com/
-->download and open this application
-->Scan for networks, make sure your PC and board are connected in same network
-->search for obtained IP, see in manufracturer "ESPRESSIF"
--> Scan for wifi in your mobile or laptop you will see your hotspot name in scanned network
*/
#include <ESP8266WiFi.h> //Wifi library of esp8266 to access HARDWARRE APIS and othe functionality
/* Set these to your Wifi credentials. */
const char*Wifi_ssid = "INCORE_AP_IoT"; // SSID of your Router OR mobile hotspot
const char*Wifi_password = "Welcome@Incore"; // PASSWORD of your Router or Mobile hotspot see below example
const char *Apssid = "WHAT EVER YOU LIKE"; //give Accesspoint SSID, your esp's hotspot name
const char *Appassword = "PASSWORD"; //password of your esp's hotspot
void setup() {
// put your setup code here, to run once:
Serial.begin(115200); //to enable Serial Commmunication with connected esp8266 board
delay(500);
WiFi.mode(WIFI_AP_STA); //changing ESP9266 wifi mode to AP + STATION
WiFi.softAP(Apssid, Appassword); //Starting AccessPoint on given credential
IPAddress myIP = WiFi.softAPIP(); //IP Address of our Esp8266 accesspoint(where we can host webpages, and see data)
Serial.print("Access Point IP address: ");
Serial.println(myIP);
Serial.println("");
delay(1500);
Serial.println("connecting to Wifi:");
Serial.println(Wifi_ssid);
WiFi.begin(Wifi_ssid, Wifi_password); // to tell ESP8266 Where to connect and trying to connect
while (WiFi.status() != WL_CONNECTED) { // While loop for checking Internet Connected or not
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP()); // successful Connection of ESP8266,
// printing Local IP given by your Router or Mobile Hotspot,
// Esp8266 connect at this IP
Serial.println("");
}
void loop() {
// put your main code here, to run repeatedly:
}
@gelomon
Copy link

gelomon commented Aug 21, 2023

Thank you! I have implemented this + elegantOTA + arduinoOTA so I have full flexibility to update my esp8266

@poyrazhancilar
Copy link

Thank you, works without any problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment