pushing upload file size via web socket so we can use an upload progress percent on OLED.
Tidied wifi traffic icons
This commit is contained in:
parent
760aa2fc6f
commit
c83a0cc9c5
|
@ -8,15 +8,15 @@
|
|||
<script>
|
||||
// global variables
|
||||
var sendSize;
|
||||
var Socket;
|
||||
var ws;
|
||||
|
||||
function _(el) {
|
||||
return document.getElementById(el);
|
||||
}
|
||||
function init() {
|
||||
Socket = new WebSocket('ws://' + window.location.hostname + ':81/');
|
||||
ws = new WebSocket('ws://' + window.location.hostname + ':81/');
|
||||
|
||||
Socket.onmessage = function(event){
|
||||
ws.onmessage = function(event){
|
||||
var response = JSON.parse(event.data);
|
||||
var key;
|
||||
for(key in response) {
|
||||
|
@ -37,6 +37,13 @@
|
|||
_("cancel").hidden = true;
|
||||
var file = _("file1").files[0];
|
||||
sendSize = file.size;
|
||||
|
||||
var JSONmsg = {};
|
||||
JSONmsg['UploadSize'] = sendSize;
|
||||
var str = JSON.stringify(JSONmsg);
|
||||
console.log("JSON Tx:", str);
|
||||
ws.send(str);
|
||||
|
||||
var formdata = new FormData();
|
||||
formdata.append("update", file);
|
||||
var ajax = new XMLHttpRequest();
|
||||
|
|
|
@ -137,13 +137,21 @@ CScreenHeader::animate()
|
|||
int yPos = 0;
|
||||
if(_clearUpAnimation) {
|
||||
// arrow was drawn in the prior iteration, now erase it
|
||||
_display.fillRect(xPos, yPos, W_WIFIIN_ICON, H_WIFIIN_ICON, BLACK);
|
||||
if(NVstore.getOTAEnabled())
|
||||
_display.fillRect(X_WIFI_ICON +12, Y_WIFI_ICON, 12, 5, BLACK);
|
||||
else
|
||||
_display.fillRect(xPos, yPos, W_WIFIIN_ICON, H_WIFIIN_ICON, BLACK);
|
||||
_display.drawBitmap(X_WIFI_ICON, Y_WIFI_ICON, wifiIcon, W_WIFI_ICON, H_WIFI_ICON, WHITE);
|
||||
retval = true;
|
||||
_clearUpAnimation = false;
|
||||
}
|
||||
else if(hasWebServerSpoken(true)) {
|
||||
// we have emitted data to the web client, show an UP arrow
|
||||
_display.fillRect(xPos, yPos, W_WIFIIN_ICON, H_WIFIIN_ICON, BLACK);
|
||||
if(NVstore.getOTAEnabled())
|
||||
_display.fillRect(X_WIFI_ICON +12, Y_WIFI_ICON, 12, 5, BLACK);
|
||||
else
|
||||
_display.fillRect(xPos, yPos, W_WIFIIN_ICON, H_WIFIIN_ICON, BLACK);
|
||||
_display.drawBitmap(X_WIFI_ICON, Y_WIFI_ICON, wifiIcon, W_WIFI_ICON, H_WIFI_ICON, WHITE);
|
||||
_display.drawBitmap(xPos, yPos, wifiOutIcon, W_WIFIIN_ICON, H_WIFIIN_ICON, WHITE);
|
||||
_clearUpAnimation = true; // clear arrow upon next iteration
|
||||
retval = true;
|
||||
|
@ -154,13 +162,17 @@ CScreenHeader::animate()
|
|||
yPos = H_WIFI_ICON - H_WIFIIN_ICON + 1;
|
||||
if(_clearDnAnimation) {
|
||||
// arrow was drawn in the prior iteration, now erase it
|
||||
_display.fillRect(xPos, yPos, W_WIFIOUT_ICON, H_WIFIOUT_ICON, BLACK);
|
||||
_display.fillRect(X_WIFI_ICON + 12, Y_WIFI_ICON + 6, 12, 5, BLACK);
|
||||
// _display.fillRect(xPos, yPos, W_WIFIOUT_ICON, H_WIFIOUT_ICON, BLACK);
|
||||
_display.drawBitmap(X_WIFI_ICON, Y_WIFI_ICON, wifiIcon, W_WIFI_ICON, H_WIFI_ICON, WHITE);
|
||||
retval = true;
|
||||
_clearDnAnimation = false;
|
||||
}
|
||||
else if(hasWebClientSpoken(true)) {
|
||||
// we have receievd data from the web client, show an DOWN arrow
|
||||
_display.fillRect(xPos, yPos, W_WIFIOUT_ICON, H_WIFIOUT_ICON, BLACK);
|
||||
_display.fillRect(X_WIFI_ICON + 12, Y_WIFI_ICON + 6, 12, 5, BLACK);
|
||||
// _display.fillRect(xPos, yPos, W_WIFIOUT_ICON, H_WIFIOUT_ICON, BLACK);
|
||||
_display.drawBitmap(X_WIFI_ICON, Y_WIFI_ICON, wifiIcon, W_WIFI_ICON, H_WIFI_ICON, WHITE);
|
||||
_display.drawBitmap(xPos, yPos, wifiInIcon, W_WIFIOUT_ICON, H_WIFIOUT_ICON, WHITE);
|
||||
_clearDnAnimation = true; // clear arrow upon next iteration
|
||||
retval = true;
|
||||
|
|
|
@ -69,6 +69,7 @@ extern bool getGPIO(int channel);
|
|||
extern void feedWatchdog();
|
||||
extern bool isUpdateAvailable(bool test=true);
|
||||
extern void checkFOTA();
|
||||
extern void setUploadSize(long val);
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -185,6 +185,9 @@ void interpretJsonCommand(char* pLine)
|
|||
info.password[31] = 0;
|
||||
NVstore.setMQTTinfo(info);
|
||||
}
|
||||
else if(strcmp("UploadSize", it->key) == 0) {
|
||||
setUploadSize(it->value.as<long>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#define USE_EMBEDDED_WEBUPDATECODE
|
||||
//#define USE_EMBEDDED_WEBUPDATECODE
|
||||
|
||||
#include "BTCWebServer.h"
|
||||
#include "../Utility/DebugPort.h"
|
||||
|
@ -51,6 +51,7 @@ WebSocketsServer webSocket = WebSocketsServer(81);
|
|||
bool bRxWebData = false; // flags for OLED animation
|
||||
bool bTxWebData = false;
|
||||
bool bUpdateAccessed = false; // flag used to ensure web update always starts via /update. direct accesses to /updatenow will FAIL
|
||||
long _SuppliedFileSize = 0;
|
||||
|
||||
const int led = 13;
|
||||
|
||||
|
@ -142,15 +143,15 @@ const char* updateIndex = R"=====(
|
|||
<script>
|
||||
// global variables
|
||||
var sendSize;
|
||||
var Socket;
|
||||
var ws;
|
||||
|
||||
function _(el) {
|
||||
return document.getElementById(el);
|
||||
}
|
||||
function init() {
|
||||
Socket = new WebSocket('ws://' + window.location.hostname + ':81/');
|
||||
ws = new WebSocket('ws://' + window.location.hostname + ':81/');
|
||||
|
||||
Socket.onmessage = function(event){
|
||||
ws.onmessage = function(event){
|
||||
var response = JSON.parse(event.data);
|
||||
var key;
|
||||
for(key in response) {
|
||||
|
@ -171,6 +172,13 @@ const char* updateIndex = R"=====(
|
|||
_("cancel").hidden = true;
|
||||
var file = _("file1").files[0];
|
||||
sendSize = file.size;
|
||||
|
||||
var JSONmsg = {};
|
||||
JSONmsg['UploadSize'] = sendSize;
|
||||
var str = JSON.stringify(obj);
|
||||
console.log("JSON Tx:", str);
|
||||
ws.send(str);
|
||||
|
||||
var formdata = new FormData();
|
||||
formdata.append("update", file);
|
||||
var ajax = new XMLHttpRequest();
|
||||
|
@ -332,14 +340,14 @@ void initWebServer(void) {
|
|||
ESP.restart(); // reboot
|
||||
}
|
||||
}, []() {
|
||||
DebugPort.println("WEB: POST /updatenow handler");
|
||||
// DebugPort.println("WEB: POST /updatenow handler");
|
||||
if(bUpdateAccessed) { // only allow progression via /update, attempts to directly access /updatenow will fail
|
||||
HTTPUpload& upload = server.upload();
|
||||
if (upload.status == UPLOAD_FILE_START) {
|
||||
String filename = upload.filename;
|
||||
DebugPort.setDebugOutput(true);
|
||||
if(filename.endsWith(".bin")) {
|
||||
DebugPort.printf("Update: %s\r\n", filename.c_str());
|
||||
DebugPort.printf("Update: %s %d\r\n", filename.c_str(), upload.totalSize);
|
||||
if (!Update.begin()) { //start with max available size
|
||||
Update.printError(DebugPort);
|
||||
}
|
||||
|
@ -361,6 +369,11 @@ void initWebServer(void) {
|
|||
sprintf(JSON, "{\"progress\":%d}", upload.totalSize);
|
||||
sendWebServerString(JSON); // feedback proper byte count of update
|
||||
}
|
||||
int percent = 0;
|
||||
if(_SuppliedFileSize)
|
||||
percent = 100 * upload.totalSize / _SuppliedFileSize;
|
||||
ShowOTAScreen(percent);
|
||||
|
||||
DebugPort.print(".");
|
||||
if(fsUploadFile) {
|
||||
fsUploadFile.write(upload.buf, upload.currentSize); // Write the received bytes to the file
|
||||
|
@ -484,3 +497,7 @@ bool hasWebServerSpoken(bool reset)
|
|||
return retval;
|
||||
}
|
||||
|
||||
void setUploadSize(long val)
|
||||
{
|
||||
_SuppliedFileSize = val;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue