Asynchronous 已触发任务监视程序-任务未及时重置监视程序

Asynchronous 已触发任务监视程序-任务未及时重置监视程序,asynchronous,webserver,task,esp32,watchdog,Asynchronous,Webserver,Task,Esp32,Watchdog,我正在尝试编写一个小型异步Web服务器。让我简单描述一下情景: 我的ESP32也是一个路由器。因此,如果我将手机连接到WiFi中,ESP32正在传播,并通过浏览器呼叫ip地址和特殊路径,就会传送一个网站。这里显示一个按钮。在这一点上,它运行得相当好。现在,如果我点击这个按钮,一个HTTPSWeb请求(方法:GET)被发送到一台特殊的机器。这台机器应答并返回一个JSON。这可能会持续几秒钟。从JSON字符串中提取值后,应显示该值 为此,我使用以下库: WiFi.h HTTPClient.h

我正在尝试编写一个小型异步Web服务器。让我简单描述一下情景:

我的ESP32也是一个路由器。因此,如果我将手机连接到WiFi中,ESP32正在传播,并通过浏览器呼叫ip地址和特殊路径,就会传送一个网站。这里显示一个按钮。在这一点上,它运行得相当好。现在,如果我点击这个按钮,一个HTTPSWeb请求(方法:GET)被发送到一台特殊的机器。这台机器应答并返回一个JSON。这可能会持续几秒钟。从JSON字符串中提取值后,应显示该值

为此,我使用以下库:

  • WiFi.h
  • HTTPClient.h
我(通过另一个草图)知道,最后三个工作没有任何问题

不幸的是,当我单击该按钮时,以下输出显示在我的串行监视器上:

正在开始连接到服务器…
[HTTPS]开始。。。路径:
[HTTPS]获取…
E(137906)任务\u wdt:任务监视程序已触发。以下任务未及时重置看门狗:
E(137906)任务wdt:-异步tcp(CPU 0/1)
E(137906)任务\u wdt:当前正在运行的任务:
E(137906)任务wdt:CPU 0:IDLE0
E(137906)任务\u wdt:CPU 1:loopTask
E(137906)任务:正在中止。
在core 0上的PC 0x400e08af上调用了abort() 回溯:0x4008cc18:0x3ffbe170 0x4008ce49:0x3ffbe190 0x400e08af:0x3ffbe1b0 0x40084f21:0x3ffbe1d0 0x4016581b:0x3ffbc120 0x400e1c66:0x3ffbc140 0x4008ab21:0x3ffbc160 0x4008932d:0x3ffbc180

重新启动…
美国东部时间2016年6月8日00:22:57

rst:0xc(软件CPU重置),引导:0x17(SPI快速闪存引导)
配置SIP:0,SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
模式:DIO,时钟div:1
加载:0x3fff0018,长度:4
加载:0x3fff001c,长度:1044
加载:0x40078000,长度:8896
加载:0x40080400,长度:5816
条目0x400806ac
序列首字母完成

有人知道发生了什么以及如何解决吗?以便正确发送GET请求/收到答复

我用的是一个

我对每个答案都很满意,提前谢谢

致意

请允许我最后添加我的代码:

#include <heltec.h>
#include "WiFi.h"
#include "ESPAsyncWebServer.h"

#include <WiFiClientSecure.h>
#include <HTTPClient.h>
 
const char* ssid = "MyWiFiSSID";
const char* password =  "MyWiFiPW";
 
AsyncWebServer server(80);

void setup() {

  Heltec.begin(true, false, true, true, 470E6);

  WiFi.softAP(ssid, password);
  
  IPAddress IP = WiFi.softAPIP();
  Serial.print("AccessPoint IP address: ");
  Serial.println(IP);
  
  server.on("/hello", HTTP_GET, [](AsyncWebServerRequest *request){
    
    request->send(200, "text/html", "<!DOCTYPE html><html><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" charset=\"UTF-8\"><link rel=\"icon\" href=\"data:,\"><style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}.button { background-color: #4CAF50; border: none; color: white; padding: 16px 40px; text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;}</style></head><body><h1>Welcome to the Landing Page of the Web Server</h1><p><a href=\"/get_unlock_pin\"><button class=\"button\">Click Me</button></a></p></body></html>");
  });

  server.on("/get_unlock_pin", HTTP_GET, [](AsyncWebServerRequest *request){

    String firstpartofrawhtmlcode = "<!DOCTYPE html><html><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" charset=\"UTF-8\"><link rel=\"icon\" href=\"data:,\"><style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}.button { background-color: #4CAF50; border: none; color: white; padding: 16px 40px; text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;}</style></head><body><h2>Received Pin: </h2><h2 style=\"color: #FF0000\">";
    String receivedPin = getPin("192.168.4.101");
    String secondpartofrawhtmlcode = "</h2></body></html>";
    String fullrawhtmlcode;
    firstpartofrawhtmlcode = firstpartofrawhtmlcode.concat(receivedPin);
    fullrawhtmlcode = firstpartofrawhtmlcode.concat(secondpartofrawhtmlcode);
    request->send(200, "text/html", fullrawhtmlcode);
  });
 
  server.begin();
}

