Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
co2ampel
ampel-firmware
Commits
3a9ec97d
Commit
3a9ec97d
authored
Feb 24, 2022
by
Eric Duminil
Browse files
Trying http update. Works with HTTP on ESP8266
parent
7a296269
Pipeline
#5928
failed with stage
in 2 minutes and 10 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
ampel-firmware/sensor_console.cpp
View file @
3a9ec97d
#include "sensor_console.h"
namespace
sensor_console
{
const
uint8_t
MAX_COMMANDS
=
2
6
;
const
uint8_t
MAX_COMMANDS
=
2
7
;
//TODO: Check if it's really needed? Is it including parameter???
const
uint8_t
MAX_COMMAND_SIZE
=
40
;
...
...
ampel-firmware/wifi_util.cpp
View file @
3a9ec97d
...
...
@@ -8,6 +8,8 @@
#if defined(ESP8266)
# include <ESP8266WiFi.h>
# include <ESP8266HTTPClient.h>
# include <ESP8266httpUpdate.h>
#elif defined(ESP32)
# include <WiFi.h>
#endif
...
...
@@ -15,6 +17,50 @@
namespace
wifi
{
char
local_ip
[
16
];
// "255.255.255.255\0"
void
update_started
()
{
Serial
.
println
(
"CALLBACK: HTTP update process started"
);
}
void
update_finished
()
{
Serial
.
println
(
"CALLBACK: HTTP update process finished"
);
}
void
update_progress
(
int
cur
,
int
total
)
{
Serial
.
printf
(
"CALLBACK: HTTP update process at %d of %d bytes...
\n
"
,
cur
,
total
);
}
void
update_error
(
int
err
)
{
Serial
.
printf
(
"CALLBACK: HTTP update fatal error code %d
\n
"
,
err
);
}
void
update
()
{
ESPhttpUpdate
.
onStart
(
update_started
);
ESPhttpUpdate
.
onEnd
(
update_finished
);
ESPhttpUpdate
.
onProgress
(
update_progress
);
ESPhttpUpdate
.
onError
(
update_error
);
WiFiClient
client
;
t_httpUpdate_return
ret
=
ESPhttpUpdate
.
update
(
client
,
"http://servfbp1.fbp.hft-stuttgart.de/simstadt_doc/firmware.bin"
);
// Or:
//t_httpUpdate_return ret = ESPhttpUpdate.update(client, "server", 80, "file.bin");
//TODO: https://github.com/programmer131/ESP8266_ESP32_SelfUpdate
switch
(
ret
)
{
case
HTTP_UPDATE_FAILED
:
Serial
.
printf
(
"HTTP_UPDATE_FAILD Error (%d): %s
\n
"
,
ESPhttpUpdate
.
getLastError
(),
ESPhttpUpdate
.
getLastErrorString
().
c_str
());
break
;
case
HTTP_UPDATE_NO_UPDATES
:
Serial
.
println
(
"HTTP_UPDATE_NO_UPDATES"
);
break
;
case
HTTP_UPDATE_OK
:
Serial
.
println
(
"HTTP_UPDATE_OK"
);
break
;
}
}
bool
connected
()
{
return
WiFi
.
status
()
==
WL_CONNECTED
;
}
...
...
@@ -76,6 +122,7 @@ namespace wifi {
void
defineCommands
()
{
sensor_console
::
defineCommand
(
"wifi_scan"
,
scanNetworks
,
F
(
"(Scans available WiFi networks)"
));
sensor_console
::
defineCommand
(
"local_ip"
,
showLocalIp
,
F
(
"(Displays local IP and current SSID)"
));
sensor_console
::
defineCommand
(
"update!"
,
update
,
F
(
"(Updates to latest firmware)"
));
//TODO: Add "update!" command? https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266httpUpdate/examples/httpUpdate/httpUpdate.ino
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment