Fixed OTA firmware update
This commit is contained in:
parent
b39f3ba826
commit
c789fd259b
2
.gitignore
vendored
2
.gitignore
vendored
@ -4,3 +4,5 @@ src/credentials.h
|
||||
*.sublime-workspace
|
||||
web/node_modules/
|
||||
web/update/
|
||||
src/version.h
|
||||
web/version.js
|
||||
|
@ -1,3 +1,3 @@
|
||||
& .\updateversion.ps1
|
||||
& platformio run
|
||||
Copy-Item .\.pioenvs\esp12e\firmware.elf .\web\update\
|
||||
Copy-Item .\.pioenvs\esp12e\firmware.bin .\web\update\
|
11
src/main.cpp
11
src/main.cpp
@ -212,11 +212,14 @@ void handleUpdateFirmware(uint8_t* packet)
|
||||
switch (OTAUpdateEnabled)
|
||||
{
|
||||
case 1:
|
||||
_dln("Checking for update (fixed)");
|
||||
result = ESPhttpUpdate.update(OTAUpdateFixedHost, OTAUpdateFixedPort, OTAUpdateFixedPath, FirmwareVersion);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
{
|
||||
_dln("Checking for update (client defined)");
|
||||
|
||||
uint16_t port;
|
||||
memcpy(&port, packet, sizeof(port));
|
||||
packet += sizeof(port);
|
||||
@ -251,19 +254,25 @@ void handleUpdateFirmware(uint8_t* packet)
|
||||
switch (result)
|
||||
{
|
||||
case HTTP_UPDATE_NO_UPDATES:
|
||||
_dln("No updates");
|
||||
udpServer.write(Command::UpdateFirmware);
|
||||
udpServer.write((uint8_t)0);
|
||||
break;
|
||||
|
||||
case HTTP_UPDATE_OK:
|
||||
_dln("Update OK");
|
||||
udpServer.write(Command::UpdateFirmware);
|
||||
udpServer.write((uint8_t)1);
|
||||
break;
|
||||
|
||||
default:
|
||||
_d("Error while updating: ");
|
||||
_dln(ESPhttpUpdate.getLastError());
|
||||
_dln(ESPhttpUpdate.getLastErrorString().c_str());
|
||||
|
||||
udpServer.write(Command::Error);
|
||||
udpServer.write(Command::UpdateFirmware);
|
||||
udpServer.write((uint8_t)1);
|
||||
udpServer.write((uint8_t)2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -51,25 +51,37 @@ void Stairs::setAll(uint16_t brightness)
|
||||
|
||||
uint16_t Stairs::getPWMValue(uint8_t step, uint16_t brightness)
|
||||
{
|
||||
_d("Getting PWM value for step "); _d(step); _d(", brightness "); _dln(brightness);
|
||||
if (brightness == IStairs::Off || brightness == IStairs::On)
|
||||
{
|
||||
_dln("Full on/off, returning input");
|
||||
return brightness;
|
||||
}
|
||||
|
||||
if (step < 0 || step >= StepCount)
|
||||
{
|
||||
_dln("Step out of bounds, returning input");
|
||||
return brightness;
|
||||
}
|
||||
|
||||
Range* range = &this->ranges[step];
|
||||
_d("Start: "); _dln(range->start);
|
||||
_d("End: "); _dln(range->end);
|
||||
|
||||
if (this->useScaling)
|
||||
{
|
||||
_dln("Using scaling");
|
||||
float factor = ((range->end - range->start) + 1) * factorBase;
|
||||
brightness = pow(2, (brightness / factor)) - 1 + range->start;
|
||||
}
|
||||
else
|
||||
{
|
||||
_dln("Not using scaling");
|
||||
if (brightness < range->start) brightness = range->start;
|
||||
if (brightness > range->end) brightness = range->end;
|
||||
}
|
||||
|
||||
_d("Output: "); _dln(brightness);
|
||||
return brightness;
|
||||
}
|
||||
|
||||
|
@ -1,6 +0,0 @@
|
||||
#ifndef __Version
|
||||
#define __Version
|
||||
|
||||
static const char* FirmwareVersion = "0.1.0+8";
|
||||
|
||||
#endif
|
21
web/app.js
21
web/app.js
@ -1,4 +1,5 @@
|
||||
var fs = require('fs');
|
||||
var md5File = require('md5-file');
|
||||
var express = require('express');
|
||||
var semverUtils = require('semver-utils')
|
||||
var client = require('./client');
|
||||
@ -8,7 +9,7 @@ var httpPort = 3127;
|
||||
var stairsHost = '10.138.2.25';
|
||||
var stairsUdpPort = 3126;
|
||||
|
||||
var firmwareFile = './update/firmware.elf';
|
||||
var firmwareFile = './update/firmware.bin';
|
||||
|
||||
|
||||
function requireNoCache(filename)
|
||||
@ -29,7 +30,7 @@ function isNewer(version1, version2)
|
||||
if (version1.patch > version2.patch) return true;
|
||||
if (version1.patch < version2.patch) return false;
|
||||
|
||||
if (version1.build > version2.build) return true;
|
||||
if (parseInt(version1.build, 10) > parseInt(version2.build, 10)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -102,14 +103,26 @@ app.get('/checkUpdate', function(req, res)
|
||||
|
||||
if (isNewer(localVersion, deviceVersion))
|
||||
{
|
||||
console.log('Sending update');
|
||||
|
||||
md5File(firmwareFile, function(err, hash)
|
||||
{
|
||||
if (err)
|
||||
{
|
||||
res.sendStatus(500);
|
||||
return;
|
||||
}
|
||||
|
||||
res.set('Content-Length', fs.statSync(firmwareFile).size);
|
||||
res.set('x-MD5', hash);
|
||||
res.download(firmwareFile);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
console.log('No update required');
|
||||
res.sendStatus(304);
|
||||
}
|
||||
|
||||
res.send(304);
|
||||
});
|
||||
|
||||
app.use(express.static(__dirname + '/static'));
|
||||
|
@ -8,6 +8,7 @@
|
||||
"dependencies": {
|
||||
"buffer-reader": "^0.1.0",
|
||||
"express": "^4.15.2",
|
||||
"md5-file": "^3.1.1",
|
||||
"semver-utils": "^1.1.1"
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +0,0 @@
|
||||
module.exports =
|
||||
{
|
||||
Version: "0.1.0+8"
|
||||
};
|
Loading…
Reference in New Issue
Block a user