-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
404 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,114 @@ | ||
-<!--#include file="ssi/header.html"--> | ||
<style> | ||
.fileUpload { | ||
position: relative; | ||
overflow: hidden; | ||
margin: 10px; | ||
} | ||
|
||
.fileUpload input.upload { | ||
position: absolute; | ||
top: 0; | ||
right: 0; | ||
margin: 0; | ||
padding: 0; | ||
font-size: 20px; | ||
cursor: pointer; | ||
opacity: 0; | ||
filter: alpha(opacity=0); | ||
} | ||
<!--#include file="ssi/header.html"--> | ||
<style type="text/css"> | ||
.progr { | ||
width: 100%; | ||
height: 32px; | ||
background-color: rgba(240, 240, 24, 0.6); | ||
color: #c0c0c0; | ||
} | ||
|
||
.progr-ok { | ||
width: 100%; | ||
height: 32px; | ||
background-color: rgba(240, 240, 24, 1.0); | ||
color: #e0e060; | ||
} | ||
|
||
.progr-fail { | ||
width: 100%; | ||
height: 32px; | ||
background-color: rgba(240, 240, 24, 1.0); | ||
color: #c00000; | ||
} | ||
|
||
.progr-done { | ||
width: 100%; | ||
height: 32px; | ||
background-color: rgba(240, 240, 24, 1.0); | ||
color: #00c000; | ||
} | ||
|
||
</style> | ||
|
||
|
||
<div id="main"> | ||
<div class="header"> | ||
<h1>OTA Upgrade!</h1> | ||
<h2>Upload new firmware to the device and perform an upgrade Over The Air!</h2> | ||
</div> | ||
<div class="content"> | ||
<h2 class="content-subhead">Upload firmware</h2> | ||
<p> | ||
Select a firmware file you want flashed to the device. | ||
Currently, we only supports flashing a new firmware. <br>Flashing the filesystem may be supported at a later time. | ||
</p> | ||
|
||
<form method="POST" id="FormOTA" enctype="multipart/form-data"> | ||
<input id="ota_upload_file" placeholder="Choose File" disabled="disabled" /> | ||
<div class="fileUpload pure-button pure-button-primary"> | ||
<span>Select File</span> | ||
<input id="ota_upload" type="file" name="file" class="upload" /> | ||
</div> | ||
<br> | ||
<br> | ||
<input type="submit" value="Upload" class="pure-button button-warning"> | ||
</form> | ||
</div> | ||
<div class="header"> | ||
<h1>OTA Upgrade!</h1> | ||
<h2>Upload new firmware to the device and perform an upgrade Over The Air!</h2> | ||
</div> | ||
<div class="content"> | ||
<h2 class="content-subhead">Upload firmware</h2> | ||
<p> | ||
Select a firmware file you want flashed to the device. | ||
|
||
<form name=multipart action="/api/v1/ota/" method="post" enctype="multipart/form-data" onsubmit="do_upload(this); return false;"> | ||
<table> | ||
<tr> | ||
<td> | ||
<input type="file" name="ota" id="ota" size="20" accept=".bin" onchange="file_change();" style="font-size: 12pt"> | ||
</td> | ||
<td colspan=2> | ||
<span id=file_info style="font-size:12pt;"></span></td> | ||
</tr> | ||
<tr> | ||
<td colspan=3> | ||
<input type="submit" id="update" name="upload" disabled value="Upload" style="font-size: 18pt"> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td colspan=3> | ||
<progress id=progr value=0 max=100 class=progr>Upload Progress</progress> | ||
</td> | ||
</tr> | ||
</table> | ||
</td> | ||
</tr> | ||
</table> | ||
</form> | ||
</div> | ||
</div> | ||
|
||
</div> | ||
|
||
<script src="js/ui.js"></script> | ||
<script src="js/jquery.min.js"></script> | ||
<script> | ||
document.getElementById("ota_upload").onchange = function() { | ||
document.getElementById("ota_upload_file").value = this.value; | ||
}; | ||
|
||
$( document ).ready(function() { | ||
// POST firmware | ||
$('#FormOTA').submit(function(e){ | ||
e.preventDefault(); | ||
$.ajax({ | ||
url:'/api/v1/post/ota_upload', | ||
type:'POST', | ||
data:$('#FormOTA').serialize(), | ||
success:function(){ | ||
console.log("Success"); | ||
} | ||
}); | ||
}); | ||
}); | ||
-<!--#include file="ssi/footer.html"--> | ||
|
||
function do_upload(f) { | ||
var xhr = new XMLHttpRequest(); | ||
|
||
document.getElementById('update').disabled = 1; | ||
document.getElementById("progr").class = "progr-ok"; | ||
|
||
xhr.upload.addEventListener("progress", function(e) { | ||
document.getElementById("progr").value = parseInt(e.loaded / e.total * 100); | ||
|
||
if (e.loaded == e.total) { | ||
} | ||
|
||
}, false); | ||
|
||
xhr.onreadystatechange = function(e) { | ||
console.log("rs" + xhr.readyState + " status " + xhr.status); | ||
if (xhr.readyState == 4) { | ||
document.getElementById("progr").class = "progr-ok"; | ||
setTimeout(function() { | ||
window.location.href = location.origin + "/"; | ||
}, 1000); | ||
} | ||
}; | ||
|
||
xhr.open("POST", f.action, true); | ||
xhr.send(new FormData(f)); | ||
|
||
return false; | ||
} | ||
|
||
function file_change() { | ||
document.getElementById('update').disabled = 0; | ||
} | ||
</script> | ||
|
||
|
||
|
||
<!--#include file="ssi/footer.html"--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#ifndef OTA_PROTOCOL_H | ||
#define OTA_PROTOCOL_H | ||
#include <libwebsockets.h> | ||
|
||
int callback_esplws_ota(struct lws *wsi, enum lws_callback_reasons reason, | ||
void *user, void *in, size_t len); | ||
|
||
struct per_session_data__esplws_ota { | ||
struct lws_spa *spa; | ||
char filename[32]; | ||
char result[LWS_PRE + 512]; | ||
int result_len; | ||
int filename_length; | ||
esp_ota_handle_t otahandle; | ||
const esp_partition_t *part; | ||
long file_length; | ||
nvs_handle nvh; | ||
}; | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.