-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Set IDF to v3.2 * Remove BLE submodule * Add BLE lib source * Update Camera example to support OV3660
- Loading branch information
Showing
247 changed files
with
15,354 additions
and
5,225 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,6 +1,3 @@ | ||
[submodule "libraries/BLE"] | ||
path = libraries/BLE | ||
url = https://github.com/nkolban/ESP32_BLE_Arduino.git | ||
[submodule "libraries/AzureIoT"] | ||
path = libraries/AzureIoT | ||
url = https://github.com/VSChina/ESP32_AzureIoT_Arduino |
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
Submodule BLE
deleted from
b232e7
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,15 @@ | ||
# ESP32 BLE for Arduino | ||
The Arduino IDE provides an excellent library package manager where versions of libraries can be downloaded and installed. This Github project provides the repository for the ESP32 BLE support for Arduino. | ||
|
||
The actual source of the project which is being maintained can be found here: | ||
|
||
https://github.com/nkolban/esp32-snippets | ||
|
||
Issues and questions should be raised here: | ||
|
||
https://github.com/nkolban/esp32-snippets/issues | ||
|
||
|
||
Documentation for using the library can be found here: | ||
|
||
https://github.com/nkolban/esp32-snippets/tree/master/Documentation |
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,160 @@ | ||
/** | ||
* A BLE client example that is rich in capabilities. | ||
* There is a lot new capabilities implemented. | ||
* author unknown | ||
* updated by chegewara | ||
*/ | ||
|
||
#include "BLEDevice.h" | ||
//#include "BLEScan.h" | ||
|
||
// The remote service we wish to connect to. | ||
static BLEUUID serviceUUID("4fafc201-1fb5-459e-8fcc-c5c9c331914b"); | ||
// The characteristic of the remote service we are interested in. | ||
static BLEUUID charUUID("beb5483e-36e1-4688-b7f5-ea07361b26a8"); | ||
|
||
static boolean doConnect = false; | ||
static boolean connected = false; | ||
static boolean doScan = false; | ||
static BLERemoteCharacteristic* pRemoteCharacteristic; | ||
static BLEAdvertisedDevice* myDevice; | ||
|
||
static void notifyCallback( | ||
BLERemoteCharacteristic* pBLERemoteCharacteristic, | ||
uint8_t* pData, | ||
size_t length, | ||
bool isNotify) { | ||
Serial.print("Notify callback for characteristic "); | ||
Serial.print(pBLERemoteCharacteristic->getUUID().toString().c_str()); | ||
Serial.print(" of data length "); | ||
Serial.println(length); | ||
Serial.print("data: "); | ||
Serial.println((char*)pData); | ||
} | ||
|
||
class MyClientCallback : public BLEClientCallbacks { | ||
void onConnect(BLEClient* pclient) { | ||
} | ||
|
||
void onDisconnect(BLEClient* pclient) { | ||
connected = false; | ||
Serial.println("onDisconnect"); | ||
} | ||
}; | ||
|
||
bool connectToServer() { | ||
Serial.print("Forming a connection to "); | ||
Serial.println(myDevice->getAddress().toString().c_str()); | ||
|
||
BLEClient* pClient = BLEDevice::createClient(); | ||
Serial.println(" - Created client"); | ||
|
||
pClient->setClientCallbacks(new MyClientCallback()); | ||
|
||
// Connect to the remove BLE Server. | ||
pClient->connect(myDevice); // if you pass BLEAdvertisedDevice instead of address, it will be recognized type of peer device address (public or private) | ||
Serial.println(" - Connected to server"); | ||
|
||
// Obtain a reference to the service we are after in the remote BLE server. | ||
BLERemoteService* pRemoteService = pClient->getService(serviceUUID); | ||
if (pRemoteService == nullptr) { | ||
Serial.print("Failed to find our service UUID: "); | ||
Serial.println(serviceUUID.toString().c_str()); | ||
pClient->disconnect(); | ||
return false; | ||
} | ||
Serial.println(" - Found our service"); | ||
|
||
|
||
// Obtain a reference to the characteristic in the service of the remote BLE server. | ||
pRemoteCharacteristic = pRemoteService->getCharacteristic(charUUID); | ||
if (pRemoteCharacteristic == nullptr) { | ||
Serial.print("Failed to find our characteristic UUID: "); | ||
Serial.println(charUUID.toString().c_str()); | ||
pClient->disconnect(); | ||
return false; | ||
} | ||
Serial.println(" - Found our characteristic"); | ||
|
||
// Read the value of the characteristic. | ||
if(pRemoteCharacteristic->canRead()) { | ||
std::string value = pRemoteCharacteristic->readValue(); | ||
Serial.print("The characteristic value was: "); | ||
Serial.println(value.c_str()); | ||
} | ||
|
||
if(pRemoteCharacteristic->canNotify()) | ||
pRemoteCharacteristic->registerForNotify(notifyCallback); | ||
|
||
connected = true; | ||
} | ||
/** | ||
* Scan for BLE servers and find the first one that advertises the service we are looking for. | ||
*/ | ||
class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks { | ||
/** | ||
* Called for each advertising BLE server. | ||
*/ | ||
void onResult(BLEAdvertisedDevice advertisedDevice) { | ||
Serial.print("BLE Advertised Device found: "); | ||
Serial.println(advertisedDevice.toString().c_str()); | ||
|
||
// We have found a device, let us now see if it contains the service we are looking for. | ||
if (advertisedDevice.haveServiceUUID() && advertisedDevice.isAdvertisingService(serviceUUID)) { | ||
|
||
BLEDevice::getScan()->stop(); | ||
myDevice = new BLEAdvertisedDevice(advertisedDevice); | ||
doConnect = true; | ||
doScan = true; | ||
|
||
} // Found our server | ||
} // onResult | ||
}; // MyAdvertisedDeviceCallbacks | ||
|
||
|
||
void setup() { | ||
Serial.begin(115200); | ||
Serial.println("Starting Arduino BLE Client application..."); | ||
BLEDevice::init(""); | ||
|
||
// Retrieve a Scanner and set the callback we want to use to be informed when we | ||
// have detected a new device. Specify that we want active scanning and start the | ||
// scan to run for 5 seconds. | ||
BLEScan* pBLEScan = BLEDevice::getScan(); | ||
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks()); | ||
pBLEScan->setInterval(1349); | ||
pBLEScan->setWindow(449); | ||
pBLEScan->setActiveScan(true); | ||
pBLEScan->start(5, false); | ||
} // End of setup. | ||
|
||
|
||
// This is the Arduino main loop function. | ||
void loop() { | ||
|
||
// If the flag "doConnect" is true then we have scanned for and found the desired | ||
// BLE Server with which we wish to connect. Now we connect to it. Once we are | ||
// connected we set the connected flag to be true. | ||
if (doConnect == true) { | ||
if (connectToServer()) { | ||
Serial.println("We are now connected to the BLE Server."); | ||
} else { | ||
Serial.println("We have failed to connect to the server; there is nothin more we will do."); | ||
} | ||
doConnect = false; | ||
} | ||
|
||
// If we are connected to a peer BLE Server, update the characteristic each time we are reached | ||
// with the current time since boot. | ||
if (connected) { | ||
String newValue = "Time since boot: " + String(millis()/1000); | ||
Serial.println("Setting new characteristic value to \"" + newValue + "\""); | ||
|
||
// Set the characteristic's value to be the array of bytes that is actually a string. | ||
pRemoteCharacteristic->writeValue(newValue.c_str(), newValue.length()); | ||
}else if(doScan){ | ||
BLEDevice::getScan()->start(0); // this is just eample to start scan after disconnect, most likely there is better way to do it in arduino | ||
} | ||
|
||
delay(1000); // Delay a second between loops. | ||
} // End of loop |
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,103 @@ | ||
/* | ||
Based on Neil Kolban example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleScan.cpp | ||
Ported to Arduino ESP32 by pcbreflux | ||
*/ | ||
|
||
|
||
/* | ||
Create a BLE server that will send periodic iBeacon frames. | ||
The design of creating the BLE server is: | ||
1. Create a BLE Server | ||
2. Create advertising data | ||
3. Start advertising. | ||
4. wait | ||
5. Stop advertising. | ||
6. deep sleep | ||
*/ | ||
#include "sys/time.h" | ||
|
||
#include "BLEDevice.h" | ||
#include "BLEUtils.h" | ||
#include "BLEBeacon.h" | ||
#include "esp_sleep.h" | ||
|
||
#define GPIO_DEEP_SLEEP_DURATION 10 // sleep x seconds and then wake up | ||
RTC_DATA_ATTR static time_t last; // remember last boot in RTC Memory | ||
RTC_DATA_ATTR static uint32_t bootcount; // remember number of boots in RTC Memory | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
uint8_t temprature_sens_read(); | ||
//uint8_t g_phyFuns; | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
// See the following for generating UUIDs: | ||
// https://www.uuidgenerator.net/ | ||
BLEAdvertising *pAdvertising; | ||
struct timeval now; | ||
|
||
#define BEACON_UUID "8ec76ea3-6668-48da-9866-75be8bc86f4d" // UUID 1 128-Bit (may use linux tool uuidgen or random numbers via https://www.uuidgenerator.net/) | ||
|
||
void setBeacon() { | ||
|
||
BLEBeacon oBeacon = BLEBeacon(); | ||
oBeacon.setManufacturerId(0x4C00); // fake Apple 0x004C LSB (ENDIAN_CHANGE_U16!) | ||
oBeacon.setProximityUUID(BLEUUID(BEACON_UUID)); | ||
oBeacon.setMajor((bootcount & 0xFFFF0000) >> 16); | ||
oBeacon.setMinor(bootcount&0xFFFF); | ||
BLEAdvertisementData oAdvertisementData = BLEAdvertisementData(); | ||
BLEAdvertisementData oScanResponseData = BLEAdvertisementData(); | ||
|
||
oAdvertisementData.setFlags(0x04); // BR_EDR_NOT_SUPPORTED 0x04 | ||
|
||
std::string strServiceData = ""; | ||
|
||
strServiceData += (char)26; // Len | ||
strServiceData += (char)0xFF; // Type | ||
strServiceData += oBeacon.getData(); | ||
oAdvertisementData.addData(strServiceData); | ||
|
||
pAdvertising->setAdvertisementData(oAdvertisementData); | ||
pAdvertising->setScanResponseData(oScanResponseData); | ||
|
||
} | ||
|
||
void setup() { | ||
|
||
|
||
Serial.begin(115200); | ||
gettimeofday(&now, NULL); | ||
|
||
Serial.printf("start ESP32 %d\n",bootcount++); | ||
|
||
Serial.printf("deep sleep (%lds since last reset, %lds since last boot)\n",now.tv_sec,now.tv_sec-last); | ||
|
||
last = now.tv_sec; | ||
|
||
// Create the BLE Device | ||
BLEDevice::init(""); | ||
|
||
// Create the BLE Server | ||
// BLEServer *pServer = BLEDevice::createServer(); // <-- no longer required to instantiate BLEServer, less flash and ram usage | ||
|
||
pAdvertising = BLEDevice::getAdvertising(); | ||
|
||
setBeacon(); | ||
// Start advertising | ||
pAdvertising->start(); | ||
Serial.println("Advertizing started..."); | ||
delay(100); | ||
pAdvertising->stop(); | ||
Serial.printf("enter deep sleep\n"); | ||
esp_deep_sleep(1000000LL * GPIO_DEEP_SLEEP_DURATION); | ||
Serial.printf("in deep sleep\n"); | ||
} | ||
|
||
void loop() { | ||
} |
Oops, something went wrong.