( roleez | 2024. 05. 25., szo – 10:23 )

Szerkesztve: 2024. 05. 25., szo – 10:47

Ezt a minimális példát futtattam:

#include <WiFi.h>

const char *ssid = "xxx";

const char *password = "xxx";


int LED = 2;

int btnGPIO = 0;

int btnState = false;


void setup() {

  Serial.begin(115200);

  delay(10);


  // Set GPIO0 Boot button as input

  pinMode(LED, OUTPUT);

  pinMode(btnGPIO, INPUT);


  // We start by connecting to a WiFi network

  // To debug, please enable Core Debug Level to Verbose


  Serial.println();

  Serial.print("[WiFi] Connecting to ");

  Serial.println(ssid);


  WiFi.begin(ssid, password);

  // Auto reconnect is set true as default

  // To set auto connect off, use the following function

  //    WiFi.setAutoReconnect(false);


  // Will try for about 10 seconds (20x 500ms)

  int tryDelay = 500;

  int numberOfTries = 20;


  // Wait for the WiFi event

  while (true) {


    switch (WiFi.status()) {

    case WL_NO_SSID_AVAIL:

      Serial.println("[WiFi] SSID not found");

      break;

    case WL_CONNECT_FAILED:

      Serial.print("[WiFi] Failed - WiFi not connected! Reason: ");

      return;

      break;

    case WL_CONNECTION_LOST:

      Serial.println("[WiFi] Connection was lost");

      break;

    case WL_SCAN_COMPLETED:

      Serial.println("[WiFi] Scan is completed");

      break;

    case WL_DISCONNECTED:

      Serial.println("[WiFi] WiFi is disconnected");

      break;

    case WL_CONNECTED:

      Serial.println("[WiFi] WiFi is connected!");

      Serial.print("[WiFi] IP address: ");

      Serial.println(WiFi.localIP());

      digitalWrite(LED, HIGH);

      return;

      break;

    default:

      Serial.print("[WiFi] WiFi Status: ");

      Serial.println(WiFi.status());

      break;

    }

    delay(tryDelay);


    if (numberOfTries <= 0) {

      Serial.print("[WiFi] Failed to connect to WiFi!");

      // Use disconnect function to force stop trying to connect

      WiFi.disconnect();

      digitalWrite(LED, LOW);

      return;

    } else {

      numberOfTries--;

    }

  }

}


void loop() {

  // Read the button state

  btnState = digitalRead(btnGPIO);


  if (btnState == LOW) {

    // Disconnect from WiFi

    Serial.println("[WiFi] Disconnecting from WiFi!");

    // This function will disconnect and turn off the WiFi (NVS WiFi data is

    // kept)

    if (WiFi.disconnect(true, false)) {

      Serial.println("[WiFi] Disconnected from WiFi!");

    }

    delay(1000);

  }

}

Induláskor (flashelés után, USB újracsatlakozása után) ezt kapom (20x):

..
[WiFi] WiFi is disconnected
[ 3284][V][WiFiGeneric.cpp:362] _arduino_event_cb(): STA Disconnected: SSID: gentoom, BSSID: 18:e8:29:fb:75:08, Reason: 15
[ 3285][D][WiFiGeneric.cpp:931] _eventCallback(): Arduino Event: 5 - STA_DISCONNECTED
[ 3292][W][WiFiGeneric.cpp:955] _eventCallback(): Reason: 15 - 4WAY_HANDSHAKE_TIMEOUT
[ 3300][D][WiFiGeneric.cpp:975] _eventCallback(): WiFi Reconnect Running
[ 3308][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0
...

(és ezt se mindig, most pl. 5x próbáltam, és mindig kapcsolódott - de nem ez a jellemző.)

 

Majd megnyomom a gombot:
 

rst:0x1 (POWERON_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:1184
load:0x40078000,len:13104
load:0x40080400,len:3036
entry 0x400805e4

...

[WiFi] WiFi is disconnected
[WiFi] WiFi is disconnected
[WiFi] WiFi is disconnected
[  1201][V][WiFiGeneric.cpp:362] _arduino_event_cb(): STA Disconnected: SSID: gentoom, BSSID: 18:e8:29:fb:75:08, Reason: 4
[  1202][D][WiFiGeneric.cpp:931] _eventCallback(): Arduino Event: 5 - STA_DISCONNECTED
[  1209][W][WiFiGeneric.cpp:955] _eventCallback(): Reason: 4 - ASSOC_EXPIRE
[  1215][D][WiFiGeneric.cpp:975] _eventCallback(): WiFi Reconnect Running
[  1224][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0
[  1300][V][WiFiGeneric.cpp:355] _arduino_event_cb(): STA Connected: SSID: gentoom, BSSID: 18:e8:29:fb:75:08, Channel: 1, Auth: WPA2_PSK
[  1301][D][WiFiGeneric.cpp:931] _eventCallback(): Arduino Event: 4 - STA_CONNECTED
[  1327][V][WiFiGeneric.cpp:369] _arduino_event_cb(): STA Got New IP:192.168.3.135
[  1328][D][WiFiGeneric.cpp:931] _eventCallback(): Arduino Event: 7 - STA_GOT_IP
[  1331][D][WiFiGeneric.cpp:996] _eventCallback(): STA IP: 192.168.3.135, MASK: 255.255.255.0, GW: 192.168.3.1
[WiFi] WiFi is connected!
[WiFi] IP address: 192.168.3.135

Kapcsolódik. Lehet az AMS117 IC-nél lévő kondik (10 uF) kevesek?