0

I have an problem with the SoftAP of ESP8266-Arduino.

If ACCESS_POINT is false everything works fine. But if ACCESS_POINT is true: It works. But after a few seconds of data transmissions the AP is gone. The only way to reconnect is to restart the ESP8266.

I need the AP mode for using mobile with the smartphone.

I've already cleared the memory of the ESP8266 complete. But it doesn't help...

#define PIN_NEOPIXEL 2
#define PIN_LED_SWITCH 0

#define NUMPIXELS 60

#define ACCESS_POINT true

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN_NEOPIXEL, NEO_GRB + NEO_KHZ800);

ESP8266WebServer server(80);
WebSocketsServer webSocket(81);

void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght) {
    switch (type) {
        case WStype_BIN:
            //Serial.printf("[%u] get Text: %s  %u\n", num, payload, lenght);
            if (payload[0] == '#') {
                if(lenght == 1 + NUMPIXELS * 3) {
                    for(int i=0;i<NUMPIXELS;i++){
                        int r = payload[1 + i * 3];
                        int g = payload[1 + i * 3 + 1];
                        int b = payload[1 + i * 3 + 2];

                        pixels.setPixelColor(i, pixels.Color(r,g,b));
                    }

                    pixels.show();
                }
            }
            if (payload[0] == '!') { //LED ein/aus
                if (payload[1] == '1') {
                    digitalWrite(PIN_LED_SWITCH, false);
                    pinMode(PIN_LED_SWITCH, OUTPUT);
                } else {
                    pinMode(PIN_LED_SWITCH, INPUT_PULLUP);
                }
            }
            break;
    }
}


void setup() {
    pixels.begin();

    Serial.begin(115200);

    WiFi.mode(WIFI_OFF);
    if(!ACCESS_POINT) {
        WiFi.mode(WIFI_STA);
        WiFi.begin("SSID", "...key...");

        while (WiFi.status() != WL_CONNECTED) {
            delay(1000);
        }

        Serial.print("IP address:\t");
        Serial.println(WiFi.localIP());
    } else {
        WiFi.mode(WIFI_AP);
        IPAddress apIP(192, 168, 4, 1);
        IPAddress netMsk(255, 255, 255, 0);
        WiFi.softAPConfig(apIP, apIP, netMsk);
        WiFi.softAP("Pixelstick");
        while (WiFi.softAPgetStationNum() < 1) {
            delay(1000);
        }
    }


    server.on("/", []() {
        server.send(200, "text/html", INDEX_HTML);
    });
    server.begin();

    webSocket.begin();
    webSocket.onEvent(webSocketEvent);
}

void loop() {
    webSocket.loop();
    server.handleClient();
    yield();
}

1 Answer 1

0

Since you did not give any versions of SW or HW:

The following works stable on a NodeMCU v0.9 and v1.0 (ESP8266-12E)

IDE -> Arduino IDE 1.85 with ESP Package version 2.42 (worked also with 2.41)

Version of the package can be checked here C:\Users[YOURUSERNAME]\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2

For these environments do the following

void loop() {
    webSocket.loop();
    server.handleClient();
 //   yield(); ==> delete this line
}

yield() leads to unpredictable behavior with the esp8266 libs - in older versions this was used as a workaround to some bugs but was never a satisfying solution

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.