Skip to content

Commit f4b2e6b

Browse files
everything ready for commit of v0.1.0
1 parent 1a8ac02 commit f4b2e6b

25 files changed

+60
-42
lines changed

Arduino Sketch/main/BLE.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55

66
#include "BLE.h"
77

8-
#define SERVICE_UUID_ESPOTA "e804b643-6ce7-4e81-9f8a-ce0f699085eb"
9-
#define CHARACTERISTIC_UUID_ID "e804b644-6ce7-4e81-9f8a-ce0f699085eb"
8+
#define SERVICE_UUID_ESPOTA "d804b643-6ce7-4e81-9f8a-ce0f699085eb"
9+
#define CHARACTERISTIC_UUID_ID "d804b644-6ce7-4e81-9f8a-ce0f699085eb"
1010

11-
#define SERVICE_UUID_OTA "b8659210-af91-4ad3-a995-a58d6fd26145" // UART service UUID
12-
#define CHARACTERISTIC_UUID_FW "b8659211-af91-4ad3-a995-a58d6fd26145"
13-
#define CHARACTERISTIC_UUID_HW_VERSION "b8659212-af91-4ad3-a995-a58d6fd26145"
14-
#define CHARACTERISTIC_UUID_READY "b8659213-af91-4ad3-a995-a58d6fd26145"
11+
#define SERVICE_UUID_OTA "c8659210-af91-4ad3-a995-a58d6fd26145"
12+
#define CHARACTERISTIC_UUID_FW "c8659211-af91-4ad3-a995-a58d6fd26145"
13+
#define CHARACTERISTIC_UUID_HW_VERSION "c8659212-af91-4ad3-a995-a58d6fd26145"
1514

1615
#define FULL_PACKET 512
1716
#define CHARPOS_UPDATE_FLAG 5
@@ -51,7 +50,6 @@ void otaCallback::onWrite(BLECharacteristic *pCharacteristic)
5150
}
5251

5352
uint8_t txData[5] = {1, 2, 3, 4, 5};
54-
//delay(1000);
5553
pCharacteristic->setValue((uint8_t*)txData, 5);
5654
pCharacteristic->notify();
5755
}

Arduino Sketch/main/BLE.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222

2323
#define SOFTWARE_VERSION_MAJOR 0
2424
#define SOFTWARE_VERSION_MINOR 1
25-
#define SOFTWARE_VERSION_PATCH 1
25+
#define SOFTWARE_VERSION_PATCH 0
2626
#define HARDWARE_VERSION_MAJOR 1
27-
#define HARDWARE_VERSION_MINOR 2
27+
#define HARDWARE_VERSION_MINOR 3
2828

2929
class BLE; // forward declaration
3030

Binary file not shown.

GithubRepo/v1.2.bin

0 Bytes
Binary file not shown.

GithubRepo/v1.3.bin

0 Bytes
Binary file not shown.

GithubRepo/v1_3.bin

-940 KB
Binary file not shown.

