Added basis for firmware uploading

This commit is contained in:
Mark van Renswoude 2018-01-01 21:00:56 +01:00
parent f87a8b6eb7
commit d9ae78ba07
6 changed files with 101 additions and 3 deletions

55
src/server/firmware.cpp Normal file
View File

@ -0,0 +1,55 @@
/*
* Stairs
* Copyright 2017 (c) Mark van Renswoude
*
* https://git.x2software.net/pub/Stairs
*/
#include "firmware.h"
#include "../debug.h"
#include "../global.h"
void handleFileUpload(AsyncWebServerRequest *request, const String& filename, size_t index, uint8_t *data, size_t len, bool final)
{
_d("Firmware :: handleFileUpload: index = "); _d(index);
_d(", len = "); _d(len);
_d(", final = "); _dln(final);
uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
if (index == 0)
{
if (Update.begin(maxSketchSpace))
Update.runAsync(true);
else
_dln("Firmware :: failed to start");
}
if (Update.write(data, len) == len)
{
if(final)
{
#ifdef SerialDebug
if (Update.end(true))
Serial.println("Update succesful!");
else
Update.printError(Serial);
#else
Update.end(true);
#endif
}
}
#ifdef SerialDebug
else
Update.printError(Serial);
#endif
}
void registerFirmwareRoutes(AsyncWebServer* server)
{
server.onFileUpload(handleFileUpload);
}

13
src/server/firmware.h Normal file
View File

@ -0,0 +1,13 @@
/*
* Stairs
* Copyright 2017 (c) Mark van Renswoude
*
* https://git.x2software.net/pub/Stairs
*/
#ifndef __server_firmware
#define __server_firmware
#include <ESPAsyncWebServer.h>
void registerFirmwareRoutes(AsyncWebServer* server);
#endif

View File

@ -242,6 +242,11 @@ function startApp()
{
console.log(error);
});
},
uploadFirmware: function()
{
//
}
}
});

2
web/dist/bundle.js vendored

File diff suppressed because one or more lines are too long

View File

@ -36,6 +36,7 @@
<button class="button" :class="{ 'button-outline': activeTab != 'status' }" @click="activeTab = 'status'">{{ $t('status.tabTitle') }}</button>
<button class="button" :class="{ 'button-outline': activeTab != 'triggers' }" @click="activeTab = 'triggers'">{{ $t('triggers.tabTitle') }}</button>
<button class="button" :class="{ 'button-outline': activeTab != 'connection' }" @click="activeTab = 'connection'">{{ $t('connection.tabTitle') }}</button>
<button class="button" :class="{ 'button-outline': activeTab != 'firmware' }" @click="activeTab = 'firmware'">{{ $t('firmware.tabTitle') }}</button>
</div>
<div v-if="activeTab == 'status'">
@ -105,6 +106,20 @@
</fieldset>
</form>
</div>
<div v-if="activeTab == 'firmware'">
<form @submit.prevent="uploadFirmware">
<fieldset>
<h3>{{ $t('firmware.title') }}</h3>
<input type="file">
<div class="buttons">
<input class="button-primary" type="submit" :disabled="saving" :value="saving ? $t('applyButtonSaving') : $t('applyButton')">
</div>
</fieldset>
</form>
</div>
</div>
<div class="clearfix"></div>

View File

@ -59,6 +59,11 @@ var messages = {
gateway: 'Gateway',
hostname: 'Hostname',
hostnamePlaceholder: 'Default: mac address'
},
firmware: {
tabTitle: 'Firmware',
title: 'Firmware update'
}
},
@ -69,8 +74,8 @@ var messages = {
copyright: 'Copyright © 2017 Mark van Renswoude',
loading: 'Een ogenblik geduld, bezig met laden van configuratie...',
applyButton: 'Apply',
applyButtonSaving: 'Saving...',
applyButton: 'Toepassen',
applyButtonSaving: 'Bezig met opslaan...',
wifiStatus: {
accesspoint: {
@ -122,6 +127,11 @@ var messages = {
gateway: 'Gateway',
hostname: 'Hostnaam',
hostnamePlaceholder: 'Standaard: mac adres'
},
firmware: {
tabTitle: 'Firmware',
title: 'Firmware bijwerken'
}
}
}