@@ -18,7 +18,7 @@ var remaining;
18
18
var amountToWrite ;
19
19
var currentPosition ;
20
20
21
- var hardwareVersion = "N/A" ;
21
+ var currentHardwareVersion = "N/A" ;
22
22
var softwareVersion = "N/A" ;
23
23
var latestSoftware = "N/A" ;
24
24
@@ -59,9 +59,14 @@ function CheckVersion(){
59
59
{
60
60
return ;
61
61
}
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
+ } )
63
68
//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' ) )
65
70
. then ( function ( response ) {
66
71
// The API call was successful!
67
72
return response . json ( ) ;
@@ -70,28 +75,23 @@ function CheckVersion(){
70
75
// JSON should be formatted so that 0'th entry is the newest version
71
76
latestSoftware = data . firmware [ 0 ] [ 'software' ] ;
72
77
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 ;
88
79
document . getElementById ( 'sw_version' ) . innerHTML = "Software: " + softwareVersion ;
89
80
if ( latestSoftware === softwareVersion )
90
81
{
91
- //Do Nothing, maybe a pop up?
82
+ //Software is updated, do nothing.
92
83
}
93
84
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
+ }
95
95
}
96
96
} )
97
97
. catch ( error => { console . log ( error ) ; } ) ;
0 commit comments