GithubRepo/version.json

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
{
22
"firmware": [
3-
{
4-
"software": "v0.1.1",
5-
"hardware": [
6-
"v1.3",
7-
"v1.2"
8-
]
9-
},
103
{
114
"software": "v0.1.0",
125
"hardware": [
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

WebApp/ota-app/src/App.js renamed to WebApp/src/App.js

Lines changed: 53 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ import React from 'react';
22
import Popup from 'react-popup';
33
import './App.css';
44

5-
var myESP32 = 'e804b643-6ce7-4e81-9f8a-ce0f699085eb'
5+
var myESP32 = 'd804b643-6ce7-4e81-9f8a-ce0f699085eb'
66

7-
var otaServiceUuid = 'b8659210-af91-4ad3-a995-a58d6fd26145'
8-
var versionCharacteristicUuid = 'b8659212-af91-4ad3-a995-a58d6fd26145'
9-
var fileCharacteristicUuid = 'b8659211-af91-4ad3-a995-a58d6fd26145'
7+
var otaServiceUuid = 'c8659210-af91-4ad3-a995-a58d6fd26145'
8+
var versionCharacteristicUuid = 'c8659212-af91-4ad3-a995-a58d6fd26145'
9+
var fileCharacteristicUuid = 'c8659211-af91-4ad3-a995-a58d6fd26145'
1010

11+
let esp32Device = null;
1112
let esp32Service = null;
1213
let readyFlagCharacteristic = null;
1314
let dataToSend = null;
@@ -26,8 +27,6 @@ const characteristicSize = 512;
2627

2728
/* BTConnect
2829
* Brings up the bluetooth connection window and filters for the esp32
29-
* TODO:
30-
* 10-Add handler for disconnect so page doesn't crash
3130
*/
3231
function BTConnect(){
3332
navigator.bluetooth.requestDevice({
@@ -36,7 +35,11 @@ function BTConnect(){
3635
}],
3736
optionalServices: [otaServiceUuid]
3837
})
39-
.then(device => device.gatt.connect())
38+
.then(device => {
39+
esp32Device = device;
40+
esp32Device.addEventListener('gattserverdisconnected', onDisconnected);
41+
return esp32Device.gatt.connect()
42+
})
4043
.then(server => server.getPrimaryService(otaServiceUuid))
4144
.then(service => {
4245
esp32Service = service;
@@ -50,6 +53,29 @@ function BTConnect(){
5053
.catch(error => { console.log(error); });
5154
}
5255

56+
/* onDisconnected(event)
57+
* If the device becomes disconnected, prompt the user to reconnect.
58+
*/
59+
function onDisconnected(event) {
60+
Popup.create({
61+
content: esp32Device.name + ' is disconnected, would you like to reconnect?',
62+
buttons: {
63+
left: [{
64+
text: 'Yes',
65+
action: function () {
66+
Popup.close();
67+
BTConnect();
68+
}
69+
}],
70+
right: [{
71+
text: 'No',
72+
action: function () {
73+
Popup.close();
74+
}
75+
}]
76+
}
77+
})
78+
}
5379

5480
/* CheckVersion()
5581
* Grab most current version from Github and Server, if they don't match, prompt the user for firmware update
@@ -66,7 +92,7 @@ function CheckVersion(){
6692
softwareVersion = 'v' + value.getUint8(2) + '.' + value.getUint8(3) + '.' + value.getUint8(4);
6793
})
6894
//Grab our version numbers from Github
69-
.then(_ => fetch('https://raw.githubusercontent.com/sparkfun/ESP32_OTA_BLE_React_WebApp_Demo/master/version.json'))
95+
.then(_ => fetch('https://raw.githubusercontent.com/sparkfun/ESP32_OTA_BLE_React_WebApp_Demo/master/GithubRepo/version.json'))
7096
.then(function (response) {
7197
// The API call was successful!
7298
return response.json();
@@ -83,35 +109,31 @@ function CheckVersion(){
83109
var softwareVersionCount = 0;
84110
latestCompatibleSoftware = data.firmware[softwareVersionCount]['software'];
85111
versionFindLoop:
86-
while (latestCompatibleSoftware !== undefined) {
112+
while (latestCompatibleSoftware !=='undefined') {
87113
var compatibleHardwareVersion = "N/A"
88114
var hardwareVersionCount = 0;
89-
while (compatibleHardwareVersion !== undefined) {
115+
while (compatibleHardwareVersion !== 'undefined') {
90116
compatibleHardwareVersion = data.firmware[softwareVersionCount]['hardware'][hardwareVersionCount++];
91117
if (compatibleHardwareVersion === currentHardwareVersion)
92118
{
93119
latestCompatibleSoftware = data.firmware[softwareVersionCount]['software'];
94-
console.log(latestCompatibleSoftware);
95-
PromptUserForUpdate();
120+
if (latestCompatibleSoftware !== softwareVersion)
121+
{
122+
console.log(latestCompatibleSoftware);
123+
PromptUserForUpdate();
124+
}
96125
break versionFindLoop;
97126
}
98127
}
99128
softwareVersionCount++;
100129
}
101-
console.log("Uh oh, no compatible software found");
102130
}
103131
})
104132
.catch(error => { console.log(error); });
105133
}
106134

107135
/* PromptUserForUpdate()
108-
* Downloads the firmware based on the hardware version and latest software version
109-
* TODO:
110-
* 7-Make separate public repo for firmware and patchnotes
111-
* 5-Make github folder structure for different hardware versions
112-
* 6-Look at the specific release that matches software we want to switch to (Have html adapt to changing HW and SW versions)
113-
* 4-Get patchnotes from github release page(???) and display them with update prompt
114-
* 6-Use CSS to turn Popup into actual popup
136+
* Asks the user if they want to update, if yes downloads the firmware based on the hardware version and latest software version and begins sending
115137
*/
116138
function PromptUserForUpdate(){
117139
Popup.create({
@@ -120,7 +142,7 @@ function PromptUserForUpdate(){
120142
left: [{
121143
text: 'Yes',
122144
action: function () {
123-
fetch('https://raw.githubusercontent.com/AndyEngland521/Tet/master/Firmware/main/compiled/v1_3.bin')
145+
fetch('https://raw.githubusercontent.com/sparkfun/ESP32_OTA_BLE_React_WebApp_Demo/' + latestCompatibleSoftware + '/GithubRepo/' + currentHardwareVersion + '.bin')
124146
.then(function (response) {
125147
return response.arrayBuffer();
126148
})
@@ -136,7 +158,6 @@ function PromptUserForUpdate(){
136158
right: [{
137159
text: 'No',
138160
action: function () {
139-
/** Close this popup. Close will always close the current visible one, if one is visible */
140161
Popup.close();
141162
}
142163
}]
@@ -147,9 +168,6 @@ function PromptUserForUpdate(){
147168
/* SendFileOverBluetooth(data)
148169
* Figures out how large our update binary is, attaches an eventListener to our dataCharacteristic so the Server can tell us when it has finished writing the data to memory
149170
* Calls SendBufferedData(), which begins a loop of write, wait for ready flag, write, wait for ready flag...
150-
* TODO:
151-
* 8-Disconnect the eventListener once the update is complete
152-
* 7-Call SendBufferedData from promise returned by addEventListener or startNotifications (???Slight reliability improvement???)
153171
*/
154172
function SendFileOverBluetooth() {
155173
if(!esp32Service)
@@ -162,7 +180,6 @@ function SendFileOverBluetooth() {
162180
remaining = totalSize;
163181
amountToWrite = 0;
164182
currentPosition = 0;
165-
166183
esp32Service.getCharacteristic(fileCharacteristicUuid)
167184
.then(characteristic => {
168185
readyFlagCharacteristic = characteristic;
@@ -195,6 +212,15 @@ function SendBufferedData() {
195212
console.log("remaining: " + remaining);
196213
esp32Service.getCharacteristic(fileCharacteristicUuid)
197214
.then(characteristic => RecursiveSend(characteristic, dataToSend))
215+
.then(_ => {
216+
if (remaining === 0)
217+
{
218+
esp32Device.gatt.disconnect()
219+
}
220+
})
221+
.then(_ => {
222+
return document.getElementById('completion').innerHTML = (100 * (currentPosition/totalSize)).toPrecision(3) + '%';
223+
})
198224
.catch(error => {
199225
console.log(error);
200226
});
@@ -223,6 +249,7 @@ return (
223249
<Popup />
224250
<p id="hw_version">Hardware: Not Connected</p>
225251
<p id="sw_version">Software: Not Connected</p>
252+
<p id="completion"></p>
226253
<button id="connect"
227254
onClick={BTConnect}
228255
>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)