1- import React from 'react' ;
1+
2+ /***************************************************
3+ This is a React WebApp written to Flash an ESP32 via BLE
4+
5+ Written by Andrew England (SparkFun)
6+ BSD license, all text above must be included in any redistribution.
7+ *****************************************************/
8+
9+ import React from 'react' ;
210import Popup from 'react-popup' ;
311import './App.css' ;
412
@@ -36,9 +44,7 @@ function BTConnect(){
3644 optionalServices : [ otaServiceUuid ]
3745 } )
3846 . then ( device => {
39- esp32Device = device ;
40- esp32Device . addEventListener ( 'gattserverdisconnected' , onDisconnected ) ;
41- return esp32Device . gatt . connect ( )
47+ return device . gatt . connect ( )
4248 } )
4349 . then ( server => server . getPrimaryService ( otaServiceUuid ) )
4450 . then ( service => {
@@ -90,6 +96,8 @@ function CheckVersion(){
9096 . then ( value => {
9197 currentHardwareVersion = 'v' + value . getUint8 ( 0 ) + '.' + value . getUint8 ( 1 ) ;
9298 softwareVersion = 'v' + value . getUint8 ( 2 ) + '.' + value . getUint8 ( 3 ) + '.' + value . getUint8 ( 4 ) ;
99+ document . getElementById ( 'hw_version' ) . innerHTML = "Hardware: " + currentHardwareVersion ;
100+ document . getElementById ( 'sw_version' ) . innerHTML = "Software: " + softwareVersion ;
93101 } )
94102 //Grab our version numbers from Github
95103 . then ( _ => fetch ( 'https://raw.githubusercontent.com/sparkfun/ESP32_OTA_BLE_React_WebApp_Demo/master/GithubRepo/version.json' ) )
@@ -99,8 +107,6 @@ function CheckVersion(){
99107 } )
100108 . then ( function ( data ) {
101109 // JSON should be formatted so that 0'th entry is the newest version
102- document . getElementById ( 'hw_version' ) . innerHTML = "Hardware: " + currentHardwareVersion ;
103- document . getElementById ( 'sw_version' ) . innerHTML = "Software: " + softwareVersion ;
104110 if ( latestCompatibleSoftware === softwareVersion )
105111 {
106112 //Software is updated, do nothing.
@@ -109,10 +115,10 @@ function CheckVersion(){
109115 var softwareVersionCount = 0 ;
110116 latestCompatibleSoftware = data . firmware [ softwareVersionCount ] [ 'software' ] ;
111117 versionFindLoop:
112- while ( latestCompatibleSoftware !== ' undefined' ) {
118+ while ( latestCompatibleSoftware !== undefined ) {
113119 var compatibleHardwareVersion = "N/A"
114120 var hardwareVersionCount = 0 ;
115- while ( compatibleHardwareVersion !== ' undefined' ) {
121+ while ( compatibleHardwareVersion !== undefined ) {
116122 compatibleHardwareVersion = data . firmware [ softwareVersionCount ] [ 'hardware' ] [ hardwareVersionCount ++ ] ;
117123 if ( compatibleHardwareVersion === currentHardwareVersion )
118124 {
@@ -212,12 +218,6 @@ function SendBufferedData() {
212218 console . log ( "remaining: " + remaining ) ;
213219 esp32Service . getCharacteristic ( fileCharacteristicUuid )
214220 . then ( characteristic => RecursiveSend ( characteristic , dataToSend ) )
215- . then ( _ => {
216- if ( remaining === 0 )
217- {
218- esp32Device . gatt . disconnect ( )
219- }
220- } )
221221 . then ( _ => {
222222 return document . getElementById ( 'completion' ) . innerHTML = ( 100 * ( currentPosition / totalSize ) ) . toPrecision ( 3 ) + '%' ;
223223 } )
0 commit comments