I have a problem of using WPS connection.

Akira Kashihara
Posts: 1
Joined: Sat Jul 08, 2017 5:12 am

I have a problem of using WPS connection.

Postby Akira Kashihara » Sun Jul 16, 2017 10:25 am

Hello, I face a problem on using WPS connection.
I refer to same code of esp-idf repository and create the following.
However I get an error "Guru Meditation Error: Core 0 panic'ed (abort)"
I debug this code and I guess that " ESP_ERROR_CHECK(esp_wifi_start());" makes this error but I cannot understand why this code makes me it.
I'm looking forward to your solution about it.

Code: Select all

#include <Arduino.h>

#include <WiFi.h>
#include <esp_wps.h>
#include <esp_wifi.h>
#include <esp_log.h>
#include <esp_event_loop.h>

#include <HTTPClient.h>

#define USE_SERIAL Serial

static const char *TAG = "example_wps";
#define PIN2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5], (a)[6], (a)[7]
#define PINSTR "%c%c%c%c%c%c%c%c"

static esp_err_t event_handler(void *ctx, system_event_t *event) {
  switch (event->event_id) {
    case SYSTEM_EVENT_STA_START:  //Station Start event
      ESP_LOGI(TAG, "SYSTEM_STA_START");  //log station start event
      break;
    case SYSTEM_EVENT_STA_GOT_IP:             //station ip address get event
      ESP_LOGI(TAG, "SYSTEM_EVENT_STA_GOT_IP"); //log
      ESP_LOGI(TAG, "got ip %s\n", ip4addr_ntoa(&event->event_info.got_ip.ip_info.ip)); //log ip address
      break;
    case SYSTEM_EVENT_STA_DISCONNECTED:     //station disconnected event
      ESP_LOGI(TAG, "SYSTEM_EVENT_STA_DISCONNECTED"); //log disconnect
      ESP_ERROR_CHECK(esp_wifi_connect());            //wifi reconnect after disconnect event
    case SYSTEM_EVENT_STA_WPS_ER_SUCCESS:           //ESO32 station wps succeeds in enrollee mode
      ESP_LOGI(TAG, "SYSTEM_EVENT_STA_WPS_ER_SUCCEESS");  //log esp32 station wps enrollee mode
      ESP_ERROR_CHECK(esp_wifi_wps_disable());        //wps function is disable
      ESP_ERROR_CHECK(esp_wifi_connect());            //wifi connect
      break;
    case SYSTEM_EVENT_STA_WPS_ER_FAILED:  //esp32 wps is failed
      ESP_LOGI(TAG, "SYSTEM_EVENT_STA_WPS_ER_FAILED");    //log that esp32 wps is failed
      ESP_ERROR_CHECK(esp_wifi_wps_disable());  //esp wps is disable
      ESP_ERROR_CHECK(esp_wifi_wps_enable(WPS_TYPE_PBC));    //esp32 wps is push button configuration mode restart
      ESP_ERROR_CHECK(esp_wifi_wps_start(0));             //esp32 wps is started
      break;
    case SYSTEM_EVENT_STA_WPS_ER_TIMEOUT:     //esp32 wps is timeout
      ESP_LOGI(TAG, "SYSTEM_EVENT_STA_WPS_ER_TIMEOUT"); //log timeout
      ESP_ERROR_CHECK(esp_wifi_wps_disable());  //esp wps is disable
      ESP_ERROR_CHECK(esp_wifi_wps_enable(WPS_TYPE_PBC));    //esp32 wps is push button configuration mode restart
      ESP_ERROR_CHECK(esp_wifi_wps_start(0));             //esp32 wps is started
      break;
    case SYSTEM_EVENT_STA_WPS_ER_PIN:                 //ESP32 station wps pin code in enrollee mode
      ESP_LOGI(TAG, "SYSTEM_EVENT_STA_WPS_ER_PIN");   //log
      //show the PIN code here
      ESP_LOGI(TAG, "WPS_PIN = "PINSTR, PIN2STR(event->event_info.sta_er_pin.pin_code));
      break;
    default:
      break;
  }
  return ESP_OK;
}

void setup() {

  tcpip_adapter_init(); //This will initialize TCPIP inside.

  wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); //Initialize WiFi Configuration
  ESP_ERROR_CHECK(esp_wifi_init(&cfg));                //esp wifi initilaize with cfg

  ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));     //wifi mode is station mode
  ESP_ERROR_CHECK(esp_wifi_start());                    //wifi start

  ESP_LOGI(TAG, "start wps...");                        //output log
  ESP_ERROR_CHECK(esp_wifi_wps_enable(WPS_TYPE_PBC));   //wps enable in on Push Button Configuration mode
  ESP_ERROR_CHECK(esp_wifi_wps_start(0));               //wps is started without blocking time

  USE_SERIAL.begin(115200);

  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);
  }
}

void loop() {
  if (esp_wifi_connect() == ESP_OK) {
    HTTPClient http;

    USE_SERIAL.print("[HTTP] begin...\n");
    http.begin("http://example.com/index.html"); //HTTP

    USE_SERIAL.print("[HTTP] GET...\n");
    int httpCode = http.GET();

    if (httpCode > 0) {
      USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);

      if (httpCode == HTTP_CODE_OK) {
        String payload = http.getString();
        USE_SERIAL.println(payload);
      }
    } else {
      USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
    }

    http.end();
  }
  delay(5000);
}

Who is online

Users browsing this forum: No registered users and 119 guests