Update SoftAP

This commit is contained in:
jomjol
2022-12-31 11:15:51 +01:00
parent eff713a2a9
commit b9abbafefc
10 changed files with 135 additions and 19 deletions

View File

@@ -14,6 +14,7 @@ public:
bool isNewParagraph(std::string input);
bool GetNextParagraph(std::string& aktparamgraph, bool &disabled, bool &eof);
bool getNextLine(std::string* rt, bool &disabled, bool &eof);
bool ConfigFileExists(){return pFile;};
private:
FILE* pFile;

View File

@@ -139,6 +139,11 @@ bool setupTime() {
ConfigFile configFile = ConfigFile(CONFIG_FILE);
if (!configFile.ConfigFileExists()){
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "No ConfigFile defined - exit setupTime() ");
return false;
}
std::vector<std::string> splitted;
std::string line = "";
bool disabledLine = false;

View File

@@ -160,13 +160,6 @@ extern "C" void app_main(void)
return; // No way to continue without SD-Card!
}
CheckIsPlannedReboot();
CheckOTAUpdate();
CheckUpdate();
#ifdef ENABLE_SOFTAP
CheckStartAPMode(); // if no wlan.ini and/or config.ini --> AP ist startet and this function does not exit anymore until reboot
#endif
setupTime();
string versionFormated = getFwVersion() + ", Date/Time: " + std::string(BUILD_TIME) + \
@@ -186,6 +179,12 @@ extern "C" void app_main(void)
LogFile.WriteToFile(ESP_LOG_INFO, TAG, versionFormated);
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Reset reason: " + getResetReason());
CheckIsPlannedReboot();
CheckOTAUpdate();
CheckUpdate();
#ifdef ENABLE_SOFTAP
CheckStartAPMode(); // if no wlan.ini and/or config.ini --> AP ist startet and this function does not exit anymore until reboot
#endif
char *ssid = NULL, *passwd = NULL, *hostname = NULL, *ip = NULL, *gateway = NULL, *netmask = NULL, *dns = NULL; int rssithreashold = 0;
LoadWlanFromFile(WLAN_CONFIG_FILE, ssid, passwd, hostname, ip, gateway, netmask, dns, rssithreashold);

View File

@@ -107,8 +107,9 @@ void SendHTTPResponse(httpd_req_t *req)
message = "<h3>1. Upload initial configuration to sd-card</h3><p>";
message += "The configuration file config.ini is missing and most propably the full configuration and html folder on the sd-card. ";
message += "This is normal after the first flashing of the firmware and an empty sd-card. Please upload \"remote_setup.zip\", which contains an full inital configuration.<p>";
message += "<input id=\"newfile\" type=\"file\">";
message += "<input id=\"newfile\" type=\"file\"><br>";
message += "<button class=\"button\" style=\"width:300px\" id=\"doUpdate\" type=\"button\" onclick=\"upload()\">Upload File</button><p>";
message += "The upload might take up to 60s. After a succesfull upload the page will be updated.";
httpd_resp_send_chunk(req, message.c_str(), strlen(message.c_str()));
message = "<script language=\"JavaScript\">";
@@ -118,18 +119,20 @@ void SendHTTPResponse(httpd_req_t *req)
message += "var filePath = document.getElementById(\"newfile\").value.split(/[\\\\/]/).pop();";
message += "var file = document.getElementById(\"newfile\").files[0];";
message += "if (!file.name.includes(\"remote-setup\")){if (!confirm(\"The zip file name should contain '...remote-setup...'. Are you sure that you have downloaded the correct file?\"))return;};";
message += "var upload_path = \"/upload/firmware/\" + filePath; xhttp.open(\"POST\", upload_path, true); xhttp.send(file);document.reload();}";
message += "var upload_path = \"/upload/firmware/\" + filePath; xhttp.open(\"POST\", upload_path, true); xhttp.send(file);document.reload();";
message += "document.getElementById(\"doUpdate\").disabled = true;}";
message += "</script>";
isConfigINI = true;
httpd_resp_send_chunk(req, message.c_str(), strlen(message.c_str()));
return;
}
if (!isWlanINI)
{
message = "<h3>2. WLAN access credentials</h3><p>";
message = "<table>";
message += "<table>";
message += "<tr><td>WLAN-SSID</td><td><input type=\"text\" name=\"ssid\" id=\"ssid\"></td><td>SSID of the WLAN</td></tr>";
message += "<tr><td>WLAN-Password</td><td><input type=\"text\" name=\"password\" id=\"password\"></td><td>ATTENTION: the password will not be encrypted during the sending.</td>";
message += "<tr><td>WLAN-Password</td><td><input type=\"text\" name=\"password\" id=\"password\"></td><td>ATTENTION: the password will not be encrypted during the sending.</td><tr>";
message += "</table><p>";
message += "<h4>ATTENTION:<h4>Be sure about the WLAN settings. They cannot be reseted afterwards. If ssid or password is wrong, you need to take out the sd-card and manually change them in \"wlan.ini\"!<p>";
httpd_resp_send_chunk(req, message.c_str(), strlen(message.c_str()));
// message = "</tr><tr><td> Hostname</td><td><input type=\"text\" name=\"hostname\" id=\"hostname\"></td><td></td>";
@@ -140,9 +143,6 @@ void SendHTTPResponse(httpd_req_t *req)
// message += "<tr><td>RSSI Threashold</td><td><input type=\"number\" name=\"name\" id=\"threashold\" min=\"-100\" max=\"0\" step=\"1\" value = \"0\"></td><td>WLAN Mesh Parameter: Threashold for RSSI value to check for start switching access point in a mesh system.Possible values: -100 to 0, 0 = disabled - Value will be transfered to wlan.ini at next startup)</td></tr>";
// httpd_resp_send_chunk(req, message.c_str(), strlen(message.c_str()));
message = "/<table><p>";
message += "<h4>ATTENTION:<h4>Be sure about the WLAN settings. They cannot be reset afterwards. If ssid or password is wrong, you need to take out the sd-card and manually change them in \"wlan.ini\"!<p>";
httpd_resp_send_chunk(req, message.c_str(), strlen(message.c_str()));
message = "<button class=\"button\" type=\"button\" onclick=\"wr()\">Write wlan.ini</button>";
message += "<script language=\"JavaScript\">async function wr(){";
@@ -155,7 +155,7 @@ void SendHTTPResponse(httpd_req_t *req)
message = "<h3>3. Reboot</h3><p>";
message += "After triggering the reboot, the zip-files gets extracted and written to the sd-card.<br>The ESP32 will restart two times and then connect to your access point. Please find the IP in your router settings and access it with the new ip-address.<p>";
message += "The first update and initialization process can take up to 3 minutes before you find it in the wlan. Errors can be found on the console / serial logout.<p>Have fun!<p>";
message += "The first update and initialization process can take up to 3 minutes before you find it in the wlan. Error logs can be found on the console / serial logout.<p>Have fun!<p>";
message += "<button class=\"button\" type=\"button\" onclick=\"rb()\")>Reboot to first setup.</button>";
message += "<script language=\"JavaScript\">async function rb(){";
message += "api = \"/reboot\";";
@@ -404,6 +404,8 @@ esp_err_t upload_post_handlerAP(httpd_req_t *req)
remaining -= received;
}
fclose(fd);
isConfigINI = true;
FILE* pfile = fopen("/sdcard/update.txt", "w");
std::string _s_zw= "/sdcard" + std::string(filename);
@@ -411,17 +413,14 @@ esp_err_t upload_post_handlerAP(httpd_req_t *req)
fclose(pfile);
fclose(fd);
ESP_LOGI(TAG, "File reception complete");
httpd_resp_set_hdr(req, "Location", "/test");
httpd_resp_set_status(req, "303 See Other");
httpd_resp_set_hdr(req, "Location", "/test");
// httpd_resp_sendstr(req, "File uploaded successfully");
httpd_resp_send_chunk(req, NULL, 0);
ESP_LOGI(TAG, "Update page send out");
// httpd_resp_sendstr(req, "File uploaded successfully");
return ESP_OK;
}

BIN
docs/access-point.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 KiB

112
docs/index_new.html Normal file
View File

