Web update via OTA now under user control. Icon shows on header when an update is available.
Update can be commanded via the Version Information menu by pressing UP, CENTRE, UP. Prompt driven of course! Removed Wifi Trigger pin - does not play nice with automatic COM port uploads! Reverted to DS18B20 read from index 0 - allows plugging sensor in and re-discovery!
This commit is contained in:
parent
fc8eef73a6
commit
2ccd948001
|
@ -393,7 +393,6 @@ void setup() {
|
|||
sCredentials creds = NVstore.getCredentials();
|
||||
|
||||
if(NVstore.getWifiEnabled()) {
|
||||
// initWifi(WiFi_TriggerPin, AP_SSID, AP_PASSWORD);
|
||||
initWifi(WiFi_TriggerPin, creds.SSID, creds.APpassword);
|
||||
#if USE_OTA == 1
|
||||
if(NVstore.getOTAEnabled()) {
|
||||
|
@ -797,7 +796,7 @@ void loop()
|
|||
tDelta = timenow - lastTemperatureTime;
|
||||
if(tDelta > TEMPERATURE_INTERVAL) { // maintain a minimum holdoff period
|
||||
lastTemperatureTime += TEMPERATURE_INTERVAL; // reset time to observe temeprature
|
||||
fTemperature = TempSensor.getTempC(tempSensorAddress); // read sensor
|
||||
fTemperature = TempSensor.getTempCByIndex(0); // read sensor
|
||||
// DebugPort.printf("DS18B20 = %f\r\n", fTemperature);
|
||||
// initialise filtered temperature upon very first pass
|
||||
if(fTemperature > -80) { // avoid disconnected sensor readings being integrated
|
||||
|
@ -1338,6 +1337,7 @@ int getBoardRevision()
|
|||
void ShowOTAScreen(int percent, bool webupdate)
|
||||
{
|
||||
ScreenManager.showOTAMessage(percent, webupdate);
|
||||
feedWatchdog();
|
||||
}
|
||||
|
||||
void feedWatchdog()
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
}
|
||||
}
|
||||
function uploadFile() {
|
||||
_("cancel").hidden = true;
|
||||
var file = _("file1").files[0];
|
||||
sendSize = file.size;
|
||||
var formdata = new FormData();
|
||||
|
@ -77,7 +78,7 @@
|
|||
<h3 id="status"></h3>
|
||||
<p id="loaded_n_total"></p>
|
||||
<BR>
|
||||
<input type='button' onclick=window.location.assign("/") value='Cancel'>
|
||||
<input type='button' onclick=window.location.assign("/") value='Cancel' id="cancel">
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
|
@ -37,5 +37,4 @@ public:
|
|||
CBasicScreen(C128x64_OLED& display, CScreenManager& mgr);
|
||||
bool show();
|
||||
bool keyHandler(uint8_t event);
|
||||
bool animate() { return CScreen::animate(); };
|
||||
};
|
||||
|
|
|
@ -41,12 +41,6 @@ CClockScreen::CClockScreen(C128x64_OLED& display, CScreenManager& mgr) : CScreen
|
|||
_keyRepeatCount = -1;
|
||||
}
|
||||
|
||||
void
|
||||
CClockScreen::showTime(int)
|
||||
{
|
||||
// override and DO NOTHING!
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
CClockScreen::show()
|
||||
|
|
|
@ -30,7 +30,7 @@ class CScreenManager;
|
|||
|
||||
class CClockScreen : public CScreenHeader {
|
||||
protected:
|
||||
virtual void showTime(int numTimers);
|
||||
virtual void showTime() {}; // override so time does not show in header
|
||||
bool _colon;
|
||||
int _keyRepeatCount;
|
||||
public:
|
||||
|
|
|
@ -130,6 +130,8 @@ CGPIOScreen::show()
|
|||
bool
|
||||
CGPIOScreen::animate()
|
||||
{
|
||||
CPasswordScreen::animate();
|
||||
|
||||
if(_rowSel != 4) {
|
||||
int yPos = 53;
|
||||
int xPos = _display.xCentre();
|
||||
|
|
|
@ -111,8 +111,6 @@ CHeaterSettingsScreen::animate()
|
|||
{
|
||||
char msg[16];
|
||||
|
||||
CPasswordScreen::animate();
|
||||
|
||||
if(isPasswordBusy() || (_rowSel == 4)) { // Password screen activity
|
||||
_printMenuText(Column, Line2, " ");
|
||||
_printMenuText(Column, Line1, " ");
|
||||
|
|
|
@ -41,7 +41,6 @@ public:
|
|||
void onExit();
|
||||
bool show();
|
||||
bool keyHandler(uint8_t event);
|
||||
bool animate() { return CScreen::animate(); };
|
||||
};
|
||||
|
||||
#endif
|
|
@ -81,14 +81,8 @@ CScreenHeader::show()
|
|||
// battery
|
||||
showBatteryIcon(getHeaterInfo().getBattVoltage());
|
||||
|
||||
// timers
|
||||
int numTimers = showTimers();
|
||||
|
||||
// // GPIO
|
||||
// showGPIO();
|
||||
|
||||
// clock
|
||||
showTime(numTimers);
|
||||
showTime();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -110,7 +104,27 @@ CScreenHeader::show()
|
|||
bool
|
||||
CScreenHeader::animate()
|
||||
{
|
||||
bool retval = false;
|
||||
bool retval = true;
|
||||
|
||||
_animateCount++;
|
||||
ROLLUPPERLIMIT(_animateCount, 10, 0);
|
||||
if(isUpdateAvailable(true)) {
|
||||
int xPos = X_TIMER_ICON - 3;
|
||||
int yPos = Y_TIMER_ICON;
|
||||
switch(_animateCount) {
|
||||
case 0:
|
||||
case 2:
|
||||
_display.fillRect(xPos, yPos, W_TIMER_ICON+3, H_TIMER_ICON, BLACK);
|
||||
break;
|
||||
case 1:
|
||||
_display.drawBitmap(xPos+6, yPos, updateIcon, updateWidth, updateHeight, WHITE);
|
||||
break;
|
||||
default:
|
||||
showTimers();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if((isWifiConnected() || isWifiAP()) && isWebClientConnected()) {
|
||||
|
||||
int xPos = X_WIFI_ICON + W_WIFI_ICON;
|
||||
|
@ -129,6 +143,7 @@ CScreenHeader::animate()
|
|||
}
|
||||
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);
|
||||
_display.drawBitmap(xPos, yPos, wifiOutIcon, W_WIFIIN_ICON, H_WIFIIN_ICON, WHITE);
|
||||
_clearUpAnimation = true; // clear arrow upon next iteration
|
||||
retval = true;
|
||||
|
@ -145,6 +160,7 @@ CScreenHeader::animate()
|
|||
}
|
||||
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.drawBitmap(xPos, yPos, wifiInIcon, W_WIFIOUT_ICON, H_WIFIOUT_ICON, WHITE);
|
||||
_clearDnAnimation = true; // clear arrow upon next iteration
|
||||
retval = true;
|
||||
|
@ -240,7 +256,7 @@ CScreenHeader::showTimers()
|
|||
|
||||
|
||||
void
|
||||
CScreenHeader::showTime(int numTimers)
|
||||
CScreenHeader::showTime()
|
||||
{
|
||||
const BTCDateTime& now = Clock.get();
|
||||
|
||||
|
@ -262,11 +278,6 @@ CScreenHeader::showTime(int numTimers)
|
|||
int xPos = X_WIFI_ICON + W_WIFI_ICON + W_WIFIIN_ICON; // rhs of wifi conglomeration
|
||||
if(isWifiAP()) xPos += 4; // add more if an Access Point
|
||||
|
||||
/* switch(numTimers) {
|
||||
case 0: xPos = _display.xCentre(); break;
|
||||
case 1: xPos += (X_TIMER_ICON - xPos) / 2; break;
|
||||
}
|
||||
_printMenuText(xPos, Y_CLOCK, msg, false, eCentreJustify);*/
|
||||
_printMenuText(X_CLOCK, Y_CLOCK, msg);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,12 +32,13 @@ class CScreenHeader : public CScreen {
|
|||
bool _clearUpAnimation;
|
||||
bool _clearDnAnimation;
|
||||
bool _colon;
|
||||
int _animateCount;
|
||||
protected:
|
||||
void showBTicon();
|
||||
void showWifiIcon();
|
||||
void showBatteryIcon(float voltage);
|
||||
int showTimers();
|
||||
virtual void showTime(int numTimers); // x location depends upon how many timers are active
|
||||
virtual void showTime(); // x location depends upon how many timers are active
|
||||
void showGPIO();
|
||||
public:
|
||||
CScreenHeader(C128x64_OLED& disp, CScreenManager& mgr);
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
|
||||
static uint8_t condensed[7][120];
|
||||
|
||||
CTimerChartScreen::CTimerChartScreen(C128x64_OLED& display, CScreenManager& mgr, int instance) : CScreenHeader(display, mgr)
|
||||
CTimerChartScreen::CTimerChartScreen(C128x64_OLED& display, CScreenManager& mgr, int instance) : CScreen(display, mgr)
|
||||
{
|
||||
_rowSel = 0;
|
||||
_colSel = 0;
|
||||
|
|
|
@ -30,7 +30,8 @@ class C128x64_OLED;
|
|||
class CScreenManager;
|
||||
class CProtocol;
|
||||
|
||||
class CTimerChartScreen : public CScreenHeader {
|
||||
//class CTimerChartScreen : public CScreenHeader {
|
||||
class CTimerChartScreen : public CScreen {
|
||||
int _rowSel;
|
||||
int _colSel;
|
||||
int _instance;
|
||||
|
|
|
@ -40,7 +40,9 @@ void
|
|||
CVersionInfoScreen::onSelect()
|
||||
{
|
||||
CScreenHeader::onSelect();
|
||||
_factoryDefaultEn = 0;
|
||||
_rowSel = 0;
|
||||
_animateCount = 0;
|
||||
checkFOTA();
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -57,7 +59,12 @@ CVersionInfoScreen::show()
|
|||
|
||||
if(!CPasswordScreen::show()) { // for showing "saving settings"
|
||||
|
||||
if(_factoryDefaultEn < 2) {
|
||||
if(_rowSel == 20) {
|
||||
_printInverted(_display.xCentre(), 0, " Firmware update ", true, eCentreJustify);
|
||||
_printMenuText(_display.xCentre(), 35, "Press UP to", false, eCentreJustify);
|
||||
_printMenuText(_display.xCentre(), 43, "confirm download", false, eCentreJustify);
|
||||
}
|
||||
else if(_rowSel < 2) {
|
||||
_printInverted(_display.xCentre(), 0, " Version Information ", true, eCentreJustify);
|
||||
|
||||
_display.drawBitmap(10, 11, firmwareIcon, firmwareWidth, firmwareHeight, WHITE);
|
||||
|
@ -72,10 +79,16 @@ CVersionInfoScreen::show()
|
|||
_printMenuText(108, 38, "Analog", false, eCentreJustify);
|
||||
_display.drawLine(88, 42, 127, 42, WHITE);
|
||||
}
|
||||
_printMenuText(_display.xCentre(), 53, " \021 Exit \020 ", true, eCentreJustify);
|
||||
|
||||
if(_rowSel == 1 && isUpdateAvailable()) {
|
||||
_printMenuText(_display.xCentre(), 53, " \021 Get Update \020 ", true, eCentreJustify);
|
||||
}
|
||||
else {
|
||||
_printMenuText(_display.xCentre(), 53, " \021 Exit \020 ", true, eCentreJustify);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(_factoryDefaultEn == 11) { // after the saving popup has expired
|
||||
if(_rowSel == 11) { // after the saving popup has expired
|
||||
const char* content[2];
|
||||
content[0] = "Factory reset";
|
||||
content[1] = "completed";
|
||||
|
@ -83,7 +96,7 @@ CVersionInfoScreen::show()
|
|||
}
|
||||
else {
|
||||
_printInverted(_display.xCentre(), 0, " Factory Default ", true, eCentreJustify);
|
||||
if(_factoryDefaultEn == 10) {
|
||||
if(_rowSel == 10) {
|
||||
_printMenuText(_display.xCentre(), 35, "Press UP to", false, eCentreJustify);
|
||||
_printMenuText(_display.xCentre(), 43, "confirm save", false, eCentreJustify);
|
||||
}
|
||||
|
@ -91,9 +104,9 @@ CVersionInfoScreen::show()
|
|||
|
||||
_display.drawBitmap(10, 15, cautionIcon, cautionWidth, cautionHeight, WHITE);
|
||||
|
||||
_printMenuText(50, 30, "Abort", _factoryDefaultEn == 2);
|
||||
_printMenuText(50, 16, "Apply", _factoryDefaultEn == 3);
|
||||
if(_factoryDefaultEn == 3)
|
||||
_printMenuText(50, 30, "Abort", _rowSel == 2);
|
||||
_printMenuText(50, 16, "Apply", _rowSel == 3);
|
||||
if(_rowSel == 3)
|
||||
_printMenuText(_display.xCentre(), 53, " \021 Apply \020 ", true, eCentreJustify);
|
||||
else
|
||||
_printMenuText(_display.xCentre(), 53, " \021 Exit \020 ", true, eCentreJustify);
|
||||
|
@ -105,6 +118,19 @@ CVersionInfoScreen::show()
|
|||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
CVersionInfoScreen::animate()
|
||||
{
|
||||
if(_rowSel <= 1 && isUpdateAvailable()) {
|
||||
_animateCount++;
|
||||
ROLLUPPERLIMIT(_animateCount, 10, 0);
|
||||
int ypos = 11 + 20 - 7 - _animateCount;
|
||||
_display.fillRect(0, 11, 7, 21, BLACK);
|
||||
_display.drawBitmap(1, ypos, wifiOutIcon, 5, 7, WHITE);
|
||||
_display.fillRect(0, 11, 7, 2, WHITE);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
CVersionInfoScreen::keyHandler(uint8_t event)
|
||||
|
@ -112,23 +138,30 @@ CVersionInfoScreen::keyHandler(uint8_t event)
|
|||
if(event & keyPressed) {
|
||||
// UP press
|
||||
if(event & key_Up) {
|
||||
if(_factoryDefaultEn == 10) {
|
||||
if(_rowSel == 20) {
|
||||
isUpdateAvailable(false); // make firmware update happen
|
||||
_rowSel = 0;
|
||||
}
|
||||
else if(_rowSel == 10) {
|
||||
wifiFactoryDefault();
|
||||
BoardRevisionReset();
|
||||
NVstore.init();
|
||||
NVstore.save();
|
||||
_showStoringMessage();
|
||||
_factoryDefaultEn = 11;
|
||||
_rowSel = 11;
|
||||
}
|
||||
else {
|
||||
_factoryDefaultEn++;
|
||||
UPPERLIMIT(_factoryDefaultEn, 3);
|
||||
_rowSel++;
|
||||
UPPERLIMIT(_rowSel, 3);
|
||||
}
|
||||
}
|
||||
// DOWN press
|
||||
if(event & key_Down) {
|
||||
_factoryDefaultEn--;
|
||||
LOWERLIMIT(_factoryDefaultEn, 0);
|
||||
if(_rowSel == 20) { // firmware update cancel
|
||||
_rowSel = 0;
|
||||
}
|
||||
_rowSel--;
|
||||
LOWERLIMIT(_rowSel, 0);
|
||||
}
|
||||
// LEFT press
|
||||
if(event & key_Left) {
|
||||
|
@ -140,8 +173,14 @@ CVersionInfoScreen::keyHandler(uint8_t event)
|
|||
}
|
||||
// CENTRE press
|
||||
if(event & key_Centre) {
|
||||
if(_factoryDefaultEn == 3) {
|
||||
_factoryDefaultEn = 10;
|
||||
if(_rowSel == 20) { // firmware update cancel
|
||||
_rowSel = 0;
|
||||
}
|
||||
else if(_rowSel == 3) { // factory enable selection
|
||||
_rowSel = 10;
|
||||
}
|
||||
else if(_rowSel == 1) { // firmware update selection
|
||||
_rowSel = 20;
|
||||
}
|
||||
else {
|
||||
_ScreenManager.selectMenu(CScreenManager::RootMenuLoop); // force return to main menu
|
||||
|
|
|
@ -31,13 +31,15 @@ class CScreenManager;
|
|||
|
||||
class CVersionInfoScreen : public CPasswordScreen
|
||||
{
|
||||
int _factoryDefaultEn;
|
||||
int _rowSel;
|
||||
void _initUI();
|
||||
int _animateCount;
|
||||
public:
|
||||
CVersionInfoScreen(C128x64_OLED& display, CScreenManager& mgr);
|
||||
bool show();
|
||||
bool keyHandler(uint8_t event);
|
||||
void onSelect();
|
||||
bool animate();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -187,7 +187,7 @@ CWiFiScreen::animate()
|
|||
if(pMsg)
|
||||
_printMenuText(_display.xCentre(), 56, pMsg, false, eCentreJustify);
|
||||
}
|
||||
CScreen::animate();
|
||||
CScreenHeader::animate();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -57,12 +57,22 @@ const unsigned char wifiIcon [] PROGMEM = {
|
|||
|
||||
// 'wifiInIcon, 5x5px
|
||||
const unsigned char wifiInIcon [] PROGMEM = {
|
||||
0x70, 0x70, 0xf8, 0x70, 0x20
|
||||
0x70, // ###
|
||||
0x70, // ###
|
||||
0xf8, // #####
|
||||
0x70, // ###
|
||||
0x20 // #
|
||||
};
|
||||
|
||||
// 'wifiOutIcon, 5x5px
|
||||
const unsigned char wifiOutIcon [] PROGMEM = {
|
||||
0x20, 0x70, 0xf8, 0x70, 0x70
|
||||
0x20, // #
|
||||
0x70, // ###
|
||||
0xf8, // #####
|
||||
0x70, // ###
|
||||
0x70, // ###
|
||||
0x70, // ###
|
||||
0x70 // ###
|
||||
};
|
||||
|
||||
// 'BatteryIcon', 15x10px
|
||||
|
@ -572,7 +582,22 @@ const uint8_t PROGMEM cautionIcon[] =
|
|||
};
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Image data for update
|
||||
//
|
||||
|
||||
const uint8_t PROGMEM updateIcon[] =
|
||||
{
|
||||
0xFF, 0x80, // #########
|
||||
0x80, 0x80, // # #
|
||||
0xFF, 0x80, // #########
|
||||
0xF7, 0x80, // #### ####
|
||||
0xE3, 0x80, // ### ###
|
||||
0xD5, 0x80, // ## # # ##
|
||||
0xF7, 0x80, // #### ####
|
||||
0xF7, 0x80, // #### ####
|
||||
0xFF, 0x80, // #########
|
||||
0xFF, 0x80, // #########
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -187,3 +187,8 @@ const uint8_t hardwareHeight = 15;
|
|||
extern const uint8_t cautionIcon[];
|
||||
const uint8_t cautionWidth = 30;
|
||||
const uint8_t cautionHeight = 29;
|
||||
|
||||
// Bitmap sizes for update
|
||||
extern const uint8_t updateIcon[];
|
||||
const uint8_t updateWidth = 9;
|
||||
const uint8_t updateHeight = 10;
|
||||
|
|
|
@ -20,6 +20,9 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#ifndef __BTC_HELPERS_H__
|
||||
#define __BTC_HELPERS_H__
|
||||
|
||||
#include "Protocol.h"
|
||||
|
||||
|
||||
|
@ -64,6 +67,9 @@ extern void setupGPIO();
|
|||
extern void setGPIO(int channel, bool state);
|
||||
extern bool getGPIO(int channel);
|
||||
extern void feedWatchdog();
|
||||
extern bool isUpdateAvailable(bool test=true);
|
||||
extern void checkFOTA();
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -71,3 +77,5 @@ extern void feedWatchdog();
|
|||
#define UPPERLIMIT(A, B) if((A) > (B)) (A) = (B)
|
||||
#define ROLLUPPERLIMIT(A, B, C) if((A) > (B)) (A) = (C)
|
||||
#define ROLLLOWERLIMIT(A, B, C) if((A) < (B)) (A) = (C)
|
||||
|
||||
#endif
|
|
@ -79,14 +79,6 @@ bool handleFileRead(String path) { // send the right file to the client (if it e
|
|||
|
||||
void handleBTCRoot() {
|
||||
handleFileRead("/index.html");
|
||||
/* if(SPIFFS.exists("/index.html")) {
|
||||
File html = SPIFFS.open("/index.html");
|
||||
server.streamFile(html, "text/html");
|
||||
html.close();
|
||||
}
|
||||
else {
|
||||
DebugPort.println("\"/index.html\" does not exist!!!");
|
||||
}*/
|
||||
}
|
||||
#else
|
||||
void handleBTCRoot() {
|
||||
|
@ -135,76 +127,28 @@ void handleBTCNotFound() {
|
|||
}
|
||||
|
||||
const char* serverIndex = R"=====(
|
||||
<!DOCTYPE html>
|
||||
<style>body {font-family: Arial, Helvetica, sans-serif;}</style>
|
||||
<html>
|
||||
<head>
|
||||
<script>
|
||||
function _(el) {
|
||||
return document.getElementById(el);
|
||||
}
|
||||
function uploadFile() {
|
||||
var file = _("update").files[0];
|
||||
var formdata = new FormData();
|
||||
formdata.append("update", file);
|
||||
var ajax = new XMLHttpRequest();
|
||||
ajax.upload.addEventListener("progress", progressHandler, false);
|
||||
ajax.addEventListener("load", completeHandler, false);
|
||||
ajax.addEventListener("error", errorHandler, false);
|
||||
ajax.addEventListener("abort", abortHandler, false);
|
||||
ajax.open("POST", "/updatenow")
|
||||
ajax.send(formdata);
|
||||
}
|
||||
function progressHandler(event) {
|
||||
_("loaded_n_total").innerHTML = "Uploaded "+event.loaded+" bytes of "event.total;
|
||||
var percent = (event.load / event.total) * 100;
|
||||
_("progressBar").value = Math.round(percent);
|
||||
_("status").innerHTML = Math.round(percent)+"% uploaded.. please wait";
|
||||
}
|
||||
function completeHandler(event) {
|
||||
_("status").innerHTML = event.target.responseText;
|
||||
_("progressBar").value = 0;
|
||||
}
|
||||
function errorHandler(event) {
|
||||
_("status").innerHTML = "Upload Failed";
|
||||
}
|
||||
function abortHandler(event) {
|
||||
_("status").innerHTML = "Upload Aborted";
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<title>Afterburner firmware update</title>
|
||||
<h1>Afterburner firmware update</h1>
|
||||
<form method='POST' action='/updatenow' enctype='multipart/form-data'>
|
||||
<input type='file' name='update'>
|
||||
<BR>
|
||||
<BR>
|
||||
<input type='button' value='Update' onclick="uploadFile()"> <input type='button' onclick=window.location.assign('/') value='Cancel'>
|
||||
<progress id="progressBar" value="0" max="100" style="width:300px;"></progress>
|
||||
<h3 id="status"></h3>
|
||||
<p id="loaded_n_total"</p>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
)=====";
|
||||
|
||||
const char* rootIndex = R"=====(
|
||||
<!DOCTYPE html>
|
||||
<script>
|
||||
function init() {
|
||||
window.location.assign("/");
|
||||
}
|
||||
</script
|
||||
<html>
|
||||
<head>
|
||||
<title>HTML Meta Tag</title>
|
||||
<meta http-equiv = "refresh" content = "0; url = /" />
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to root URL</p>
|
||||
</body>
|
||||
<head>
|
||||
<title>HTML Meta Tag</title>
|
||||
</head>
|
||||
<body onload="javascript:init()">
|
||||
<p>Root redirect</p>
|
||||
</body>
|
||||
</html>
|
||||
)=====";
|
||||
|
||||
void rootRedirect()
|
||||
{
|
||||
server.sendHeader("Connection", "close");
|
||||
// server.sendHeader("Connection", "close");
|
||||
server.send(200, "text/html", rootIndex);
|
||||
}
|
||||
|
||||
|
@ -217,7 +161,7 @@ void initWebServer(void) {
|
|||
DebugPort.printf("Progress: %u%%\r", percent);
|
||||
DebugPort.handle(); // keep telnet spy alive
|
||||
ShowOTAScreen(percent, true);
|
||||
|
||||
DebugPort.print("^");
|
||||
});
|
||||
|
||||
if (MDNS.begin("Afterburner")) {
|
||||
|
@ -233,9 +177,10 @@ void initWebServer(void) {
|
|||
server.on("/tst", HTTP_GET, []() {
|
||||
rootRedirect();
|
||||
});
|
||||
// magical code shamelessly lifted from Arduino WebUpdate example, modified
|
||||
// this allows pushing new firmware to the ESP from a WEB BROWSER!
|
||||
// added authentication and a sequencing flag to ensure this is not bypassed
|
||||
|
||||
// Magical code originally shamelessly lifted from Arduino WebUpdate example, then modified
|
||||
// This allows pushing new firmware to the ESP from a WEB BROWSER!
|
||||
// Added authentication and a sequencing flag to ensure this is not bypassed
|
||||
//
|
||||
// Initial launch page
|
||||
server.on("/update", HTTP_GET, []() {
|
||||
|
@ -245,10 +190,8 @@ void initWebServer(void) {
|
|||
}
|
||||
bUpdateAccessed = true;
|
||||
server.sendHeader("Connection", "close");
|
||||
// server.send(200, "text/html", serverIndex); // transition to file upload page
|
||||
server.sendHeader("Cache-Control", "no-cache");
|
||||
handleFileRead("/uploadfirmware.html");
|
||||
|
||||
});
|
||||
server.on("/updatenow", HTTP_GET, []() { // handle attempts to just browse the /updatenow path - force redirect to root
|
||||
rootRedirect();
|
||||
|
@ -256,7 +199,10 @@ void initWebServer(void) {
|
|||
// actual guts that manages the new firmware upload
|
||||
server.on("/updatenow", HTTP_POST, []() {
|
||||
// completion functionality
|
||||
server.send(200, "text/plain", (Update.hasError()) ? "FAIL - Afterburner will reboot shortly" : "OK - Afterburner will reboot shortly");
|
||||
if(Update.hasError())
|
||||
server.send(200, "text/plain", "FAIL - Afterburner will reboot shortly");
|
||||
else
|
||||
server.send(200, "OK - Afterburner will reboot shortly");
|
||||
delay(1000);
|
||||
ESP.restart(); // reboot
|
||||
}, []() {
|
||||
|
@ -270,12 +216,12 @@ void initWebServer(void) {
|
|||
}
|
||||
} else if (upload.status == UPLOAD_FILE_WRITE) {
|
||||
#if USE_SW_WATCHDOG == 1
|
||||
feedWatchdog();
|
||||
feedWatchdog(); // we get stuck here for a while, don't let the watchdog bite!
|
||||
#endif
|
||||
if(upload.totalSize) {
|
||||
char JSON[64];
|
||||
sprintf(JSON, "{\"progress\":%d}", upload.totalSize);
|
||||
sendWebServerString(JSON);
|
||||
sendWebServerString(JSON); // feedback proper byte count of update
|
||||
// DebugPort.print(JSON);
|
||||
}
|
||||
DebugPort.print(".");
|
||||
|
@ -296,7 +242,7 @@ void initWebServer(void) {
|
|||
}
|
||||
}
|
||||
else {
|
||||
// attempt to POST without using /update - force redirect to root
|
||||
// attempt to POST without using /update - forced redirect to root
|
||||
rootRedirect();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -50,8 +50,10 @@ int wifiButtonState = 0;
|
|||
|
||||
extern CScreenManager ScreenManager;
|
||||
|
||||
|
||||
bool initWifi(int initpin,const char *failedssid, const char *failedpassword)
|
||||
{
|
||||
|
||||
TRIG_PIN = initpin;
|
||||
pinMode(TRIG_PIN, INPUT_PULLUP);
|
||||
|
||||
|
@ -64,9 +66,6 @@ bool initWifi(int initpin,const char *failedssid, const char *failedpassword)
|
|||
sprintf(MACstr[1], "%02X:%02X:%02X:%02X:%02X:%02X", MAC[0], MAC[1], MAC[2], MAC[3], MAC[4], MAC[5]);
|
||||
DebugPort.printf(" AP MAC address: %s\r\n", MACstr[1]);
|
||||
|
||||
char APname[32];
|
||||
sprintf(APname, "%s", failedssid);
|
||||
|
||||
//reset settings - wipe credentials for testing
|
||||
// wm.resetSettings();
|
||||
|
||||
|
@ -87,8 +86,7 @@ bool initWifi(int initpin,const char *failedssid, const char *failedpassword)
|
|||
|
||||
DebugPort.println("Attempting to start STA mode (or config portal) via WifiManager...");
|
||||
|
||||
// wm.setHostname(failedssid);
|
||||
wm.setHostname(APname);
|
||||
wm.setHostname(failedssid);
|
||||
wm.setConfigPortalTimeout(20);
|
||||
wm.setConfigPortalBlocking(false);
|
||||
wm.setSaveParamsCallback(saveParamsCallback); // ensure our webserver gets awoken when IP config changes to STA
|
||||
|
@ -97,8 +95,7 @@ bool initWifi(int initpin,const char *failedssid, const char *failedpassword)
|
|||
//REMOVED - UNSTABLE WHETHER WE GET 192.168.4.1 or 192.168.100.1 ????
|
||||
// REMOVED wm.setAPStaticIPConfig(IPAddress(192, 168, 100, 1), IPAddress(192, 168, 100, 1), IPAddress(255,255,255,0));
|
||||
|
||||
// bool res = wm.autoConnect(failedssid, failedpassword); // auto generated AP name from chipid
|
||||
bool res = wm.autoConnect(APname, failedpassword); // auto generated AP name from chipid
|
||||
bool res = wm.autoConnect(failedssid, failedpassword); // auto generated AP name from chipid
|
||||
DebugPort.printf("WifiMode after autoConnect = "); DebugPort.println(WiFi.getMode());
|
||||
|
||||
int chnl = 1;
|
||||
|
@ -124,8 +121,7 @@ bool initWifi(int initpin,const char *failedssid, const char *failedpassword)
|
|||
DebugPort.println("Starting AP mode");
|
||||
//REMOVED - UNSTABLE WHETHER WE GET 192.168.4.1 or 192.168.100.1 ????
|
||||
// REMOVED WiFi.softAPConfig(IPAddress(192, 168, 100, 1), IPAddress(192, 168, 100, 1), IPAddress(255,255,255,0));
|
||||
// WiFi.softAP(failedssid, failedpassword, chnl);
|
||||
WiFi.softAP(APname, failedpassword, chnl);
|
||||
WiFi.softAP(failedssid, failedpassword, chnl);
|
||||
WiFi.enableAP(true);
|
||||
DebugPort.printf(" AP SSID: %s\r\n", WiFi.softAPgetHostname());
|
||||
DebugPort.printf(" AP IP address: %s\r\n", getWifiAPAddrStr());
|
||||
|
@ -138,7 +134,7 @@ bool initWifi(int initpin,const char *failedssid, const char *failedpassword)
|
|||
wm.startWebPortal();
|
||||
isPortalAP = true; // we started portal, we have to flag it!
|
||||
}
|
||||
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
@ -147,7 +143,7 @@ void doWiFiManager()
|
|||
{
|
||||
wm.process();
|
||||
|
||||
|
||||
#if USE_PORTAL_TRIGGER_PIN == 1
|
||||
// manage handling of pin to enter WiFManager config portal
|
||||
// we typically use the BOOT pin for this (pins.h)
|
||||
//
|
||||
|
@ -193,6 +189,7 @@ void doWiFiManager()
|
|||
// consider as contact bounce if < 50ms!
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void wifiDisable(long rebootDelay)
|
||||
|
|
|
@ -24,8 +24,14 @@
|
|||
#if USE_SPIFFS == 1
|
||||
#include <SPIFFS.h>
|
||||
#endif
|
||||
#include <esp32fota.h>
|
||||
#include "../Protocol/helpers.h"
|
||||
|
||||
extern void ShowOTAScreen(int percent=0, bool webpdate=false);
|
||||
|
||||
esp32FOTA FOTA("afterburner-fota-http", int(getVersion()*1000));
|
||||
unsigned long FOTAtime = millis() + 60000; // initially check in a minutes time
|
||||
int FOTAauth = 0;
|
||||
|
||||
#include <esp_int_wdt.h>
|
||||
#include <esp_task_wdt.h>
|
||||
|
@ -37,6 +43,7 @@ void hard_restart() {
|
|||
}
|
||||
|
||||
void initOTA(){
|
||||
FOTA.checkURL = "http://www.mrjones.id.au/afterburner/fota/fota.json";
|
||||
// ArduinoOTA.setHostname("myesp32");
|
||||
ArduinoOTA.setHostname("AfterburnerOTA");
|
||||
// ArduinoOTA.setPassword("TESTO123");
|
||||
|
@ -54,7 +61,9 @@ void initOTA(){
|
|||
DebugPort.println("Start updating " + type);
|
||||
DebugPort.handle(); // keep telnet spy alive
|
||||
ShowOTAScreen();
|
||||
|
||||
#if USE_SW_WATCHDOG == 1
|
||||
feedWatchdog(); // we get stuck here for a while, don't let the watchdog bite!
|
||||
#endif
|
||||
})
|
||||
.onEnd([]() {
|
||||
DebugPort.println("\nEnd");
|
||||
|
@ -67,7 +76,7 @@ void initOTA(){
|
|||
DebugPort.printf("Progress: %u%%\r", percent);
|
||||
DebugPort.handle(); // keep telnet spy alive
|
||||
ShowOTAScreen(percent);
|
||||
|
||||
DebugPort.print("%%");
|
||||
})
|
||||
.onError([](ota_error_t error) {
|
||||
DebugPort.printf("Error[%u]: ", error);
|
||||
|
@ -84,4 +93,41 @@ void initOTA(){
|
|||
|
||||
void DoOTA(){
|
||||
ArduinoOTA.handle();
|
||||
|
||||
// manage Firmware OTA
|
||||
// this is where the controlelr contacts a web server to discover if new firmware is available
|
||||
// if so, it can dowload and implant using OTA and become effective next reboot!
|
||||
long tDelta = millis() - FOTAtime;
|
||||
if(tDelta > 0) {
|
||||
FOTAtime = millis() + 600000; // 10 minutes
|
||||
DebugPort.println("Checking for new firmware...");
|
||||
if(FOTA.execHTTPcheck()) {
|
||||
DebugPort.println("New firmware available on web server!");
|
||||
if(FOTAauth == 2) {
|
||||
FOTA.execOTA();
|
||||
FOTAauth = 0;
|
||||
}
|
||||
else
|
||||
FOTAauth = 1; // flag that new firmware is available
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
bool isUpdateAvailable(bool test)
|
||||
{
|
||||
if(test) {
|
||||
return FOTAauth == 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
FOTAauth = 2;
|
||||
FOTAtime = millis(); // force immediate update test
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void checkFOTA()
|
||||
{
|
||||
FOTAtime = millis();
|
||||
}
|
|
@ -44,6 +44,7 @@
|
|||
#define USE_WEBSERVER 1
|
||||
#define USE_SPIFFS 1
|
||||
|
||||
#define USE_PORTAL_TRIGGER_PIN 0
|
||||
|
||||
|
||||
|
||||
|
@ -109,7 +110,7 @@
|
|||
//#define PROTOCOL_INVESTIGATION
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Software base watchdog
|
||||
// Software based watchdog
|
||||
//
|
||||
#define USE_SW_WATCHDOG 1
|
||||
|
||||
|
|
Loading…
Reference in a new issue