Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
qthing
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jens Nolte
qthing
Commits
48d39c9c
Commit
48d39c9c
authored
6 years ago
by
fxk8y
Browse files
Options
Downloads
Patches
Plain Diff
add ota handlerqueue
parent
d908902c
No related branches found
No related tags found
1 merge request
!1
Feature/mqtt ota
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
main/mqtt_ota.cpp
+55
-2
55 additions, 2 deletions
main/mqtt_ota.cpp
main/mqtt_ota.h
+1
-0
1 addition, 0 deletions
main/mqtt_ota.h
main/qthing.h
+13
-1
13 additions, 1 deletion
main/qthing.h
with
69 additions
and
3 deletions
main/mqtt_ota.cpp
+
55
−
2
View file @
48d39c9c
...
@@ -9,11 +9,14 @@
...
@@ -9,11 +9,14 @@
#define TAG "MQTT_OTA"
#define TAG "MQTT_OTA"
void
default_ota_event
(
ota_event_t
event
);
ota_callback_t
ota_handler
=
default_ota_event
;
esp_ota_handle_t
ota_handle
=
0
;
esp_ota_handle_t
ota_handle
=
0
;
const
esp_partition_t
*
partition
=
NULL
;
const
esp_partition_t
*
partition
=
NULL
;
void
handle_ota_message
(
const
multipart_message_t
&
message
)
{
void
handle_ota_message
(
const
multipart_message_t
&
message
)
{
ESP_LOG
I
(
TAG
,
"length=%d offset=%d"
,
message
.
length
,
message
.
offset
);
ESP_LOG
D
(
TAG
,
"length=%d offset=%d"
,
message
.
length
,
message
.
offset
);
esp_err_t
err
;
esp_err_t
err
;
...
@@ -21,18 +24,68 @@ void handle_ota_message(const multipart_message_t& message) {
...
@@ -21,18 +24,68 @@ void handle_ota_message(const multipart_message_t& message) {
partition
=
esp_ota_get_next_update_partition
(
NULL
);
partition
=
esp_ota_get_next_update_partition
(
NULL
);
err
=
esp_ota_begin
(
partition
,
message
.
total_length
,
&
ota_handle
);
err
=
esp_ota_begin
(
partition
,
message
.
total_length
,
&
ota_handle
);
if
(
err
!=
ESP_OK
)
ESP_LOGW
(
TAG
,
"BEGIN OTA FAILED!"
);
if
(
err
!=
ESP_OK
)
ESP_LOGW
(
TAG
,
"BEGIN OTA FAILED!"
);
ota_event_t
event
=
{
.
state
=
start
,
.
error
=
err
,
.
bytes_written
=
0
,
.
bytes_total
=
(
uint32_t
)
message
.
total_length
};
ota_handler
(
event
);
}
}
err
=
esp_ota_write
(
ota_handle
,
(
const
void
*
)
message
.
payload
,
message
.
length
);
err
=
esp_ota_write
(
ota_handle
,
(
const
void
*
)
message
.
payload
,
message
.
length
);
if
(
err
!=
ESP_OK
)
ESP_LOGW
(
TAG
,
"WRITE OTA FAILED!"
);
if
(
err
!=
ESP_OK
)
ESP_LOGW
(
TAG
,
"WRITE OTA FAILED!"
);
ota_event_t
event
=
{
.
state
=
progress
,
.
error
=
err
,
.
bytes_written
=
(
uint32_t
)(
message
.
length
+
message
.
offset
),
.
bytes_total
=
(
uint32_t
)
message
.
total_length
};
ota_handler
(
event
);
if
(
message
.
offset
+
message
.
length
==
message
.
total_length
)
{
// last ota message
if
(
message
.
offset
+
message
.
length
==
message
.
total_length
)
{
// last ota message
err
=
esp_ota_end
(
ota_handle
);
err
=
esp_ota_end
(
ota_handle
);
if
(
err
!=
ESP_OK
)
ESP_LOGW
(
TAG
,
"END OTA FAILED!"
);
if
(
err
!=
ESP_OK
)
ESP_LOGW
(
TAG
,
"END OTA FAILED!"
);
ota_event_t
event
=
{
.
state
=
success
,
.
error
=
err
,
.
bytes_written
=
(
uint32_t
)
message
.
total_length
,
.
bytes_total
=
(
uint32_t
)
message
.
total_length
};
ota_handler
(
event
);
err
=
esp_ota_set_boot_partition
(
partition
);
err
=
esp_ota_set_boot_partition
(
partition
);
if
(
err
!=
ESP_OK
)
ESP_LOGW
(
TAG
,
"FINALIZE OTA FAILED!"
);
if
(
err
!=
ESP_OK
)
ESP_LOGW
(
TAG
,
"FINALIZE OTA FAILED!"
);
esp_restart
();
}
}
}
}
void
default_ota_event
(
ota_event_t
event
)
{
switch
(
event
.
state
)
{
case
start
:
ESP_LOGI
(
TAG
,
"OTA Start"
);
break
;
case
progress
:
{
float
pct
=
((
float
)
event
.
bytes_written
/
(
float
)
event
.
bytes_total
)
*
100
;
ESP_LOGI
(
TAG
,
"OTA Progress %d%% (%d/%d KiB)"
,
(
int
)
pct
,
event
.
bytes_written
/
1024
,
event
.
bytes_total
/
1024
);
break
;
}
case
success
:
ESP_LOGI
(
TAG
,
"OTA Successful"
);
break
;
case
error
:
ESP_LOGW
(
TAG
,
"OTA Error 0x%x"
,
event
.
error
);
break
;
}
}
void
add_ota_callback
(
ota_callback_t
handler
)
{
ota_callback_t
old_ota_handler
=
ota_handler
;
ota_handler
=
[
old_ota_handler
,
handler
](
ota_event_t
event
){
old_ota_handler
(
event
);
handler
(
event
);
};
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
main/mqtt_ota.h
+
1
−
0
View file @
48d39c9c
...
@@ -5,5 +5,6 @@
...
@@ -5,5 +5,6 @@
void
handle_ota_message
(
const
multipart_message_t
&
message
);
void
handle_ota_message
(
const
multipart_message_t
&
message
);
void
add_ota_callback
(
ota_callback_t
handler
);
#endif
#endif
This diff is collapsed.
Click to expand it.
main/qthing.h
+
13
−
1
View file @
48d39c9c
...
@@ -20,7 +20,17 @@ typedef struct {
...
@@ -20,7 +20,17 @@ typedef struct {
const
uint32_t
total_length
;
const
uint32_t
total_length
;
}
multipart_message_t
;
}
multipart_message_t
;
typedef
std
::
function
<
void
(
multipart_message_t
)
>
binary_message_callback_t
;
// content, length, offset
typedef
std
::
function
<
void
(
multipart_message_t
)
>
binary_message_callback_t
;
enum
ota_state_t
{
start
,
progress
,
success
,
error
};
typedef
struct
{
const
ota_state_t
state
;
const
esp_err_t
error
;
const
uint32_t
bytes_written
;
const
uint32_t
bytes_total
;
}
ota_event_t
;
typedef
std
::
function
<
void
(
ota_event_t
)
>
ota_callback_t
;
// network
// network
void
enable_wlan
();
void
enable_wlan
();
...
@@ -28,6 +38,8 @@ void enable_wlan();
...
@@ -28,6 +38,8 @@ void enable_wlan();
// mqtt
// mqtt
void
publish_message
(
const
std
::
string
&
topic
,
const
std
::
string
&
message
);
void
publish_message
(
const
std
::
string
&
topic
,
const
std
::
string
&
message
);
void
add_message_callback
(
const
std
::
string
&
topic
,
message_callback_t
callback
);
void
add_message_callback
(
const
std
::
string
&
topic
,
message_callback_t
callback
);
void
add_binary_message_callback
(
const
std
::
string
&
topic
,
binary_message_callback_t
callback
);
void
add_ota_callback
(
ota_callback_t
handler
);
// common IO
// common IO
void
enable_oled
();
void
enable_oled
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment