mirror of
https://github.com/jomjol/AI-on-the-edge-device.git
synced 2025-12-07 20:16:55 +03:00
Rolling 20220916
This commit is contained in:
@@ -40,6 +40,11 @@ In other cases you can contact the developer via email: <img src="https://raw.gi
|
|||||||
|
|
||||||
------
|
------
|
||||||
|
|
||||||
|
##### Rolling (2022-09-16)
|
||||||
|
|
||||||
|
- Increase precission for more than 6-7 digits (based on idea of **[stefanbode](https://github.com/stefanbode)**)
|
||||||
|
- HTML: bug fix in case of https access (**[PLCHome](https://github.com/PLCHome)**)
|
||||||
|
|
||||||
##### Rolling (2022-09-10)
|
##### Rolling (2022-09-10)
|
||||||
|
|
||||||
- Internal preparations for improved update mechanism
|
- Internal preparations for improved update mechanism
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ static char ota_write_data[BUFFSIZE + 1] = { 0 };
|
|||||||
#define OTA_URL_SIZE 256
|
#define OTA_URL_SIZE 256
|
||||||
static const char *TAGPARTOTA = "server_ota";
|
static const char *TAGPARTOTA = "server_ota";
|
||||||
|
|
||||||
|
esp_err_t handler_reboot(httpd_req_t *req);
|
||||||
|
|
||||||
|
|
||||||
static void infinite_loop(void)
|
static void infinite_loop(void)
|
||||||
{
|
{
|
||||||
@@ -388,7 +390,10 @@ esp_err_t handler_ota_update(httpd_req_t *req)
|
|||||||
gpio_handler_deinit();
|
gpio_handler_deinit();
|
||||||
if (ota_update_task(fn))
|
if (ota_update_task(fn))
|
||||||
{
|
{
|
||||||
resp_str = "Firmware Update Successfull!<br><br>You can restart now.";
|
// resp_str = "rebooting - Firmware Update Successfull!<br><br>You can restart now.";
|
||||||
|
// httpd_resp_send(req, resp_str, strlen(resp_str));
|
||||||
|
// httpd_resp_sendstr_chunk(req, NULL);
|
||||||
|
return handler_reboot(req);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -439,6 +444,8 @@ esp_err_t handler_ota_update(httpd_req_t *req)
|
|||||||
unlink(fn.c_str());
|
unlink(fn.c_str());
|
||||||
}
|
}
|
||||||
/* Respond with an empty chunk to signal HTTP response completion */
|
/* Respond with an empty chunk to signal HTTP response completion */
|
||||||
|
std::string zw = "file deleted!\n";
|
||||||
|
httpd_resp_sendstr_chunk(req, zw.c_str());
|
||||||
httpd_resp_send_chunk(req, NULL, 0);
|
httpd_resp_send_chunk(req, NULL, 0);
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ enum t_CNNType {
|
|||||||
Analogue,
|
Analogue,
|
||||||
Analogue100,
|
Analogue100,
|
||||||
Digital,
|
Digital,
|
||||||
// DigitalHyprid,
|
|
||||||
DigitalHyprid10,
|
DigitalHyprid10,
|
||||||
DoubleHyprid10,
|
DoubleHyprid10,
|
||||||
Digital100,
|
Digital100,
|
||||||
|
|||||||
@@ -33,9 +33,9 @@ struct NumberPost {
|
|||||||
bool checkDigitIncreaseConsistency;
|
bool checkDigitIncreaseConsistency;
|
||||||
time_t lastvalue;
|
time_t lastvalue;
|
||||||
string timeStamp;
|
string timeStamp;
|
||||||
float FlowRateAct; // m3 / min
|
double FlowRateAct; // m3 / min
|
||||||
float PreValue; // letzter Wert, der gut ausgelesen wurde
|
double PreValue; // letzter Wert, der gut ausgelesen wurde
|
||||||
float Value; // letzer ausgelesener Wert, inkl. Korrekturen
|
double Value; // letzer ausgelesener Wert, inkl. Korrekturen
|
||||||
string ReturnRateValue; // RückgabewertRate
|
string ReturnRateValue; // RückgabewertRate
|
||||||
string ReturnChangeAbsolute; // RückgabewertRate
|
string ReturnChangeAbsolute; // RückgabewertRate
|
||||||
string ReturnRawValue; // Rohwert (mit N & führenden 0)
|
string ReturnRawValue; // Rohwert (mit N & führenden 0)
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ string ClassFlowPostProcessing::GetPreValue(std::string _number)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClassFlowPostProcessing::SetPreValue(float zw, string _numbers, bool _extern)
|
void ClassFlowPostProcessing::SetPreValue(double zw, string _numbers, bool _extern)
|
||||||
{
|
{
|
||||||
printf("SetPrevalue: %f, %s\n", zw, _numbers.c_str());
|
printf("SetPrevalue: %f, %s\n", zw, _numbers.c_str());
|
||||||
for (int j = 0; j < NUMBERS.size(); ++j)
|
for (int j = 0; j < NUMBERS.size(); ++j)
|
||||||
@@ -127,7 +127,7 @@ bool ClassFlowPostProcessing::LoadPreValue(void)
|
|||||||
{
|
{
|
||||||
if (NUMBERS[j]->name == name)
|
if (NUMBERS[j]->name == name)
|
||||||
{
|
{
|
||||||
NUMBERS[j]->PreValue = stof(zwvalue.c_str());
|
NUMBERS[j]->PreValue = stod(zwvalue.c_str());
|
||||||
NUMBERS[j]->ReturnPreValue = RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma + 1); // SIcherheitshalber 1 Stelle mehr, da ggf. Exgtended Resolution an ist (wird erst beim ersten Durchlauf gesetzt)
|
NUMBERS[j]->ReturnPreValue = RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma + 1); // SIcherheitshalber 1 Stelle mehr, da ggf. Exgtended Resolution an ist (wird erst beim ersten Durchlauf gesetzt)
|
||||||
|
|
||||||
time_t tStart;
|
time_t tStart;
|
||||||
@@ -178,7 +178,7 @@ bool ClassFlowPostProcessing::LoadPreValue(void)
|
|||||||
fclose(pFile);
|
fclose(pFile);
|
||||||
printf("%s", zw);
|
printf("%s", zw);
|
||||||
zwvalue = trim(std::string(zw));
|
zwvalue = trim(std::string(zw));
|
||||||
NUMBERS[0]->PreValue = stof(zwvalue.c_str());
|
NUMBERS[0]->PreValue = stod(zwvalue.c_str());
|
||||||
|
|
||||||
time_t tStart;
|
time_t tStart;
|
||||||
int yy, month, dd, hh, mm, ss;
|
int yy, month, dd, hh, mm, ss;
|
||||||
@@ -711,15 +711,26 @@ bool ClassFlowPostProcessing::doFlow(string zwtime)
|
|||||||
#ifdef SERIAL_DEBUG
|
#ifdef SERIAL_DEBUG
|
||||||
printf("After removeLeadingZeros: ReturnValue %s\n", NUMBERS[j]->ReturnRawValue.c_str());
|
printf("After removeLeadingZeros: ReturnValue %s\n", NUMBERS[j]->ReturnRawValue.c_str());
|
||||||
#endif
|
#endif
|
||||||
NUMBERS[j]->Value = std::stof(NUMBERS[j]->ReturnValue);
|
NUMBERS[j]->Value = std::stod(NUMBERS[j]->ReturnValue);
|
||||||
#ifdef SERIAL_DEBUG
|
#ifdef SERIAL_DEBUG
|
||||||
printf("After setting the Value: Value %f and as double is %f\n", NUMBERS[j]->Value, std::stod(NUMBERS[j]->ReturnValue));
|
printf("After setting the Value: Value %f and as double is %f\n", NUMBERS[j]->Value, std::stod(NUMBERS[j]->ReturnValue));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (NUMBERS[j]->checkDigitIncreaseConsistency)
|
if (NUMBERS[j]->checkDigitIncreaseConsistency)
|
||||||
{
|
{
|
||||||
|
if (flowDigit)
|
||||||
|
{
|
||||||
|
if (flowDigit->getCNNType() != Digital)
|
||||||
|
printf("checkDigitIncreaseConsistency = true - ignored due to wrong CNN-Type (not Digital Classification)\n");
|
||||||
|
else
|
||||||
NUMBERS[j]->Value = checkDigitConsistency(NUMBERS[j]->Value, NUMBERS[j]->DecimalShift, NUMBERS[j]->analog_roi != NULL, NUMBERS[j]->PreValue);
|
NUMBERS[j]->Value = checkDigitConsistency(NUMBERS[j]->Value, NUMBERS[j]->DecimalShift, NUMBERS[j]->analog_roi != NULL, NUMBERS[j]->PreValue);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("checkDigitIncreaseConsistency = true - no digital numbers defined!\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef SERIAL_DEBUG
|
#ifdef SERIAL_DEBUG
|
||||||
printf("After checkDigitIncreaseConsistency: Value %f\n", NUMBERS[j]->Value);
|
printf("After checkDigitIncreaseConsistency: Value %f\n", NUMBERS[j]->Value);
|
||||||
#endif
|
#endif
|
||||||
@@ -745,7 +756,7 @@ bool ClassFlowPostProcessing::doFlow(string zwtime)
|
|||||||
|
|
||||||
if (NUMBERS[j]->useMaxRateValue && PreValueUse && NUMBERS[j]->PreValueOkay)
|
if (NUMBERS[j]->useMaxRateValue && PreValueUse && NUMBERS[j]->PreValueOkay)
|
||||||
{
|
{
|
||||||
float _ratedifference;
|
double _ratedifference;
|
||||||
if (NUMBERS[j]->RateType == RateChange)
|
if (NUMBERS[j]->RateType == RateChange)
|
||||||
_ratedifference = NUMBERS[j]->FlowRateAct;
|
_ratedifference = NUMBERS[j]->FlowRateAct;
|
||||||
else
|
else
|
||||||
@@ -840,7 +851,7 @@ string ClassFlowPostProcessing::getReadoutParam(bool _rawValue, bool _noerror, i
|
|||||||
return NUMBERS[_number]->ReturnValue;
|
return NUMBERS[_number]->ReturnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
string ClassFlowPostProcessing::RundeOutput(float _in, int _anzNachkomma){
|
string ClassFlowPostProcessing::RundeOutput(double _in, int _anzNachkomma){
|
||||||
std::stringstream stream;
|
std::stringstream stream;
|
||||||
int _zw = _in;
|
int _zw = _in;
|
||||||
// printf("AnzNachkomma: %d\n", _anzNachkomma);
|
// printf("AnzNachkomma: %d\n", _anzNachkomma);
|
||||||
@@ -864,7 +875,7 @@ string ClassFlowPostProcessing::RundeOutput(float _in, int _anzNachkomma){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
string ClassFlowPostProcessing::ErsetzteN(string input, float _prevalue)
|
string ClassFlowPostProcessing::ErsetzteN(string input, double _prevalue)
|
||||||
{
|
{
|
||||||
int posN, posPunkt;
|
int posN, posPunkt;
|
||||||
int pot, ziffer;
|
int pot, ziffer;
|
||||||
@@ -895,7 +906,7 @@ string ClassFlowPostProcessing::ErsetzteN(string input, float _prevalue)
|
|||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
float ClassFlowPostProcessing::checkDigitConsistency(float input, int _decilamshift, bool _isanalog, float _preValue){
|
float ClassFlowPostProcessing::checkDigitConsistency(double input, int _decilamshift, bool _isanalog, double _preValue){
|
||||||
int aktdigit, olddigit;
|
int aktdigit, olddigit;
|
||||||
int aktdigit_before, olddigit_before;
|
int aktdigit_before, olddigit_before;
|
||||||
int pot, pot_max;
|
int pot, pot_max;
|
||||||
|
|||||||
@@ -32,9 +32,9 @@ protected:
|
|||||||
bool LoadPreValue(void);
|
bool LoadPreValue(void);
|
||||||
string ShiftDecimal(string in, int _decShift);
|
string ShiftDecimal(string in, int _decShift);
|
||||||
|
|
||||||
string ErsetzteN(string, float _prevalue);
|
string ErsetzteN(string, double _prevalue);
|
||||||
float checkDigitConsistency(float input, int _decilamshift, bool _isanalog, float _preValue);
|
float checkDigitConsistency(double input, int _decilamshift, bool _isanalog, double _preValue);
|
||||||
string RundeOutput(float _in, int _anzNachkomma);
|
string RundeOutput(double _in, int _anzNachkomma);
|
||||||
|
|
||||||
void InitNUMBERS();
|
void InitNUMBERS();
|
||||||
void handleDecimalSeparator(string _decsep, string _value);
|
void handleDecimalSeparator(string _decsep, string _value);
|
||||||
@@ -58,7 +58,7 @@ public:
|
|||||||
string getReadoutTimeStamp(int _number = 0);
|
string getReadoutTimeStamp(int _number = 0);
|
||||||
void SavePreValue();
|
void SavePreValue();
|
||||||
string GetPreValue(std::string _number = "");
|
string GetPreValue(std::string _number = "");
|
||||||
void SetPreValue(float zw, string _numbers, bool _extern = false);
|
void SetPreValue(double zw, string _numbers, bool _extern = false);
|
||||||
|
|
||||||
std::string GetJSON(std::string _id = "", std::string _mac = "", std::string _lineend = "\n");
|
std::string GetJSON(std::string _id = "", std::string _mac = "", std::string _lineend = "\n");
|
||||||
|
|
||||||
|
|||||||
@@ -831,6 +831,11 @@ void register_server_tflite_uri(httpd_handle_t server)
|
|||||||
camuri.user_ctx = (void*) "EditFlow";
|
camuri.user_ctx = (void*) "EditFlow";
|
||||||
httpd_register_uri_handler(server, &camuri);
|
httpd_register_uri_handler(server, &camuri);
|
||||||
|
|
||||||
|
camuri.uri = "/value.html";
|
||||||
|
camuri.handler = handler_wasserzaehler;
|
||||||
|
camuri.user_ctx = (void*) "Value";
|
||||||
|
httpd_register_uri_handler(server, &camuri);
|
||||||
|
|
||||||
camuri.uri = "/wasserzaehler.html";
|
camuri.uri = "/wasserzaehler.html";
|
||||||
camuri.handler = handler_wasserzaehler;
|
camuri.handler = handler_wasserzaehler;
|
||||||
camuri.user_ctx = (void*) "Wasserzaehler";
|
camuri.user_ctx = (void*) "Wasserzaehler";
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const char* GIT_REV="N/A";
|
const char* GIT_REV="N/A";
|
||||||
const char* GIT_TAG="N/A";
|
const char* GIT_TAG="N/A";
|
||||||
const char* GIT_BRANCH="N/A";
|
const char* GIT_BRANCH="N/A";
|
||||||
const char* BUILD_TIME="2022-09-10 23:06";
|
const char* BUILD_TIME="2022-09-16 17:31";
|
||||||
@@ -198,7 +198,7 @@ void test_doFlow() {
|
|||||||
digits = { 3.0, 2.0, 2.0, 8.0, 9.0, 4.0, 1.7, 9.8}; // falscher Wert 32290.420
|
digits = { 3.0, 2.0, 2.0, 8.0, 9.0, 4.0, 1.7, 9.8}; // falscher Wert 32290.420
|
||||||
analogs = { };
|
analogs = { };
|
||||||
expected = "32289.420";
|
expected = "32289.420";
|
||||||
expected_extended= "32289.4199";
|
expected_extended= "32289.4198";
|
||||||
// FALSCH! wegen ungenügender Präzision von NUMBERS->Value
|
// FALSCH! wegen ungenügender Präzision von NUMBERS->Value
|
||||||
// expected_extended= "32289.4198";
|
// expected_extended= "32289.4198";
|
||||||
|
|
||||||
@@ -258,6 +258,47 @@ void test_doFlow() {
|
|||||||
result = process_doFlow(analogs, digits, Digital100, false, true);
|
result = process_doFlow(analogs, digits, Digital100, false, true);
|
||||||
TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str());
|
TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str());
|
||||||
|
|
||||||
|
// Fehler bei V11.2.0
|
||||||
|
// https://github.com/jomjol/AI-on-the-edge-device/discussions/950#discussioncomment-3661982
|
||||||
|
digits = { 3.0, 2.0, 4.1, 9.0, 4.0, 6.3, 9.2}; // 3249.459 als falsches Ergebnis
|
||||||
|
analogs = { };
|
||||||
|
expected = "3249.469";
|
||||||
|
expected_extended= "3249.4692";
|
||||||
|
|
||||||
|
// checkConsistency=true
|
||||||
|
result = process_doFlow(analogs, digits, Digital100, false, false, -3);
|
||||||
|
TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
|
||||||
|
|
||||||
|
|
||||||
|
// checkConsistency=true
|
||||||
|
// checkConsistency NOT working correctly
|
||||||
|
//result = process_doFlow(analogs, digits, Digital100, true, false, -3);
|
||||||
|
//TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
|
||||||
|
|
||||||
|
// extendResolution=true
|
||||||
|
result = process_doFlow(analogs, digits, Digital100, false, true, -3);
|
||||||
|
TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str());
|
||||||
|
|
||||||
|
// Fehler bei V11.2.0
|
||||||
|
// https://github.com/jomjol/AI-on-the-edge-device/issues/1020#issue-1375648891
|
||||||
|
digits = { 0.0, 2.0, 6.1, 9.2}; // 259.9227 als falsches Ergebnis
|
||||||
|
analogs = { 9.0, 2.5, 2.9, 7.2};
|
||||||
|
expected = "269.9227";
|
||||||
|
expected_extended= "269.92272";
|
||||||
|
// Float Value reduziert die Genauigkeit hier. Korrekt wäre
|
||||||
|
// expected_extended= "269.92272";
|
||||||
|
|
||||||
|
// checkConsistency=true
|
||||||
|
result = process_doFlow(analogs, digits, Digital100, false, false);
|
||||||
|
TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
|
||||||
|
|
||||||
|
|
||||||
|
// checkConsistency=true
|
||||||
|
// checkConsistency NOT working correctly
|
||||||
|
//result = process_doFlow(analogs, digits, Digital100, true, false, -3);
|
||||||
|
//TEST_ASSERT_EQUAL_STRING(expected, result.c_str());
|
||||||
|
|
||||||
|
|
||||||
// checkConsistency=true und extendResolution=true
|
// checkConsistency=true und extendResolution=true
|
||||||
result = process_doFlow(analogs, digits, Digital100, false, true);
|
result = process_doFlow(analogs, digits, Digital100, false, true);
|
||||||
TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str());
|
TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str());
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const char* GIT_REV="N/A";
|
const char* GIT_REV="N/A";
|
||||||
const char* GIT_TAG="N/A";
|
const char* GIT_TAG="N/A";
|
||||||
const char* GIT_BRANCH="N/A";
|
const char* GIT_BRANCH="N/A";
|
||||||
const char* BUILD_TIME="2022-09-10 23:06";
|
const char* BUILD_TIME="2022-09-16 17:31";
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -13,14 +13,14 @@ function getbasepath(){
|
|||||||
{
|
{
|
||||||
// host = "http://192.168.2.219"; // jomjol interner test
|
// host = "http://192.168.2.219"; // jomjol interner test
|
||||||
// host = "http://192.168.178.46"; // jomjol interner test
|
// host = "http://192.168.178.46"; // jomjol interner test
|
||||||
host = "http://192.168.178.62"; // jomjol interner Real
|
host = "http://192.168.178.44"; // jomjol interner Real
|
||||||
// host = "http://192.168.43.191";
|
// host = "http://192.168.43.191";
|
||||||
// host = "."; // jomjol interner localhost
|
// host = "."; // jomjol interner localhost
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
host = "http://" + host;
|
host = window.location.protocol + "//" + host;
|
||||||
if (window.location.port != "") {
|
if (window.location.port != "") {
|
||||||
host = host + ":" + window.location.port;
|
host = host + ":" + window.location.port;
|
||||||
}
|
}
|
||||||
|
|||||||
207
sd-card/html/ota_page_new.html
Normal file
207
sd-card/html/ota_page_new.html
Normal file
@@ -0,0 +1,207 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<link rel="icon" href="favicon.ico" type="image/x-icon">
|
||||||
|
<title>OTA Update</title>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
|
||||||
|
<style>
|
||||||
|
h1 {font-size: 2em;}
|
||||||
|
h2 {font-size: 1.5em;}
|
||||||
|
h3 {font-size: 1.2em;}
|
||||||
|
p {font-size: 1em;}
|
||||||
|
|
||||||
|
input[type=number] {
|
||||||
|
width: 138px;
|
||||||
|
padding: 10px 5px;
|
||||||
|
display: inline-block;
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button {
|
||||||
|
padding: 10px 20px;
|
||||||
|
width: 211px;
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body style="font-family: arial; padding: 0px 10px;">
|
||||||
|
Check at <a href="https://github.com/jomjol/AI-on-the-edge-device/releases" target=_blank>https://github.com/jomjol/AI-on-the-edge-device/releases</a> to see if there is an update available.
|
||||||
|
<h3>It is strongly recommended to update firmware and web interface (stored separately in the html directory on SD-card) at the same time!</h3>
|
||||||
|
<hr>
|
||||||
|
<h2>Update</h2>
|
||||||
|
<table class="fixed" border="0">
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<table border="0">
|
||||||
|
<tr>
|
||||||
|
<td style="width: 230px">
|
||||||
|
<label for="newfile">Select the update file (update.zip, firmware.bin, html.zip, *.tfl/tflite):</label>
|
||||||
|
</td>
|
||||||
|
<td colspan="2">
|
||||||
|
<input id="newfile" type="file" onchange="setpath()" style="width:100%;">
|
||||||
|
</td>
|
||||||
|
<td rowspan="2" style="padding-left:50px">
|
||||||
|
<button class="button" id="doUpdate" type="button" onclick="doUpdate()">Flash the firmware<br>(Takes about 60s)</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<label for="filepath">Selected upload file:</label>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input id="filepath" type="text" style="width:100%; border: 0" readonly>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<button id="upload" type="button" onclick="upload()">Upload</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<h2>Reboot</h2>
|
||||||
|
<button class="button" id="reboot" type="button" onclick="doReboot()">Reboot to activate updates</button>
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
<script type="text/javascript" src="./gethost.js"></script>
|
||||||
|
|
||||||
|
|
||||||
|
<script language="JavaScript">
|
||||||
|
|
||||||
|
var basepath = "http://192.168.178.26";
|
||||||
|
|
||||||
|
|
||||||
|
function init(){
|
||||||
|
basepath = getbasepath();
|
||||||
|
|
||||||
|
document.getElementById("reboot").disabled = true;
|
||||||
|
document.getElementById("upload").disabled = true;
|
||||||
|
document.getElementById("doUpdate").disabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function doUpdate() {
|
||||||
|
if (confirm("Are you sure to update the firmware?")) {
|
||||||
|
var stringota = "/ota?file=firmware.bin";
|
||||||
|
document.getElementById("doUpdate").disabled = true;
|
||||||
|
|
||||||
|
var xhttp = new XMLHttpRequest();
|
||||||
|
|
||||||
|
xhttp.onreadystatechange = function() {
|
||||||
|
if (xhttp.readyState == 4) {
|
||||||
|
if (xhttp.status == 200) {
|
||||||
|
document.getElementById("reboot").disabled = false;
|
||||||
|
alert("Flash successfull - Reboot necessary to make changes active.");
|
||||||
|
/* keine Reaktion, damit sich das Dokument nicht ändert */
|
||||||
|
} else if (xhttp.status == 0) {
|
||||||
|
alert("Server closed the connection abruptly!");
|
||||||
|
UpdatePage();
|
||||||
|
} else {
|
||||||
|
alert(xhttp.status + " Error!\n" + xhttp.responseText);
|
||||||
|
UpdatePage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
xhttp.open("GET", stringota, true);
|
||||||
|
xhttp.send();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function doReboot() {
|
||||||
|
if (confirm("Are you sure you want to reboot the ESP32?")) {
|
||||||
|
var stringota = "/reboot";
|
||||||
|
window.location = stringota;
|
||||||
|
window.location.href = stringota;
|
||||||
|
window.location.assign(stringota);
|
||||||
|
window.location.replace(stringota);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function setpath() {
|
||||||
|
var nameneu = document.getElementById("newfile").value;
|
||||||
|
nameneu = nameneu.split(/[\\\/]/).pop();
|
||||||
|
document.getElementById("filepath").value = nameneu;
|
||||||
|
document.getElementById("upload").disabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function upload() {
|
||||||
|
var xhttp = new XMLHttpRequest();
|
||||||
|
|
||||||
|
var filePath = document.getElementById("filepath").value;
|
||||||
|
var upload_path = "/upload/firmware/" + filePath;
|
||||||
|
var fileInput = document.getElementById("newfile").files;
|
||||||
|
|
||||||
|
/* first delete the old firmware */
|
||||||
|
xhttp.onreadystatechange = function() {
|
||||||
|
if (xhttp.readyState == 4) {
|
||||||
|
if (xhttp.status == 200) {
|
||||||
|
/* keine Reaktion, damit sich das Dokument nicht ändert */
|
||||||
|
} else if (xhttp.status == 0) {
|
||||||
|
alert("Server closed the connection abruptly!");
|
||||||
|
UpdatePage();
|
||||||
|
} else {
|
||||||
|
alert(xhttp.status + " Error!\n" + xhttp.responseText);
|
||||||
|
UpdatePage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var _toDo = basepath + "/ota?delete=" + filePath;
|
||||||
|
xhttp.open("GET", _toDo, false);
|
||||||
|
xhttp.send();
|
||||||
|
/* ----------------------------- */
|
||||||
|
|
||||||
|
|
||||||
|
/* Max size of an individual file. Make sure this
|
||||||
|
* value is same as that set in file_server.c */
|
||||||
|
var MAX_FILE_SIZE = 6000*1024;
|
||||||
|
var MAX_FILE_SIZE_STR = "6MB";
|
||||||
|
|
||||||
|
if (fileInput.length == 0) {
|
||||||
|
alert("No file selected!");
|
||||||
|
} else if (filePath.length == 0) {
|
||||||
|
alert("File path on server is not set!");
|
||||||
|
} else if (filePath.indexOf(' ') >= 0) {
|
||||||
|
alert("File path on server cannot have spaces!");
|
||||||
|
} else if (filePath[filePath.length-1] == '/') {
|
||||||
|
alert("File name not specified after path!");
|
||||||
|
} else if (fileInput[0].size > MAX_FILE_SIZE) {
|
||||||
|
alert("File size must be less than " + MAX_FILE_SIZE_STR + "!");
|
||||||
|
} else {
|
||||||
|
document.getElementById("newfile").disabled = true;
|
||||||
|
document.getElementById("filepath").disabled = true;
|
||||||
|
document.getElementById("upload").disabled = true;
|
||||||
|
|
||||||
|
xhttp.onreadystatechange = function() {
|
||||||
|
if (xhttp.readyState == 4) {
|
||||||
|
if (xhttp.status == 200) {
|
||||||
|
alert("Upload successfull!")
|
||||||
|
// document.reload();
|
||||||
|
document.getElementById("reboot").disabled = false;
|
||||||
|
document.getElementById("doUpdate").disabled = false;
|
||||||
|
} else if (xhttp.status == 0) {
|
||||||
|
alert("Server closed the connection abruptly!");
|
||||||
|
UpdatePage();
|
||||||
|
} else {
|
||||||
|
alert(xhttp.status + " Error!\n" + xhttp.responseText);
|
||||||
|
UpdatePage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
var file = fileInput[0];
|
||||||
|
xhttp.open("POST", upload_path, true);
|
||||||
|
xhttp.send(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
init();
|
||||||
|
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user