Chat freely about anything...

User avatar
By craigfoo
#48423 I'm using a Huzzah ESP8266 and my code fires up the ESP8266 Access Point so I can connect to it via TCP to send Wifi credentials over. When I set the default IP with softAPConfig, the HTTP Client fails to work. This only happens on certain routers and it fails on the current router it's trying to connect to which has an IP range of 192.168.1.100 to .199 The default gateway is 192.168.1.254.

When I set the softAPConfig IP to 192.168.1.1, the HTTP client fails to connect. If I set it to anything else; i.e. 192.168.0.1, the HTTP client works fine. Here is the test code to recreate the problem:

Code: Select all/**
 * BasicHTTPClient.ino
 *
 *  Created on: 24.05.2015
 *
 */

#include <Arduino.h>

#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>

#include <ESP8266HTTPClient.h>

#define USE_SERIAL Serial

ESP8266WiFiMulti WiFiMulti;

IPAddress apIP(192, 168, 1, 1);
IPAddress apGateway(192, 168, 1, 1);
IPAddress apSubmask(255, 255, 255, 0);

void setup() {

    USE_SERIAL.begin(115200);
    WiFi.mode(WIFI_AP_STA);
    WiFi.softAPConfig(apIP, apGateway, apSubmask);
    WiFi.softAP("ESP8266");

    USE_SERIAL.println();
    USE_SERIAL.println();
    USE_SERIAL.println();

    for(uint8_t t = 4; t > 0; t--) {
        USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
        USE_SERIAL.flush();
        delay(1000);
    }

    WiFiMulti.addAP("[SSID]", "[PASS]");

}

void loop() {
    // wait for WiFi connection
    if((WiFiMulti.run() == WL_CONNECTED)) {

        Serial.print("Local IP Address: "); Serial.println(WiFi.localIP());
        Serial.print("SoftAP IP Address: "); Serial.println(WiFi.softAPIP());

        HTTPClient http;

        USE_SERIAL.print("[HTTP] begin...\n");
        http.begin("www.google.com", 80, "/");

        USE_SERIAL.print("[HTTP] GET...\n");
        // start connection and send HTTP header
        int httpCode = http.GET();
        if(httpCode) {
            // HTTP header has been send and Server response header has been handled
            USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);

            // file found at server
            if(httpCode == 200) {
                String payload = http.getString();
                USE_SERIAL.println(payload);
            }
        } else {
            USE_SERIAL.print("[HTTP] GET... failed, no connection or no HTTP server\n");
        }
    }

    delay(5000);
}

User avatar
By craigfoo
#48425 Adding the console outputs:

Console Output:

Code: Select allLocal IP Address: 192.168.1.188
SoftAP IP Address: 192.168.1.1
[HTTP] begin...
[HTTP] GET...
[HTTP] GET... code: -1


Console Output with Changing the IP:

Code: Select allLocal IP Address: 192.168.1.188
SoftAP IP Address: 192.168.0.1
[HTTP] begin...
[HTTP] GET...
[HTTP] GET... code: 200
<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en"><head><meta content="Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for." name="description"><meta content="noodp" name="robots"><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"><meta content="/images/branding/googleg/1x/googleg_standard_color_128dp.png" itemprop="image"><title>Google</title><script>(function()

blah blah
User avatar
By eduperez
#48451 Think about this: if the gateway is 192.168.1.254, and both networks are 192.168.1.x, how can the ESP know which network should use to reach the gateway?