tzapu / WiFiManager

ESP8266 WiFi Connection manager with web captive portal
http://tzapu.com/esp8266-wifi-connection-manager-library-arduino-ide/
MIT License
6.63k stars 1.98k forks source link

[ 18356][E][WebServer.cpp:638] _handleRequest(): request handler not found #1759

Closed tozehu closed 3 months ago

tozehu commented 3 months ago

Basic Infos

Hardware

WiFimanager Master

Esp8266/Esp32: Esp32

Hardware: ESP32 wroom 32d

[env:esp32dev]

Core Version: vs code PIO

Espressif 32 6.8.1

[env:esp32dev] platform = https://github.com/platformio/platform-espressif32.git board = esp32dev framework = arduino lib_deps = https://github.com/tzapu/WiFiManager.git bblanchon/ArduinoJson@^7.1.0

Description

After compiling and uploading to ESP32 using VS Code PIO IDE, when entering the Wi-Fi configuration page, the serial output shows the following error: [18356][E][WebServer.cpp:638] _handleRequest(): request handler not found

When using Arduino to upload, it works normally.

Settings in IDE

Module: NodeMcu-32

Additional libraries:

Sketch

#BEGIN
#include <FS.h>  
#include <Arduino.h>
#include <WiFiManager.h> 
#include "AudioSampler.h"
#include <WiFi.h>
#ifdef ESP32
  #include <SPIFFS.h>
#endif
#include <ArduinoJson.h>  

//--------定义常量---------

#define uS_TO_S_FACTOR 1000000ULL
#define MUTEPIN 2                 //触摸指示灯引脚
#define TOUCH_THRESHOLD 40        //触摸灵敏度阈值,越大越灵敏
#define TRIGGER_PIN 0            //触摸引脚,现用于触发Wi-Fi配置页面

char SERVER_IP[40]="192.168.1.60";
char SERVER_PORT[7] = "8888";
IPAddress serverIP; // 用于存储转换后的 IP 地址
uint16_t serverPort; // 用于存储转换后的端口号
WiFiClient wifiClient;
bool shouldSaveConfig = false;

//-------定义变量----------
volatile bool wifiConnected = true;
volatile bool mute = false;
//volatile int statusLedState = LOW;
volatile unsigned long sinceLastTouch = 0;
volatile bool inited = false;
// i2s配置
i2s_config_t i2sConfig = { .mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX),
                           .sample_rate = 44100,
                           .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
                           .channel_format = I2S_CHANNEL_FMT_ONLY_LEFT,
                           //.communication_format =
                           //  i2s_comm_format_t(I2S_COMM_FORMAT_I2S),
                           .communication_format=
                           //i2s_comm_format_t(I2S_COMM_FORMAT_I2S_MSB),
                           i2s_comm_format_t(I2S_COMM_FORMAT_STAND_I2S),
                           .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,
                           .dma_buf_count = 4,
                           .dma_buf_len = 1024,
                           .use_apll = false,
                           .tx_desc_auto_clear = false,
                           .fixed_mclk = 0
                         };
// i2s pin配置
i2s_pin_config_t i2SPinConfig = { .bck_io_num = GPIO_NUM_14,
                                  .ws_io_num = GPIO_NUM_15,
                                  .data_out_num = I2S_PIN_NO_CHANGE,
                                  .data_in_num = GPIO_NUM_32
                                };
AudioSampler *audioSampler = NULL;

WiFiManager wm;
void configSaveCallback();
//void configModeCallback();
WiFiManagerParameter custom_SERVER_IP("server", "tcp server", SERVER_IP, 40);
WiFiManagerParameter custom_SERVER_PORT("port", "tcp port", SERVER_PORT, 6);

void configModeCallback(WiFiManager *myWiFiManager) {
  Serial.println("Entered config mode");
}

/**
 * 将IP地址字符串转换为IPAddress对象。
 * 
 * @param str 指向IP地址字符串的指针,格式为 "dd.dd.dd.dd"。
 * @return 返回一个IPAddress对象,如果输入字符串不符合格式,则返回一个全0的IPAddress对象。
 * 
 * 本函数使用sscanf函数从字符串中解析出四个整数,分别代表IP地址的四部分,
 * 然后将这四个整数组合成一个IPAddress对象返回。如果字符串不包含四部分整数,
 * 则返回一个全0的IPAddress对象表示转换失败。
 */

IPAddress ConvertIP(char *str)
{
  // 定义四个整数变量,用于存储分割后的IP地址的四部分
  int ip1, ip2, ip3, ip4;
  IPAddress temp_serverIP;

  // 使用sscanf函数从str中解析出四个整数,如果成功解析出四部分,则继续执行,
  // 否则返回一个全0的IPAddress对象表示转换失败
  if (sscanf(str, "%d.%d.%d.%d", &ip1, &ip2, &ip3, &ip4) == 4)
  {
    // 将解析出的四个整数组合成一个IPAddress对象,并返回
    temp_serverIP = IPAddress(ip1, ip2, ip3, ip4);
    return temp_serverIP;
  }
  else
  {
    // 如果解析失败,返回一个全0的IPAddress对象
    return IPAddress(0, 0, 0, 0);
  }
}

