Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
QWFLS
arduino-esp32
提交
7e9afe8c
A
arduino-esp32
项目概览
QWFLS
/
arduino-esp32
与 Fork 源项目一致
从无法访问的项目Fork
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
arduino-esp32
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
7e9afe8c
编写于
11月 27, 2018
作者:
J
Jeroen88
提交者:
Me No Dev
11月 27, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add response headers with sketch and flash sizes, and a SHA256 (#2116)
上级
dcb007a4
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
43 addition
and
9 deletion
+43
-9
libraries/HTTPUpdate/src/HTTPUpdate.cpp
libraries/HTTPUpdate/src/HTTPUpdate.cpp
+43
-9
未找到文件。
libraries/HTTPUpdate/src/HTTPUpdate.cpp
浏览文件 @
7e9afe8c
...
...
@@ -26,6 +26,9 @@
#include "HTTPUpdate.h"
#include <StreamString.h>
#include <esp_partition.h>
#include <esp_ota_ops.h> // get running partition
// To do extern "C" uint32_t _SPIFFS_start;
// To do extern "C" uint32_t _SPIFFS_end;
...
...
@@ -121,6 +124,32 @@ String HTTPUpdate::getLastErrorString(void)
}
String
getSketchSHA256
()
{
const
size_t
HASH_LEN
=
32
;
// SHA-256 digest length
uint8_t
sha_256
[
HASH_LEN
]
=
{
0
};
// get sha256 digest for running partition
if
(
esp_partition_get_sha256
(
esp_ota_get_running_partition
(),
sha_256
)
==
0
)
{
char
buffer
[
2
*
HASH_LEN
+
1
];
for
(
size_t
index
=
0
;
index
<
HASH_LEN
;
index
++
)
{
uint8_t
nibble
=
(
sha_256
[
index
]
&
0xf0
)
>>
4
;
buffer
[
2
*
index
]
=
nibble
<
10
?
char
(
nibble
+
'0'
)
:
char
(
nibble
-
10
+
'A'
);
nibble
=
sha_256
[
index
]
&
0x0f
;
buffer
[
2
*
index
+
1
]
=
nibble
<
10
?
char
(
nibble
+
'0'
)
:
char
(
nibble
-
10
+
'A'
);
}
buffer
[
2
*
HASH_LEN
]
=
'\0'
;
return
String
(
buffer
);
}
else
{
return
String
();
}
}
/**
*
* @param http HTTPClient *
...
...
@@ -139,10 +168,15 @@ HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient& http, const String& curren
http
.
addHeader
(
F
(
"Cache-Control"
),
F
(
"no-cache"
));
http
.
addHeader
(
F
(
"x-ESP32-STA-MAC"
),
WiFi
.
macAddress
());
http
.
addHeader
(
F
(
"x-ESP32-AP-MAC"
),
WiFi
.
softAPmacAddress
());
// To do
http.addHeader(F("x-ESP32-free-space"), String(ESP.getFreeSketchSpace()));
// To do
http.addHeader(F("x-ESP32-sketch-size"), String(ESP.getSketchSize()));
http
.
addHeader
(
F
(
"x-ESP32-free-space"
),
String
(
ESP
.
getFreeSketchSpace
()));
http
.
addHeader
(
F
(
"x-ESP32-sketch-size"
),
String
(
ESP
.
getSketchSize
()));
// To do http.addHeader(F("x-ESP32-sketch-md5"), String(ESP.getSketchMD5()));
// To do http.addHeader(F("x-ESP32-chip-size"), String(ESP.getFlashChipRealSize()));
// Sketch MD5 is not supported by the core, but SHA256 is, so add a SHA256 instead
String
sketchSHA256
=
getSketchSHA256
();
if
(
sketchSHA256
.
length
()
!=
0
)
{
http
.
addHeader
(
F
(
"x-ESP32-sketch-sha256"
),
sketchSHA256
);
}
http
.
addHeader
(
F
(
"x-ESP32-chip-size"
),
String
(
ESP
.
getFlashChipSize
()));
http
.
addHeader
(
F
(
"x-ESP32-sdk-version"
),
ESP
.
getSdkVersion
());
if
(
spiffs
)
{
...
...
@@ -183,8 +217,8 @@ HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient& http, const String& curren
}
log_d
(
"ESP32 info:
\n
"
);
// To do
log_d(" - free Space: %d\n", ESP.getFreeSketchSpace());
// To do
log_d(" - current Sketch Size: %d\n", ESP.getSketchSize());
log_d
(
" - free Space: %d
\n
"
,
ESP
.
getFreeSketchSpace
());
log_d
(
" - current Sketch Size: %d
\n
"
,
ESP
.
getSketchSize
());
if
(
currentVersion
&&
currentVersion
[
0
]
!=
0x00
)
{
log_d
(
" - current version: %s
\n
"
,
currentVersion
.
c_str
()
);
...
...
@@ -201,10 +235,10 @@ HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient& http, const String& curren
// To do startUpdate = false;
// To do }
}
else
{
// To do
if(len > (int) ESP.getFreeSketchSpace()) {
// To do
log_e("FreeSketchSpace to low (%d) needed: %d\n", ESP.getFreeSketchSpace(), len);
// To do
startUpdate = false;
// To do
}
if
(
len
>
(
int
)
ESP
.
getFreeSketchSpace
())
{
log_e
(
"FreeSketchSpace to low (%d) needed: %d
\n
"
,
ESP
.
getFreeSketchSpace
(),
len
);
startUpdate
=
false
;
}
}
if
(
!
startUpdate
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录