使用ESP32网络服务器下载文件时遇到问题

如何解决使用ESP32网络服务器下载文件时遇到问题

我正在使用带有Arduino框架的PlatformIO为ESP32(16MB)开发代码,在ESP32上,我同时使用了蓝牙和Wi-Fi连接。当Mobile App与ESP32的蓝牙连接时,将使用BLE特性的蓝牙在手机上发送数据(工作正常),并且当蓝牙未连接时,数据将记录在.json文件中(为此使用了SPIFFS库和文件创建功能)工作正常)。当用户想获取日志数据时,ESP32会创建Wi-Fi接入点(AP)(用过的WiFi.h),通过连接该AP,用户应该能够通过访问链接“ 192.168.4.1/download”下载.json文件。在浏览器上。将文件下载到Mobile App后,用户将访问链接“ 192.168.4.1/finisheddownload”,文件将从ESP32中删除。

成功连接到ESP32的AP后,虽然我从浏览器访问链接“ 192.168.4.1/download”,但此时代码卡住了,或者有时它重新启动了ESP32,并且什么也不起作用,如果我访问“ 192.168.4.1/完成下载”,它将成功删除文件。我的文件大小约为10MB,但是即使我在文件大小为1KB时执行此操作,其行为也一样。我已经在ESP32(4MB)模块上测试了相同的代码,并且能够下载大约50KB的文件。

我不确定是我使用的内存或库问题还是ESP32的限制。我将代码片段与我使用的内存分区一起附加,请指导。

访问文件下载链接后ESP32重启时出现错误:

在核心1的PC 0x401d844b上调用了

abort()

回溯:0x40092b60:0x3ffcf8e0 0x40092d91:0x3ffcf900 0x401d844b:0x3ffcf920 0x401d8492:0x3ffcf940 0x401bf359:0x3ffcf960 0x401bf0dc:0x3ffcf980 0x400fa67e:0x3ffcf9a0 0x400fa75a:0x3ffcf9d0 0x400e62b9:0x3ffcf9f0 0x400d23e4:0x3ffcfa20 0x400d27e3:0x3ffcfa40 0x400d2ed7:0x3ffcfa70 0x400d35f1:0x3ffcfa90 0x400e9151:0x3ffcfb10 0x4008f275:0x3ffcfb30

正在重新启动...

rst:0xc(SW_CPU_RESET),启动:0x13(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 模式:DIO,时钟分频:2 负载:0x3fff0018,len:4 加载:0x3fff001c,len:1044 加载:0x40078000,len:8896 加载:0x40080400,len:5828 条目0x400806ac

代码段:

void downloadfile(){                                       //function to download file on mobile App
  delay(500);
  do{
   BLEAdvertising *pAdvertising = pServer->getAdvertising();
   pAdvertising->stop();
   if(!SPIFFS.begin()){
        Serial.println("An Error has occurred while mounting SPIFFS");
        return;
   }
  WiFi.mode(WIFI_AP); 
  delay(100);
  Serial.print("Setting soft-AP ... ");
  Serial.println(WiFi.softAP("ESP32","123456789") ? "Ready" : "Failed!");
  Serial.print("Soft-AP IP address = ");
  Serial.println(WiFi.softAPIP());
  delay(100);
  // send a file when /download is requested
  server.on("/download",HTTP_ANY,[](AsyncWebServerRequest *request){
     request->send(SPIFFS,"/file1.json","text/plain",true);
  });
  server.on("/finisheddownload",HTTP_GET,[](AsyncWebServerRequest *request){
    logfile.del_file();
    request->send(200,"text/html","Download complete response");
    delay(500);
    Actual_filexist = 0;
    WiFi.softAPdisconnect(true);
    BLEAdvertising *pAdvertising = pServer->getAdvertising();
    pAdvertising->start();
    delay(500);
  });  
  server.begin();
  delay(500);
 }while(Actual_filexist == 1);
}

内存分区: #name类型子类型偏移大小标志 nvs数据nvs 0x9000 0x7000 app0 app ota_0 0x10000 0x2A0000
eeprom数据0x99 0x2F0000 0x1A8CE0 扩散数据扩散0x498CE0 0xA7D8C0

内存使用情况: RAM:[==] 19.9%(从327680字节使用了65292字节) Flash:[======] 60.1%(使用了2752512字节中的1654361字节)

谢谢。...

解决方法

您正在使用ESPAsyncWebServer。其文档明确指出,您不应调用delay()yield()或任何从Web服务器在回调中调用它们的函数(Important things to rememberdelay()处理程序。

您还要在处理程序可以返回之前在处理程序中调用/finisheddownload,这意味着您要在回调返回之前以及可能在响应发送到浏览器之前关闭Wifi。在回调中执行此操作并不安全。

您需要在Web服务器的回调中尽可能少地做。重写该处理程序以设置WiFi.softAPdisconnect()将检查的标志,以便除对loop()的调用外,它所做的所有工作实际上都在request->send()中完成。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 <select id="xxx"> SELECT di.id, di.name, di.work_type, di.updated... <where> <if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 <property name="dynamic.classpath" value="tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams['font.sans-serif'] = ['SimHei'] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -> systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping("/hires") public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate<String
使用vite构建项目报错 C:\Users\ychen\work>npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-