Skip to content

Commit 88fb223

Browse files
updating JSON to add a software version that is incompatible with current hardware
1 parent 29c4f3b commit 88fb223

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

WebApp/ota-app/src/App.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var remaining;
1818
var amountToWrite;
1919
var currentPosition;
2020

21-
var hardwareVersion = "N/A";
21+
var currentHardwareVersion = "N/A";
2222
var softwareVersion = "N/A";
2323
var latestSoftware = "N/A";
2424

@@ -59,9 +59,14 @@ function CheckVersion(){
5959
{
6060
return;
6161
}
62-
62+
return esp32Service.getCharacteristic(versionCharacteristicUuid)
63+
.then(characteristic => characteristic.readValue())
64+
.then(value => {
65+
currentHardwareVersion = 'v' + value.getUint8(0) + '.' + value.getUint8(1);
66+
softwareVersion = 'v' + value.getUint8(2) + '.' + value.getUint8(3) + '.' + value.getUint8(4);
67+
})
6368
//Grab our version numbers from Github
64-
fetch('https://raw.githubusercontent.com/sparkfun/ESP32_OTA_BLE_React_WebApp_Demo/master/version.json')
69+
.then(_ => fetch('https://raw.githubusercontent.com/sparkfun/ESP32_OTA_BLE_React_WebApp_Demo/master/version.json?token=AHAFCBQ5IDR5PW7K3TJO2I267TK2E'))
6570
.then(function (response) {
6671
// The API call was successful!
6772
return response.json();
@@ -70,28 +75,23 @@ function CheckVersion(){
7075
// JSON should be formatted so that 0'th entry is the newest version
7176
latestSoftware = data.firmware[0]['software'];
7277
console.log(latestSoftware);
73-
74-
})
75-
.catch(function (err) { console.warn('Something went wrong.', err); });
76-
77-
return esp32Service.getCharacteristic(versionCharacteristicUuid)
78-
.then(characteristic => characteristic.readValue())
79-
.then(value => {
80-
/*for (var i = 0; i < 5; i++) { //TODO: change bounds from hardcode to actual Version space
81-
versionCharacteristicBuffer[i] = value.getUint8(i);
82-
}*/
83-
hardwareVersion = 'v' + value.getUint8(0) + '.' + value.getUint8(1);
84-
softwareVersion = 'v' + value.getUint8(2) + '.' + value.getUint8(3) + '.' + value.getUint8(4);
85-
})
86-
.then(_ => {
87-
document.getElementById('hw_version').innerHTML = "Hardware: " + hardwareVersion;
78+
document.getElementById('hw_version').innerHTML = "Hardware: " + currentHardwareVersion;
8879
document.getElementById('sw_version').innerHTML = "Software: " + softwareVersion;
8980
if (latestSoftware === softwareVersion)
9081
{
91-
//Do Nothing, maybe a pop up?
82+
//Software is updated, do nothing.
9283
}
9384
else {
94-
PromptUserForUpdate()
85+
var compatibleHardwareVersion = "N/A"
86+
var hardwareNumber = 0;
87+
while (compatibleHardwareVersion !== undefined) {
88+
compatibleHardwareVersion = data.firmware[0]['hardware'][hardwareNumber++];
89+
if (compatibleHardwareVersion === currentHardwareVersion)
90+
{
91+
console.log(currentHardwareVersion);
92+
}
93+
PromptUserForUpdate()
94+
}
9595
}
9696
})
9797
.catch(error => { console.log(error); });

version.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
{
22
"firmware": [
3+
{
4+
"software": "v2.0.0",
5+
"hardware": [
6+
"v2.0"
7+
]
8+
},
39
{
410
"software": "v0.1.1",
511
"hardware": [

0 commit comments

Comments
 (0)