1
votes

Is it possible? ESP8266 connect to router wifi via iOS application? I want to make an application control something by ESP8266. My workflow bellow:

  • Open the app, on the device connected to wifi router.
  • Connect to ESP8266 and give it SSID and PASSWORD info from current Wifi.
  • ESP8266 receive this infos and auto connect to Wifi router.

Thank for your advices first.

I tried this way but I get user experience. Because user has to do many steps. - Using WiFiManager, make ESP8266 as wifi router. - Go to Wifi setting from device to connect to ESP8266 Wifi. - Give Wifi infos (SSID, PASSWORD) by go to 192.168.4.1 from web browser. Just note here to avoid this way

Please give me your advices. Thank you

3
just store the config in SPIFFSdandavis
ESP8266 has internal storage that stores the credentials which you've provided once. So they will not be forgotten.cagdas

3 Answers

1
votes

First of all, I don't think you made ESP8266 as a Wi-Fi router. I think you mean it goes into AP mode to prompt the user for the credentials.

I have worked around this by using the EEPROM library. You can easily find code example here

So basically:

  1. Pre hard code credentials (can be dummy data for first run) to the EEPROM.
  2. When ESP8266 boots up, load those credentials and try to connect to the Wi-Fi.
  3. If it can't connect, prompt the user to input credentials.
  4. ESP8266 tries to reconnect. If it can connect, then write credentials to EEPROM.
  5. Repeat from step 2 every time it boots up.

Now instead of having user input credentials every single time, it will try to connect first. If it fails, then user will have to do extra work.

Let me know if I can help, I have work extensively on this problem and have working code.

0
votes

WiFiManager requires you to:

  1. Connect to ESP8266's AP
  2. Go to 192.168.4.1 (or any other set address) - on iOS it should appear automatically
  3. Click on Wifi scan
  4. Choose the network you want your ESP8266 to connect to
  5. Provide password if any
  6. Click Save button

This is the minimal thing a user has to do. He/she has to connect to ESP8266's AP and provide WiFi credentials somehow. The only thing that you can change is how the user provides that credentials. If you already make your user download your iOS app, then maybe it's okay to add possibility to configure ESP8266 within your app.

In order to configure ESP8266 with WiFiManager on board your app would have to:

  1. Scan for WiFi networks and connect to ESP8266's AP (eg. by searching for particular SSIDs)
  2. Send GET request to http://192.168.4.1/wifisave?s=NETWORK_SSID&p=NETWORK_PASSWORD

However, please bear in mind that it's pointless otherwise. If your user isn't required to download any app before configuring ESP8266, then don't require him/her to do it. Web applications are a way to go in these days. This approach won't require a user to download another app just to type in the WiFi credentials. WiFiManager should appear automatically after user connects to the device's AP.

0
votes

I found the way to do that: This is code on iOS application: https://github.com/EspressifApp/EsptouchForIOS

This is code on ESP8266 run on Arduino:

#include <ESP8266WiFi.h>
#include <WiFiUdp.h>

WiFiUDP Udp;

void setup() {
  int cnt = 0;
  //Allocate baud 115200
  Serial.begin(115200);
  //Mode wifi is station
  WiFi.mode(WIFI_STA);
  //Waiting for connect
  while(WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
    if(cnt++ >= 10){
       WiFi.beginSmartConfig();
       while(1){
           delay(1000);
           //Check the connect and print inform if success
           if(WiFi.smartConfigDone()){
             Serial.println("SmartConfig Success");
             break;
           }
       }
    }
  }

  Serial.println("");
  Serial.println("");

  WiFi.printDiag(Serial);

  // Allocate server
  Udp.begin(49999);
  Serial.println("Server started");

  // Print IP address
  Serial.println(WiFi.localIP());
}

void loop() {
  // Receive the package from ESPTouch
  Udp.parsePacket();
  //Print IP of ESP8266
  while(Udp.available()){
    Serial.println(Udp.remoteIP());
    Udp.flush();
    delay(5);
  }
}