Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
http
ota在线升级
Webclient
使用webclient 的 http OTA 升级文件如何查询服务器文件是否存在?
发布于 2023-09-20 16:36:05 浏览:910
订阅该版
大家好,请问下,我使用webclient http协议更新程序,在服务器不存在的文件,也能下载文件问题,如何查询服务器文件是否存在呢,如果不存在就不需要执行升级了,我看了webclient相关API没有读这些相关的函数。是不是http不支持这个功能吗? 部分代码如下: ``` int ret = RT_EOK; struct webclient_session* session = RT_NULL; /* create webclient session and set header response size */ session = webclient_session_create(GET_HEADER_BUFSZ); if (!session) { LOG_E("open uri failed."); ret = -RT_ERROR; goto __exit; } /* get the real data length */ webclient_shard_head_function(session, uri, &file_size); if (file_size == 0) { LOG_E("Request file size is 0!"); ret = -RT_ERROR; goto __exit; } else if (file_size < 0) { LOG_E("webclient GET request type is chunked."); ret = -RT_ERROR; goto __exit; } LOG_I("OTA file size is (%d)", file_size); LOG_I("\033[1A"); /* Get download partition information and erase download partition data */ if ((dl_part = fal_partition_find(partition)) == RT_NULL) { LOG_E("Firmware download failed! Partition (%s) find error!", "download"); ret = -RT_ERROR; goto __exit; } LOG_I("Start erase flash (%s) partition!", dl_part->name); if (fal_partition_erase(dl_part, 0, file_size) < 0) { LOG_E("Firmware download failed! Partition (%s) erase error!", dl_part->name); ret = -RT_ERROR; goto __exit; } LOG_I("Erase flash (%s) partition success!", dl_part->name); /* register the handle function, you can handle data in the function */ webclient_register_shard_position_function(session, http_ota_shard_download_handle); /* the "memory size" that you can provide in the project and uri */ ret = webclient_shard_position_function(session, uri, begin_offset, file_size, HTTP_OTA_BUFF_LEN); /* clear the handle function */ webclient_register_shard_position_function(session, RT_NULL); ```
查看更多
wxfjog
2023-09-21
这家伙很懒,什么也没写!
感谢各位应答,摸索了下,发现程序已经自带有应答状态返回了,稍利用一下就解决了,session->resp_status 这个就是应答状态码主要有以下代码: 200 OK //客户端请求成功 206 Partial Content //服务器已经成功处理了部分 GET 请求 400 Bad Request //客户端请求有语法错误,不能被服务器所理解 403 Forbidden //服务器收到请求,但是拒绝提供服务 404 Not Found //请求资源不存在,eg:输入了错误的URL 500 Internal Server Error //服务器发生不可预期的错误 503 Server Unavailable //服务器当前不能处理客户端的请求 , 我主要是判断文件是否存在,因此判断404这个状态码就可以,在函数webclient_shard_head_function()之后加上以下判断代码即可。 if(session->resp_status == 404) { LOG_E("not found the file"); ret = -RT_ERROR; goto __exit; } 修改后部分代码如下: static int http_ota_fw_download(char* partition, const char* uri) { int ret = RT_EOK; struct webclient_session* session = RT_NULL; int hstate; /* create webclient session and set header response size */ session = webclient_session_create(GET_HEADER_BUFSZ); if (!session) { LOG_E("open uri failed."); ret = -RT_ERROR; goto __exit; } /* get the real data length */ webclient_shard_head_function(session, uri, &file_size); if(session->resp_status == 404) { LOG_E("not found the file"); ret = -RT_ERROR; goto __exit; } if (file_size == 0) { LOG_E("OTA file size is 0"); ret = -RT_ERROR; goto __exit; } else if (file_size < 0) { LOG_E("webclient GET request type is chunked."); ret = -RT_ERROR; goto __exit; } LOG_I("OTA file size is (%d)", file_size); LOG_I("\033[1A"); 修改后效果: ![效果图.jpg](https://oss-club.rt-thread.org/uploads/20230921/da2b1433ef836f17fcc5f8c7c16ecabd.jpg)
4
个回答
默认排序
按发布时间排序
梦笑真美
2023-09-20
这家伙很懒,什么也没写!
HTTP响应header消息会有信息内容的吧,打印出来看看
道友
2023-09-20
这家伙很懒,什么也没写!
DownloadFile不可以吗?
CrazyH
2023-09-21
这家伙很懒,什么也没写!
让服务器直接404就行了
撰写答案
登录
注册新账号
关注者
0
被浏览
910
关于作者
wxfjog
这家伙很懒,什么也没写!
提问
16
回答
12
被采纳
3
关注TA
发私信
相关问题
1
OTA 片上FLASH擦除失败
2
请教一下用私有协议数据包进行OTA的具体的实现流程
3
OTA跳转后基于RTT的app运行失败
4
使用finsh 进行ota成功,线程里开ota失败
5
http_ota 每次下载一半就断线
6
bootloader跳转到app无法正常运行
7
针对腾讯云IOT的软件包OTAbug功能反馈
8
自己写的bootloader无法正常升级基于RTT的程序
9
OTA升级,APP程序下载问题
10
bootloader下载APP后不能正常跳转
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
最新文章
1
RTT 源码分析笔记——互斥量篇
2
[E/app.filesystem] SD card mount to '/sdcard' failed!
3
单片机也能聊天?RT-Thread上跑通大语言模型
4
【RT-Thread】【ci】【scons】将ci.attachconfig.yml和scons结合使用
5
Rt-thread中OTA下载后,bootloader不搬程序
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
FinSH
ART-Pi
DMA
USB
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
FAL
rt-smart
I2C_IIC
ESP8266
UART
WIZnet_W5500
ota在线升级
cubemx
PWM
flash
freemodbus
BSP
packages_软件包
潘多拉开发板_Pandora
定时器
ADC
flashDB
GD32
socket
编译报错
中断
Debug
rt_mq_消息队列_msg_queue
keil_MDK
SFUD
msh
ulog
C++_cpp
MicroPython
本月问答贡献
出出啊
1518
个答案
343
次被采纳
小小李sunny
1444
个答案
290
次被采纳
张世争
813
个答案
177
次被采纳
crystal266
549
个答案
161
次被采纳
whj467467222
1222
个答案
149
次被采纳
本月文章贡献
出出啊
1
篇文章
3
次点赞
小小李sunny
1
篇文章
1
次点赞
张世争
1
篇文章
3
次点赞
crystal266
2
篇文章
2
次点赞
whj467467222
2
篇文章
2
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部