code sanitization
This commit is contained in:
parent
05b446dbef
commit
25d307e820
@ -26,7 +26,7 @@ description = Paxcounter is a proof-of-concept ESP32 device for metering passeng
|
|||||||
|
|
||||||
[common]
|
[common]
|
||||||
; for release_version use max. 10 chars total, use any decimal format like "a.b.c"
|
; for release_version use max. 10 chars total, use any decimal format like "a.b.c"
|
||||||
release_version = 1.5.3
|
release_version = 1.5.4
|
||||||
; DEBUG LEVEL: For production run set to 0, otherwise device will leak RAM while running!
|
; DEBUG LEVEL: For production run set to 0, otherwise device will leak RAM while running!
|
||||||
; 0=None, 1=Error, 2=Warn, 3=Info, 4=Debug, 5=Verbose
|
; 0=None, 1=Error, 2=Warn, 3=Info, 4=Debug, 5=Verbose
|
||||||
debug_level = 0
|
debug_level = 0
|
||||||
|
@ -6,7 +6,11 @@
|
|||||||
// Local logging tag
|
// Local logging tag
|
||||||
static const char TAG[] = "main";
|
static const char TAG[] = "main";
|
||||||
|
|
||||||
void IRAM_ATTR ButtonIRQ() { ButtonPressedIRQ++; }
|
void IRAM_ATTR ButtonIRQ() {
|
||||||
|
portENTER_CRITICAL(&timerMux);
|
||||||
|
ButtonPressedIRQ++;
|
||||||
|
portEXIT_CRITICAL(&timerMux);
|
||||||
|
}
|
||||||
|
|
||||||
void readButton() {
|
void readButton() {
|
||||||
if (ButtonPressedIRQ) {
|
if (ButtonPressedIRQ) {
|
||||||
|
68
src/ota.cpp
68
src/ota.cpp
@ -35,23 +35,9 @@ volatile bool isValidContentType = false;
|
|||||||
// Local logging tag
|
// Local logging tag
|
||||||
static const char TAG[] = "main";
|
static const char TAG[] = "main";
|
||||||
|
|
||||||
void display(const uint8_t row, std::string status, std::string msg) {
|
// helper function to extract header value from header
|
||||||
#ifdef HAS_DISPLAY
|
inline String getHeaderValue(String header, String headerName) {
|
||||||
u8x8.setCursor(14, row);
|
return header.substring(strlen(headerName.c_str()));
|
||||||
u8x8.print((status.substr(0, 2)).c_str());
|
|
||||||
if (!msg.empty()) {
|
|
||||||
u8x8.clearLine(7);
|
|
||||||
u8x8.setCursor(0, 7);
|
|
||||||
u8x8.print(msg.substr(0, 16).c_str());
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
// callback function to show download progress while streaming data
|
|
||||||
void show_progress(size_t current, size_t size) {
|
|
||||||
char buf[17];
|
|
||||||
snprintf(buf, 17, "%-9lu (%3lu%%)", current, current*100 / size);
|
|
||||||
display(4, "**", buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void start_ota_update() {
|
void start_ota_update() {
|
||||||
@ -99,7 +85,7 @@ void start_ota_update() {
|
|||||||
if (i >= 0) {
|
if (i >= 0) {
|
||||||
ESP_LOGI(TAG, "Connected to %s", WIFI_SSID);
|
ESP_LOGI(TAG, "Connected to %s", WIFI_SSID);
|
||||||
display(1, "OK", "WiFi connected");
|
display(1, "OK", "WiFi connected");
|
||||||
checkFirmwareUpdates(); // gets and flashes new firmware
|
do_ota_update(); // gets and flashes new firmware
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGI(TAG, "Could not connect to %s, rebooting.", WIFI_SSID);
|
ESP_LOGI(TAG, "Could not connect to %s, rebooting.", WIFI_SSID);
|
||||||
display(1, " E", "no WiFi connect");
|
display(1, " E", "no WiFi connect");
|
||||||
@ -121,7 +107,10 @@ void start_ota_update() {
|
|||||||
|
|
||||||
} // start_ota_update
|
} // start_ota_update
|
||||||
|
|
||||||
void checkFirmwareUpdates() {
|
|
||||||
|
void do_ota_update() {
|
||||||
|
char buf[17];
|
||||||
|
|
||||||
// Fetch the latest firmware version
|
// Fetch the latest firmware version
|
||||||
ESP_LOGI(TAG, "Checking latest firmware version on server...");
|
ESP_LOGI(TAG, "Checking latest firmware version on server...");
|
||||||
display(2, "**", "checking version");
|
display(2, "**", "checking version");
|
||||||
@ -140,24 +129,10 @@ void checkFirmwareUpdates() {
|
|||||||
}
|
}
|
||||||
ESP_LOGI(TAG, "New firmware version v%s available. Downloading...",
|
ESP_LOGI(TAG, "New firmware version v%s available. Downloading...",
|
||||||
latest.c_str());
|
latest.c_str());
|
||||||
display(2, "OK", "");
|
display(2, "OK", latest.c_str());
|
||||||
|
|
||||||
processOTAUpdate(latest);
|
display(3, "**", "");
|
||||||
}
|
String firmwarePath = bintray.getBinaryPath(latest);
|
||||||
|
|
||||||
// helper function to extract header value from header
|
|
||||||
inline String getHeaderValue(String header, String headerName) {
|
|
||||||
return header.substring(strlen(headerName.c_str()));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* OTA update processing
|
|
||||||
*/
|
|
||||||
void processOTAUpdate(const String &version) {
|
|
||||||
|
|
||||||
char buf[17];
|
|
||||||
display(3, "**", "requesting file");
|
|
||||||
String firmwarePath = bintray.getBinaryPath(version);
|
|
||||||
if (!firmwarePath.endsWith(".bin")) {
|
if (!firmwarePath.endsWith(".bin")) {
|
||||||
ESP_LOGI(TAG, "Unsupported binary format, OTA update cancelled.");
|
ESP_LOGI(TAG, "Unsupported binary format, OTA update cancelled.");
|
||||||
display(3, " E", "file type error");
|
display(3, " E", "file type error");
|
||||||
@ -327,6 +302,25 @@ void processOTAUpdate(const String &version) {
|
|||||||
ESP_LOGI(TAG,
|
ESP_LOGI(TAG,
|
||||||
"OTA update failed. Rebooting to runmode with current version.");
|
"OTA update failed. Rebooting to runmode with current version.");
|
||||||
client.stop();
|
client.stop();
|
||||||
|
} // do_ota_update
|
||||||
|
|
||||||
|
void display(const uint8_t row, std::string status, std::string msg) {
|
||||||
|
#ifdef HAS_DISPLAY
|
||||||
|
u8x8.setCursor(14, row);
|
||||||
|
u8x8.print((status.substr(0, 2)).c_str());
|
||||||
|
if (!msg.empty()) {
|
||||||
|
u8x8.clearLine(7);
|
||||||
|
u8x8.setCursor(0, 7);
|
||||||
|
u8x8.print(msg.substr(0, 16).c_str());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// callback function to show download progress while streaming data
|
||||||
|
void show_progress(size_t current, size_t size) {
|
||||||
|
char buf[17];
|
||||||
|
snprintf(buf, 17, "%-9lu (%3lu%%)", current, current*100 / size);
|
||||||
|
display(4, "**", buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper function to compare two versions. Returns 1 if v2 is
|
// helper function to compare two versions. Returns 1 if v2 is
|
||||||
|
@ -8,10 +8,10 @@
|
|||||||
#include <BintrayClient.h>
|
#include <BintrayClient.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
void checkFirmwareUpdates();
|
void do_ota_update();
|
||||||
void processOTAUpdate(const String &version);
|
|
||||||
void start_ota_update();
|
void start_ota_update();
|
||||||
int version_compare(const String v1, const String v2);
|
int version_compare(const String v1, const String v2);
|
||||||
void show_progress(size_t current, size_t size);
|
void show_progress(size_t current, size_t size);
|
||||||
|
void display(const uint8_t row, std::string status, std::string msg);
|
||||||
|
|
||||||
#endif // OTA_H
|
#endif // OTA_H
|
||||||
|
Loading…
Reference in New Issue
Block a user