void loop() {

}

String getPin(String ip){
    Serial.println("\nStarting connection to server...");  
    WiFiClientSecure *wificlient = new WiFiClientSecure;

    HTTPClient https;
    https.setAuthorization("MyUserName", "MyPassword");

    String path = "https://" + ip + "/api/unlock/generate_pin";
      
    Serial.print("[HTTPS] begin... Path: " + path + "\n");
    if (https.begin(*wificlient, path)) { 
        Serial.print("[HTTPS] GET...\n");
        int httpCode = https.GET();
        if (httpCode > 0) {
          Serial.printf("[HTTPS] GET... code: %d\n", httpCode);
  
          if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
            String payload = https.getString();
            Serial.println(payload);
            //Extract Pin from JSON
            String tmp = payload.substring(payload.indexOf(':'), payload.indexOf('}'));
            String tmp2 = tmp.substring(tmp.indexOf('"')+1,tmp.lastIndexOf('"')); 
            if(tmp2.substring(0,1) == "-"){
               return "-";
            }else{
               return tmp2;
            }              
          }
        } else {
               Serial.printf("[HTTPS] GET... failed, error: %s\n", https.errorToString(httpCode).c_str());
        }  
        https.end();
    } else {
        Serial.printf("[HTTPS] Unable to connect\n");
    }
}
#包括
#包括“WiFi.h”
#包括“ESPAsyncWebServer.h”
#包括
#包括
const char*ssid=“MyWiFiSSID”;
const char*password=“MyWiFiPW”;
异步web服务器(80);
无效设置(){
Heltec.begin(真、假、真、真、470E6);
WiFi.softAP(ssid,密码);
IP地址IP=WiFi.softAPIP();
串行打印(“访问点IP地址:”);
序列号println(IP);
在(“/hello”上,HTTP_GET,[](AsyncWebServerRequest*request){
请求->发送(200,“文本/html”,“html{字体系列:Helvetica;显示:内联块;边距:0px自动;文本对齐:中心;}。按钮{背景色:#4CAF50;边框:无;颜色:白色;填充:16px 40px;文本装饰:无;字体大小:30px;边距:2px;光标:指针;}欢迎访问Web服务器的登录页

”; }); 在(“/get\u unlock\u pin”上,HTTP\u get,[](AsyncWebServerRequest*请求){ String firstpartofrawhtmlcode=“html{font-family:Helvetica;display:inlineblock;margin:0px auto;text-align:center;}.button{background color:#4CAF50;border:none;color:white;padding:16px 40px;text-decoration:none;font-size:30px;margin:2px;cursor:pointer;}接收到Pin:”; 字符串receivedPin=getPin(“192.168.4.101”); 字符串的第二部分rawhtmlcode=“”; 字符串fullrawhtmlcode; firstpartofrawhtmlcode=RawHtmlCode.concat的第一部分(receivedPin); fullrawhtmlcode=RawHtmlCode.concat的第一部分(RawHtmlCode的第二部分); 请求->发送(200,“文本/html”,fullrawhtmlcode); }); server.begin(); } void循环(){ } 字符串getPin(字符串ip){ Serial.println(“\n正在启动与服务器的连接…”); WiFiClientSecure*wificlient=新的WiFiClientSecure; HTTPClient-https; https.setAuthorization(“我的用户名”、“我的密码”); String path=“https://“+ip+”/api/unlock/generate_-pin”; Serial.print(“[HTTPS]开始…路径:“+Path+”\n”); 如果(https.begin(*wificlient,path)){ Serial.print(“[HTTPS]GET…\n”); int-httpCode=https.GET(); 如果(httpCode>0){ Serial.printf(“[HTTPS]获取…代码:%d\n”,httpCode); 如果(httpCode==HTTP_代码_确定| | httpCode==HTTP_代码_永久移动){ 字符串有效负载=https.getString(); Serial.println(有效载荷); //从JSON中提取Pin 字符串tmp=payload.substring(payload.indexOf(':')、payload.indexOf('}'); 字符串tmp2=tmp.substring(tmp.indexOf(“”)+1,tmp.lastIndexOf(“”); if(tmp2.子串(0,1)==“-”){ 返回“-”; }否则{ 返回tmp2; } } }否则{ Serial.printf(“[HTTPS]获取…失败,错误:%s\n”,HTTPS.errorToString(httpCode.c_str()); } https.end(); }否则{ Serial.printf(“[HTTPS]无法连接\n”); } }
ESPAsyncWebServer回调防止看门狗计时器在运行时重置。这意味着它们不用于进行任何实际处理。注册请求并将处理延迟到主循环(或其他线程)。看一看细节