-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add support for ESP32 non-Nimble, add new begin() method, for env with existing ble server * fix typos in Nimble files * nano iot 33 ota fails, syntax error * Update library.properties remove nimble-arduino * Update ArduinoBleOtaClassESP32Ble.h incorporate change of security.h filname * migrate OTAESP32 to security and upload callbacks * change hw/sw name defs to string type * remove start advertising and adduuid from serfer and storage only begin functions, leave that to the using app * remove service start * remove advertising and service start from ESP32 startup * cleanup EnableUpload, add advertise option * fix spurious comma typo esp32 * Changed defines * Added defines header * Added defines header * Added new target * Rename to USE_NATIVE_ESP32_BLE_LIB * Removed unneded includes * Fixed multiservice * Update ArduinoOTA lib --------- Co-authored-by: Sam Detweiler <[email protected]>
- Loading branch information
1 parent
a36d086
commit cfe9bf4
Showing
15 changed files
with
258 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.pio | ||
.vscode | ||
.DS_Store | ||
*.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
#pragma once | ||
|
||
#include "BleOtaDefines.h" | ||
#ifdef USE_NIM_BLE_ARDUINO_LIB | ||
#include "ArduinoBleOtaClassNimBle.h" | ||
#elif USE_NATIVE_ESP32_BLE_LIB | ||
#include "ArduinoBleOtaClassNativeESP32.h" | ||
#else | ||
#include "ArduinoBleOtaClass.h" | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
#include "BleOtaDefines.h" | ||
#ifdef USE_NATIVE_ESP32_BLE_LIB | ||
#include "ArduinoBleOtaClassNativeESP32.h" | ||
#include "BleOtaUploader.h" | ||
#include "BleOtaUuids.h" | ||
#include "BleOtaSizes.h" | ||
|
||
namespace | ||
{ | ||
static BleOtaSecurityCallbacks dummySecurityCallbacks{}; | ||
static BleOtaUploadCallbacks dummyUploadCallbacks{}; | ||
} | ||
|
||
ArduinoBleOTAClass::ArduinoBleOTAClass() : | ||
txCharacteristic(), | ||
securityCallbacks(&dummySecurityCallbacks), | ||
uploadCallbacks(&dummyUploadCallbacks) | ||
{} | ||
|
||
bool ArduinoBleOTAClass::begin(const std::string& deviceName, OTAStorage& storage, | ||
const std::string& hwName, BleOtaVersion hwVersion, | ||
const std::string& swName, BleOtaVersion swVersion, | ||
bool enableUpload) | ||
{ | ||
BLEDevice::init(deviceName); | ||
auto* server = BLEDevice::createServer(); | ||
|
||
if(!begin(storage, hwName, hwVersion, swName, swVersion, enableUpload)) | ||
return false; | ||
|
||
auto* advertising = server->getAdvertising(); | ||
advertising->setScanResponse(true); | ||
advertising->setMinPreferred(0x06); // functions that help with iPhone connections issue | ||
advertising->setMaxPreferred(0x12); | ||
advertising->start(); | ||
return true; | ||
} | ||
|
||
bool ArduinoBleOTAClass::begin(OTAStorage& storage, | ||
const std::string& hwName, BleOtaVersion hwVersion, | ||
const std::string& swName, BleOtaVersion swVersion, | ||
bool enableUpload) | ||
{ | ||
auto* server = BLEDevice::createServer(); | ||
BLEDevice::setMTU(BLE_OTA_MTU_SIZE); | ||
|
||
bleOtaUploader.begin(storage); | ||
bleOtaUploader.setEnabling(enableUpload); | ||
auto* service = server->createService(BLE_OTA_SERVICE_UUID); | ||
|
||
auto* rxCharacteristic = service->createCharacteristic( | ||
BLE_OTA_CHARACTERISTIC_UUID_RX, | ||
BLECharacteristic::PROPERTY_WRITE_NR | ||
); | ||
rxCharacteristic->setCallbacks(this); | ||
|
||
auto* txCharacteristic = service->createCharacteristic( | ||
BLE_OTA_CHARACTERISTIC_UUID_TX, | ||
BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_NOTIFY | ||
); | ||
this->txCharacteristic = txCharacteristic; | ||
|
||
begin(*service, hwName, hwVersion, swName, swVersion); | ||
|
||
auto* advertising = server->getAdvertising(); | ||
advertising->addServiceUUID(BLE_OTA_SERVICE_UUID); | ||
service->start(); | ||
return true; | ||
} | ||
|
||
void ArduinoBleOTAClass::begin(BLEService& service, | ||
const std::string& hwName, BleOtaVersion hwVersion, | ||
const std::string& swName, BleOtaVersion swVersion) | ||
{ | ||
auto* hwNameCharacteristic = service.createCharacteristic( | ||
BLE_OTA_CHARACTERISTIC_UUID_HW_NAME, | ||
BLECharacteristic::PROPERTY_READ | ||
); | ||
hwNameCharacteristic->setValue(hwName); | ||
auto* swNameCharacteristic = service.createCharacteristic( | ||
BLE_OTA_CHARACTERISTIC_UUID_SW_NAME, | ||
BLECharacteristic::PROPERTY_READ | ||
); | ||
swNameCharacteristic->setValue(swName); | ||
auto* hwVerCharacteristic = service.createCharacteristic( | ||
BLE_OTA_CHARACTERISTIC_UUID_HW_VER, | ||
BLECharacteristic::PROPERTY_READ | ||
); | ||
hwVerCharacteristic->setValue((uint8_t*)(&hwVersion), sizeof(BleOtaVersion)); | ||
auto* swVerCharacteristic = service.createCharacteristic( | ||
BLE_OTA_CHARACTERISTIC_UUID_SW_VER, | ||
BLECharacteristic::PROPERTY_READ | ||
); | ||
swVerCharacteristic->setValue((uint8_t*)(&swVersion), sizeof(BleOtaVersion)); | ||
} | ||
|
||
void ArduinoBleOTAClass::pull() | ||
{ | ||
bleOtaUploader.pull(); | ||
} | ||
|
||
void ArduinoBleOTAClass::enableUpload() | ||
{ | ||
bleOtaUploader.setEnabling(true); | ||
} | ||
|
||
void ArduinoBleOTAClass::disableUpload() | ||
{ | ||
bleOtaUploader.setEnabling(false); | ||
} | ||
|
||
void ArduinoBleOTAClass::setSecurityCallbacks(BleOtaSecurityCallbacks& cb) | ||
{ | ||
securityCallbacks = &cb; | ||
} | ||
|
||
void ArduinoBleOTAClass::setUploadCallbacks(BleOtaUploadCallbacks& cb) | ||
{ | ||
uploadCallbacks = &cb; | ||
} | ||
|
||
void ArduinoBleOTAClass::onWrite(BLECharacteristic* characteristic) | ||
{ | ||
auto value = characteristic->getValue(); | ||
auto data = value.data(); | ||
auto length = value.length(); | ||
|
||
bleOtaUploader.onData((uint8_t*)data, length); | ||
} | ||
|
||
void ArduinoBleOTAClass::send(const uint8_t* data, size_t length) | ||
{ | ||
txCharacteristic->setValue((uint8_t*)data, length); | ||
txCharacteristic->notify(); | ||
} | ||
|
||
ArduinoBleOTAClass ArduinoBleOTA{}; | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#pragma once | ||
#include "BleOtaStorage.h" | ||
#include "BleOtaVersion.h" | ||
#include "BleOtaSecurityCallbacks.h" | ||
#include "BleOtaUploadCallbacks.h" | ||
#include <BLEDevice.h> | ||
|
||
class BleOtaUploader; | ||
|
||
class ArduinoBleOTAClass: public BLECharacteristicCallbacks | ||
{ | ||
public: | ||
ArduinoBleOTAClass(); | ||
|
||
bool begin(const std::string& deviceName, | ||
OTAStorage& storage, | ||
const std::string& hwName = " ", | ||
BleOtaVersion hwVersion = {}, | ||
const std::string& swName = " ", | ||
BleOtaVersion swVersion = {}, | ||
bool enableUpload = true); | ||
bool begin(OTAStorage& storage, | ||
const std::string& hwName = " ", | ||
BleOtaVersion hwVersion = {}, | ||
const std::string& swName = " ", | ||
BleOtaVersion swVersion = {}, | ||
bool enableUpload = true); | ||
void pull(); | ||
|
||
void enableUpload(); | ||
void disableUpload(); | ||
void setSecurityCallbacks(BleOtaSecurityCallbacks&); | ||
void setUploadCallbacks(BleOtaUploadCallbacks&); | ||
|
||
private: | ||
friend BleOtaUploader; | ||
void begin(BLEService& service, | ||
const std::string& hwName, BleOtaVersion hwVersion, | ||
const std::string& swName, BleOtaVersion swVersion); | ||
void onWrite(BLECharacteristic* characteristic) override; | ||
void send(const uint8_t* data, size_t length); | ||
|
||
BLECharacteristic* txCharacteristic; | ||
BleOtaSecurityCallbacks* securityCallbacks; | ||
BleOtaUploadCallbacks* uploadCallbacks; | ||
}; | ||
|
||
extern ArduinoBleOTAClass ArduinoBleOTA; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#pragma once | ||
|
||
#if !defined(USE_NIM_BLE_ARDUINO_LIB) && !defined(USE_NATIVE_ESP32_BLE_LIB) && !defined(USE_ARDUINO_BLE_LIB) | ||
#define USE_ARDUINO_BLE_LIB | ||
#endif |
Oops, something went wrong.