Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By GainingVenum
#52027 I'm unable to connect when using WPA2 - Personal, but if I switch to WPA, my sketch works fine. I tried two different routers with the same result. Any ideas on what I'm doing wrong? (I should also mention that I had similar results when I tried AT commands and lua).

SKETCH:
Code: Select all#include <ESP8266WiFi.h>

const char* ssid     = "MYSSID2";
const char* password = "abcdefABCDEF123";

void setup() {
  Serial.begin(115200);
  delay(100);

  Serial1.begin(115200);
  delay(100);
  Serial1.setDebugOutput(true);

  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);

//  tried static ip, still fails...
//  IPAddress ip (192,168,2,117);
//  IPAddress gw(192,168,2,1);
//  IPAddress msk(255,255,255,0);
//  IPAddress dns0(192,168,2,1);
//  IPAddress dns1(192,168,1,1); 
//  WiFi.config(ip, gw, msk, dns0, dns1);
 
  if (WiFi.waitForConnectResult() != WL_CONNECTED) {
    Serial1.println("Failed");
  } else {
    Serial.println("WiFi connected");
  }
 
  Serial.print("\n\nIP Address: ");
  Serial.println(WiFi.localIP());
  Serial.print("Mask: ");
  Serial.println(WiFi.subnetMask());
  Serial.print("Gateway: ");
  Serial.println(WiFi.gatewayIP());
  Serial.print("DNS0: ");
  Serial.println(WiFi.dnsIP(0));
  Serial.print("DNS1: ");
  Serial.println(WiFi.dnsIP(1)); 
  Serial.print("DHCP Hostname: ");
  Serial.println(WiFi.hostname());
  Serial.print("AutoConnect: ");
  Serial.println(WiFi.getAutoConnect());
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());
  long rssi = WiFi.RSSI();
  Serial.print("Signal Strength (RSSI):");
  Serial.println(rssi);
}

void loop() {
  delay(10000);

  char* host = "www.adafruit.com";
  Serial.print("\nConnecting to ");
  Serial.println(host);

  WiFiClient client;
  if (!client.connect(host, 80)) {
    Serial.print("Connection Failed");
    return;
  }

  String url = "/testwifi/index.html";
  Serial.print("Requesting URL: ");
  Serial.println(url);

  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\nConnection: close\r\n\r\n");
  delay(500);

  while (client.available()) {
    String line = client.readStringUntil('\r');
    Serial.print(line);
  }
}


SERIAL1 OUTPUT WHEN USING WPA2 PERSONAL (SERIAL OUTPUTS NOTHING):
sta config unchangedf r0, scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 1
cnt
connected with MYSSID2, channel 1
dhcp client start...
wifi evt: 0
pm open,type:2 0

SERIAL1 OUTPUT WHEN USING WPA:
sta config unchangedf r0, scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 1
cnt
connected with MYSSID2, channel 1
dhcp client start...
wifi evt: 0
ip:192.168.2.117,mask:255.255.255.0,gw:192.168.2.1
wifi evt: 3
pm open,type:2 0
[hostByName] request IP for: http://www.adafruit.com
[hostByName] Host: http://www.adafruit.com IP: 104.20.39.240
:ref 1
:wr
:sent 80
:ww
:rn 509
:rch 509, 5
:rcl
:abort
:c 1, 509, 514
:c0 1, 5
:ur 1
:del

SERIAL OUTPUT WHEN USING WPA:
IP Address: 192.168.2.117
Mask: 255.255.255.0
Gateway: 192.168.2.1
DNS0: 192.168.1.1
DNS1: 192.168.2.1
DHCP Hostname: ESP_88C15A
AutoConnect: 0
SSID: MYSSID2
Signal Strength (RSSI):-50
Connecting to http://www.adafruit.com
Requesting URL: /testwifi/index.html
HTTP/1.1 200 OK
Date: Wed, 03 Aug 2016 14:01:09 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: close
Set-Cookie: ...; expires=...; path=/; domain=.adafruit.com; HttpOnly
Last-Modified:...
Vary: Accept-Encoding
Server: cloudflare-nginx
4a
This is a test of the CC3000 module!
If you can read this, its working
0

HARDWARE / SOFTWARE CONFIGURATION:
Adafruit HAZZAH
Arduino IDE 1.6.10
Bench Power Supply 4.5v, 1A (HAZZAH breakout has 3.3v regulator)
USB-USARTs (cp2102's)
Router Details:
Linksys E1200 with latest firmware (but also tried a Fios-1100)
Wireless-G Only (but tried N, and mixed modes)
20MHz (but tried 20/40 auto)
Channel Auto (but tried various individual channels)
SSID Broadcast = Enabled
SSID and Passphrase (see sketch above, but tried many others, no special chars or spaces)
User avatar
By GainingVenum
#52307 Update: I finally had time to try my other two Adafruit Hazzah's in the same exact circuit with exactly the same sketch and they both successfully connected to my WPA2 Personal network, the first time, no issues at all. I then retried the problem unit, and it failed again. I examined all three under magnification and could find no obvious differences (i.e. no solder splatter, bad solder joints, etc.).

Question: Does uploading the same Arduino sketch to all three guarantee all have exactly the same software or could there still be differences elsewhere, like in configuration areas, etc.? I'm new to esp8266 and still trying to fully understand the purpose of things like esp_init_data_default.bin, and blank.bin, etc.

If they're identical hardware and software at this point, should I assume I either received a bad unit or somehow damaged it (soldering on the headers, supplying power, or communicating via CP2102's)? It's still strange to me that the problem unit seems to work fine until I switch the router over to WPA2 Personal. Seems like a strange problem that I might expect if I applied an over voltage, but I doubt that happened since the unit has an on-board voltage regulator and it's working fine and I've been very careful. Usually, when I let the "magic smoke" escape from a circuit I realize what I've done wrong before the smoke clears! I've bought many products from Adafruit over the years and I've always been satisfied, so my first instinct is to suspect user error and I'd like to prevent the others from failing if possible.
User avatar
By mrburnette
#52700
GainingVenum wrote:<...>
Question: Does uploading the same Arduino sketch to all three guarantee all have exactly the same software or could there still be differences elsewhere, like in configuration areas, etc.? I'm new to esp8266 and still trying to fully understand the purpose of things like esp_init_data_default.bin, and blank.bin, etc.