@@ -0,0 +1,112 @@
<html>
<title>AI on the Edge Device - Webinstaller</title>
<link rel="icon" href="https://raw.githubusercontent.com/jomjol/AI-on-the-edge-device/master/images/icon/favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script
type="module"
src="https://unpkg.com/esp-web-tools@9.0.3/dist/web/install-button.js?module"
></script>
<body style="
padding: 20px;
padding-left: 60px;
padding-right: 60px;
">
<table>
<tr>
<td><img src=https://raw.githubusercontent.com/jomjol/AI-on-the-edge-device/master/images/icon/watermeter.svg style="width: 100px; padding-right: 10px;"></td>
<td><h1>AI-on-the-edge-device</h1><h2>Webinstaller and Console</h2></td>
</tr>
</table>
<hr>
<p>This page provides the Webinstaller and a live USB Console to your AI-on-the-edge-device.<br>
For further information about AI-on-the-edge-device please go to <a href=https://github.com/jomjol/AI-on-the-edge-device>https://github.com/jomjol/AI-on-the-edge-device</a>.</p>
<p>Beside flashing the firmware you need a sd-card with configuration informations about the system and the wifi credentials.</p>
<p>There a two ways to make this settings:</body>p>
<ol>
<li>By hand: follow the instructions in the wiki (copy data to sd-card, setup wifi credentials by hand)</li>
<li>Use an integraded primitiv access point to make the first setup.<br>
In this case read the instructions below carefully in advance, as you have to temporaly change wifi and need a downloaded file.</li>
</ol>
<p>Notes:</p>
<ul>
<li>For the installation, make sure to switch the ESP32 to Bootloader mode!</li>
<li>The SD-Card still must be flashed separately on a PC (See in the <a href=https://github.com/jomjol/AI-on-the-edge-device/wiki/Installation>Wiki</a>)!</li>
<li>After the installation, a manual reset might be required!</li>
<li>Please note that not all webbrowsers and operating systems support the needed access to USB!</li>
<li>Check the <a href=https://github.com/jomjol/AI-on-the-edge-device/wiki/Installation>Wiki</a> for additional information.</li>
</ul>
<p><esp-web-install-button manifest="manifest.json"></esp-web-install-button></p>
<hr>
<p style="font-size: small;">Installer and Console powered by <a href=https://esphome.github.io/esp-web-tools/ target=_blank>ESP Web Tools</a></p>
<h5>Using internal access point for sd-card setup</h5>
<p>Before starting the flash process download the necessary file. It is a zip file, that contains the initial default configuration additionally.
You can identify it by the naming. It should contain `...remote-setup...` within the file name. Store this file locally you will need it later.
</p>
<h6>Flash the firmware with the WebInstaller</h6>
<div style="text-indent:50px;">
<p>Instructions see above.</p>
</div>
<h6>Connect to Device</h6>
<div style="text-indent:50px;">
<p>During the first booting, the device identifies, that the wifi credentials as well as the configuration informations are missing.</p>
<p>Therefore a simple wifi access point is initiated and a simple internal web server is startet.</p>
<p>The naming of the wifi is "AI-on-the-edge" and you can access without any password.</p>
<p><img src="access-point.png" alt="Access Point" width="250"></p>
<p>You connect to the server with the fixed ip: http://192.168.4.1</p>
</div>
<h6>Upload initial configuration to sd-card</h6>
<div style="text-indent:50px;">
<p><img src="setup-config.png" alt="Access Point" width="300"></p>
<p>Use the `select file` and `upload` button to start the upload.</p>
<p>A warning will come, if you have choosen a possible wrong file (without default configuration).</p>
</div>
<h6>Upload initial configuration to sd-card</h6>
<div style="text-indent:50px;">
<p><img src="setup-config.png" alt="Access Point" width="300"></p>
<p>Use the `select file` and `upload` button to start the upload.<br>
A warning will come, if you have choosen a possible wrong file (without default configuration).</p>
<p>Be patient - the upload takes up to about 60s without response during this time.<br>
After succesfull upload the page will be reloaded for the next step.</p>
</div>
<h6>Store WLAN acces information</h6>
<div style="text-indent:50px;">
<p><img src="setup-wlan.png" alt="Access Point" width="300"></p>
<p>Here you can set your wifi credentials. Only basic settings can done here. If you need advanced features (fixed ip, ...), please use the manual setup.</p>
<p>Attention:</p>
<ul>
<li>Carefully check your wifi settings. To change them later on, you need to take you the sd-card and to it manually in `wlan.ini`</li>
<li>The informations are transfered without encryption.</li>
</ul>
<p>Finish the step by pushing `Write wlan.ini`</p>
</div>
<h6>Reboot</h6>
<div style="text-indent:50px;">
<p><img src="setup-reboot.png" alt="Access Point" width="300"></p>
<p>The final step is the reboot.</p>
<p>It will take up to 3 minutes. Afterwards you can find your device in the local network. Check you router for the IP. You can find it also in the console output.</p>
</div>
</body>
</html>

BIN
docs/setup-config.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 KiB

BIN
docs/setup-reboot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 151 KiB

BIN
docs/setup-wlan.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 146 KiB

0
sd-card/demo/leer.txt Normal file
View File