2
votes

I have a question regarding wifi connection from a NodeMCU ESP8266 board to an Apple iPhone6 personal hotspot. The iOS version is 10.2.1 (14027). The NodeMCU code I use works with my home WLAN using WPA2 without any problems. If I change SSID and password to connect to the Apple hotspot the while() loop runs forever (see code, I'm using Arduino IDE 1.8.2):

#include <ESP8266WiFi.h>

const char* ssid = "iPhone6";
const char* password = "passwd";

void setup() {
  Serial.begin(115200);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(1500);
  }
}

void loop() {
  // do something
  delay(10000);
}

To check things out I used the NodeMCU to scan for wifi networks and got my Apple hotspot listed (also using WPA2) so the board can "see" it. I can connect to the Apple hotspot with my iPad and my Dell Laptop so this works also. All the web pages I found are dealing with problems to set up the NodeMCU as WiFi server and not as a client. Is there another detail that I forgot in my code? Or is there another WiFi library than ESP8266WiFi I can use? If someone managed to get this connection work I would appreciate any hint.

1
Have any non-ascii characters in your iPhone name or password?leetibbett
No, just standard ASCII without any local characters.Armin
Check the MAC address if it is in the blacklist of the AP.cagdas
Set your WiFi connection mode to STA.cagdas

1 Answers

4
votes

The problem is (I believe) that the ESP8266 will be in whatever mode (AP, STA, AP_STA) it was in the last time it was powered up, unless you explicitly change it. So, for example, your code worked fine for me, as is, a couple of times depending on what I had previously been doing with my board.

In order to get the code to work consistently, you have to (as @cagdas says) explicitly put it in STA mode. So the following change to your code will do so. I've verified this using my board and an iPhone 6s, the 1.8.2 Arduino IDE and version 1.0.0 of the ESP8266 libraries.

#include <ESP8266WiFi.h>

const char* ssid = "iPhone6";
const char* password = "passwd";

void setup() {
  Serial.begin(115200);
  WiFi.mode(WIFI_STA); // SETS TO STATION MODE!
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(1500);
  }
}

void loop() {
  Serial.print("IP is ");
  Serial.println(WiFi.localIP());
  delay(10000);
}