My opinion (and with about 18 months of experience):
If you compile three identical modules (say 1M of flash) then the memory map shown here should be identical:
https://github.com/esp8266/esp8266-wiki/wiki/Memory-Map

The ArduinoIDE compiles the sketch, libraries, core files, and links them. The upload then conforms to this memory configuration:
https://github.com/esp8266/esp8266-wiki/wiki/Memory-Map#spi-flash-rom-layout-without-ota-upgrades

My suggestion is to pick one of these tools and figure out what is happening in real-time:
https://www.google.com/#q=free+open+source+wireless+sniffer

Ray
User avatar
By romecas
#76359 I spent the last 2 days with the same issue and it got solved.. not sure how.

I have a RobotDyn (one of these https://www.tinytronics.nl/shop/nl/ardu ... -4mb-ch340) and it also didn't connect to my WPA2 network. Here's the sequence I went through to make it work:
- MAC OS build: tried the WPA2 network 100 times, with different configurations and code etc. never worked (will paste code below)
- MAC OS build: made an AndroidAP on a network on the phone, tried the new credentials and it connected immediately
- MAC OS build: tried the WPA2 network another 20 times, no luck.
- Windows build: tried the WPA2 network another 20 times, no luck.
- Windows build: made a secondary WIFI on the router, this time with a basic WEP --> worked fine!
- Windows build: adjusted this secondary network WIFI to WPA -> also worked
- Windows build: adjusted the sec. network to WPA2 --> also worked!
- Windows build: adjusted the code to connect to the original WPA2 network-> ALSO WORKED! YEY
- MAC OS build: adjusted the code to connect to the original WPA2 network-> ALSO WORKED! YEY

bottom line: it was probably some default code or memory area which was overwritten in the meantime that caused this difference. Maybe something triggered by a windows compile, not sure :(

probably worth mentioning: the log when it refused to connect was pretty much like this
Code: Select allstate: 0 -> 2 (b0)
state: 2 -> 0 (0)
...
state: 0 -> 2 (b0)
state: 2 -> 0 (0)
...
state: 0 -> 2 (b0)
state: 2 -> 0 (0)
...



code (not clean yet, but you get the idea)
Code: Select all#include <ESP8266WiFi.h>
//#include <WiFiClient.h>
//#include <IPAddress.h>
const char* ssid = "XXXXXX";
//const char* ssid = "DrayTek_Guest";
//const char* ssid = "AndroidAP";
const char* password = "XXXXXX";

String header;
String gpio5_state = "Off";
String gpio4_state = "Off";
int gpio5_pin = 5;
int gpio4_pin = 4;
int pin = 2; //pin where the LED is attached
bool toggle;

int counter;

void setup() {

  ESP.eraseConfig(); //not really sure what this does
  delay(1000);
  WiFi.disconnect(); // remove old credentials they say
  delay(1000);

  //ESP.reset();
  //ESP.restart();
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.setDebugOutput(true);
  delay(1000);

  WiFi.scanNetworksAsync(prinScanResult);
  delay(4000);
  pinMode(gpio5_pin, OUTPUT);
  pinMode(gpio4_pin, OUTPUT);
  pinMode(pin, OUTPUT);
  digitalWrite(gpio5_pin, LOW);
  digitalWrite(gpio4_pin, LOW);
  digitalWrite(pin, LOW);

  //connect to WiFi
  Serial.println();
  Serial.print("Connecting to ");
  Serial.print(ssid);
  WiFi.persistent(false);

  WiFi.mode(WIFI_OFF);

  delay(200);
  //WiFi.mode(WIFI_AP_STA);
  WiFi.mode(WIFI_STA);
  delay(1000);
  WiFi.begin(ssid, password);
  WiFi.printDiag(Serial);
  delay(1000);

  while (WiFi.status() != WL_CONNECTED)
  {
    delay(20000);
    //Serial.print(".");
    Serial.println(statusToString(WiFi.status()));
    counter++;
    if (counter > 30)
    {
      counter = 0;
      Serial.println();
    }
    toggle = not toggle;
    //digitalWrite(pin, toggle);

  }
  Serial.println();
  Serial.print("WiFi connected");
  digitalWrite(pin, HIGH);

  //Starting the web server
  //server.begin();
  Serial.println("Web server running. Waiting for ESP IP...");
  delay(10000);

  //ip address
  Serial.println(WiFi.localIP());

}

void loop() {
}



output:

[code]
rd