/**
   静音中断函数
*/
void muteTouch() {
  if (millis() - sinceLastTouch < 1000) return;
  sinceLastTouch = millis();
  mute = !mute;
  if (mute) {
    digitalWrite(MUTEPIN, HIGH);
  } else {
    digitalWrite(MUTEPIN, LOW);
  }
  Serial.print("mutetouched");

}
/**
   发送缓冲数组到服务器方法
   @param param
*/
void transmitTask(void *param) {
  AudioSampler *audioSampler = (AudioSampler *)param;
  //socket连接服务器
  WiFiClient *wifiClient = new WiFiClient();
  serverIP=ConvertIP(SERVER_IP);
  //serverIP = IPAddress(SERVER_IP);
  char* end;
  serverPort = (uint16_t)strtol(SERVER_PORT, &end, 10);
  // 将字符串形式的端口号转换为整数
  //serverPort = atoi(SERVER_PORT);
  //  while (!wifiClient->connect("192.168.43.121", 8888)) {
  Serial.println("conver server ip:"+serverIP.toString());
  Serial.println("conver server port:"+String(serverPort));
  while (!wifiClient->connect(serverIP, serverPort))
  {
    delay(100);
  }
  if (wifiClient->connected()==true)
  {
    Serial.println("tcp connected");
  }

  wifiClient->setNoDelay(true);
  const TickType_t xMaxBlockTime = pdMS_TO_TICKS(100);
  unsigned long startTime;
  unsigned long endTime;
  while (true) {
    // 等待队列通知
    uint32_t ulNotificationValue = ulTaskNotifyTake(pdTRUE, xMaxBlockTime);
    if (ulNotificationValue > 0) {
      //wifi连接上同时未静音才发送数据
      if (wifiConnected && mute) {
//        Serial.print("start-->");
//        startTime = millis();
//        Serial.print(startTime);
//        Serial.print("---->");
        //Serial.print("start send---->");
        int sendNum = wifiClient->write((uint8_t *)audioSampler->getTransmitBuffer(), audioSampler->getTransmitPackageSize());
        if(!wifiClient->connected())
        {
          Serial.println("send error");
          while (!wifiClient->connect(serverIP, serverPort))
          {
            delay(100);
          }
        }

//        Serial.print("end-->");
//        endTime = millis();
//        Serial.print(endTime);
//        Serial.print("---->");
//        Serial.print("total--->");
//        Serial.println(endTime - startTime);
      } else {
        //未连接时情况tcp缓存
        wifiClient->flush();

      }
    }
  }
}
void wifiEvent(WiFiEvent_t event){
  switch (event)
  {
  case SYSTEM_EVENT_STA_CONNECTED:
    wifiConnected = true;
    // led亮起
    //digitalWrite(STATUSPIN, HIGH);
    break;
  case SYSTEM_EVENT_STA_DISCONNECTED:
    // 回调会多次执行,所以要判断一下
    if (inited)
    {
      wifiConnected = false;
      //digitalWrite(STATUSPIN, LOW);
      ESP.restart();
    }
    break;
  default:
    break;
  }
}
void initWifi()
{
  wm.resetSettings();
  // 初始化文件系统
  // wm.resetSettings();
  wm.setDebugOutput(true);
  //wm.debugSoftAPConfig();
  //SPIFFS.format();
  if (!SPIFFS.begin()) {
    Serial.println("mounting filesystem failed.. trying to format");
    SPIFFS.format();
    Serial.println("trying again to mount FS...");
  }
  Serial.println("mounting FS...");

  if (SPIFFS.begin())
  {
    Serial.println("mounted file system");
    if (SPIFFS.exists("/config.json"))
    {
      Serial.println("reading config file");
      File configFile = SPIFFS.open("/config.json", "r");
      if (configFile)
      {
        Serial.println("opened config file");
        size_t size = configFile.size();
        std::unique_ptr<char[]> buf(new char[size]);

        configFile.readBytes(buf.get(), size);

#if defined(ARDUINOJSON_VERSION_MAJOR) && ARDUINOJSON_VERSION_MAJOR >= 6
       //DynamicJsonDocument json(1024);
        //auto deserializeError = deserializeJson(json, buf.get());
        JsonDocument json;
        auto deserializeError = deserializeJson(json, buf.get());
        serializeJson(json, Serial);
        if (!deserializeError)
        {
#else
        DynamicJsonBuffer jsonBuffer;
        JsonObject &json = jsonBuffer.parseObject(buf.get());
        json.printTo(Serial);
        if (json.success())
        {
#endif
          Serial.println("\nparsed json");
          strcpy(SERVER_IP, json["SERVER_IP"]);
          strcpy(SERVER_PORT, json["SERVER_PORT"]);
        }
        else
        {
          Serial.println("failed to load json config");
        }
        configFile.close();
      }
    }
  }
  else
  {
    Serial.println("failed to mount FS");
  }
  // 添加WiFi管理参数

  wm.setSaveConfigCallback(configSaveCallback);

  wm.setAPCallback(configModeCallback);

  // wm.setConfigResetCallback(configSaveCallback);
  IPAddress ip(192, 168, 145, 1);
  IPAddress gateway(192, 168, 145, 1);
  IPAddress subnet(255, 255, 255, 0);

  wm.setAPStaticIPConfig(ip, gateway, subnet);
  wm.setConnectTimeout(120);
  wm.addParameter(&custom_SERVER_IP);
  wm.addParameter(&custom_SERVER_PORT);

  if (!wm.autoConnect("ESP32-AP"))
  {
    Serial.println("failed to connect and hit timeout");
    delay(3000);
    ESP.restart();
    delay(5000);
  }
  Serial.println("Init Config Wifi");
  strcpy(SERVER_IP, custom_SERVER_IP.getValue());
  strcpy(SERVER_PORT, custom_SERVER_PORT.getValue());
  Serial.println("The values in the file are: ");
  Serial.println("\tSERVER_IP : " + String(SERVER_IP));
  Serial.println("\tSERVER_PORT : " + String(SERVER_PORT));

  if (shouldSaveConfig)
  {
    Serial.println("saving config");
#if defined(ARDUINOJSON_VERSION_MAJOR) && ARDUINOJSON_VERSION_MAJOR >= 6
    //DynamicJsonDocument json(1024);
    JsonDocument json;
#else
    DynamicJsonBuffer jsonBuffer;
    JsonObject &json = jsonBuffer.createObject();
#endif
    json["SERVER_IP"] = SERVER_IP;
    json["SERVER_PORT"] = SERVER_PORT;

    File configFile = SPIFFS.open("/config.json", "w");
    if (!configFile)
    {
      Serial.println("failed to open config file for writing");
    }

#if defined(ARDUINOJSON_VERSION_MAJOR) && ARDUINOJSON_VERSION_MAJOR >= 6
    serializeJson(json, Serial);
    serializeJson(json, configFile);
#else
    json.printTo(Serial);
    json.printTo(configFile);
#endif
    configFile.close();
  }

  Serial.println("local ip");
  Serial.println(WiFi.localIP());
  WiFi.onEvent(wifiEvent);
}

void configSaveCallback() {
  strcpy(SERVER_IP, custom_SERVER_IP.getValue());
  strcpy(SERVER_PORT, custom_SERVER_PORT.getValue());
  Serial.println("The values in the file are: ");
  Serial.println("\tSERVER_IP : " + String(SERVER_IP));
  Serial.println("\tSERVER_PORT : " + String(SERVER_PORT));

  /* if (shouldSaveConfig)
  {
    Serial.println("saving config");
#if defined(ARDUINOJSON_VERSION_MAJOR) && ARDUINOJSON_VERSION_MAJOR >= 6
    //DynamicJsonDocument json(1024);
    JsonDocument json;
#else
    DynamicJsonBuffer jsonBuffer;
    JsonObject &json = jsonBuffer.createObject();
#endif
    json["SERVER_IP"] = SERVER_IP;
    json["SERVER_PORT"] = SERVER_PORT;

    File configFile = SPIFFS.open("/config.json", "w");
    if (!configFile)
    {
      Serial.println("failed to open config file for writing");
    }

#if defined(ARDUINOJSON_VERSION_MAJOR) && ARDUINOJSON_VERSION_MAJOR >= 6
    serializeJson(json, Serial);
    serializeJson(json, configFile);
#else
    json.printTo(Serial);
    json.printTo(configFile);
#endif
    configFile.close();
  } */
    Serial.println("Config Saved");
    Serial.println("Should save config");
    shouldSaveConfig = true;
}
void setup()
{

    Serial.begin(115200);
    Serial.println("\n Starting");
    initWifi();

    pinMode(TRIGGER_PIN, INPUT);

    pinMode(MUTEPIN, OUTPUT);
    digitalWrite(MUTEPIN, LOW);

    audioSampler = new AudioSampler();
    TaskHandle_t transmitHandle;
    xTaskCreate(transmitTask, "transmitTask", 10240, audioSampler, 1,
                &transmitHandle);
    audioSampler->start(i2sConfig, i2SPinConfig, 2048, transmitHandle);
    touchAttachInterrupt(T0, muteTouch, TOUCH_THRESHOLD);
    inited = true;
}

void loop()
{

  /* if (digitalRead(TRIGGER_PIN) == HIGH)
  {
    Serial.println("Triggered");
    Serial.println(String(digitalRead(TRIGGER_PIN)));
    // wm.addParameter(&custom_SERVER_IP);
    // wm.addParameter(&custom_SERVER_PORT);
    delay(50);

    if (!wm.startConfigPortal("OnDemandAP"))
    {

      Serial.println("failed to connect and hit timeout");
      delay(3000);
      ESP.restart();
      delay(5000);
    }

    Serial.println("connected...yeey :)");
  } */
}

#END

Debug Messages

[ 18356][E][WebServer.cpp:638] _handleRequest(): request handler not found

tablatronix commented 3 months ago

I have never figured out what this is, I have seen it mentioned in the esp repo also with the same question