Skip to content
This repository has been archived by the owner on Dec 5, 2021. It is now read-only.

Commit

Permalink
Initial releases v1.0.6
Browse files Browse the repository at this point in the history
### Releases v1.0.6

1. Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer. 
2. Bump up to v1.0.6 to sync with [BlynkESP32_BT_WF library v1.0.6](https://github.com/khoih-prog/BlynkESP32_BT_WF).
  • Loading branch information
khoih-prog authored Aug 27, 2020
1 parent efde59a commit 819462c
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 44 deletions.
123 changes: 82 additions & 41 deletions examples/Async_PET_Check/Async_PET_Check.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
Async_PET_Check.ino
For ESP32 using WiFi along with BlueTooth BLE
Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32
Blynk_Async_ESP32_BT_WF is a library, using AsyncWebServer instead of (ESP8266)WebServer for inclusion of both ESP32
Blynk BT/BLE and WiFi libraries. Then select either one or both at runtime.
Based on and modified from Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases
Built by Khoi Hoang https://github.com/khoih-prog/Blynk_Async_ESP32_BT_WF
Licensed under MIT license
Expand All @@ -13,18 +13,18 @@
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer.
1.0.6 K Hoang 25/08/2020 Initial coding to use (ESP)AsyncWebServer instead of (ESP8266)WebServer.
Bump up to v1.0.16 to sync with BlynkESP32_BT_WF v1.0.6.
*****************************************************************************************************************************/
/****************************************************************************************************************************
Example Created by Miguel Alexandre Wisintainer
See https://nina-b302-scanner-presenca.blogspot.com/2020/06/nina-w102-ble-detector-presenca-de-pet.html
Date: 06/06/2020
Important Notes:
1) Sketch is ~0.9MB of code because only 1 instance of Blynk if #define BLYNK_USE_BT_ONLY => true
2) Sketch is very large (~1.3MB code) because 2 instances of Blynk if #define BLYNK_USE_BT_ONLY => false
3) To conmpile, use Partition Scheem with large APP size, such as
3) To conmpile, use Partition Scheme with large APP size, such as
a) 8MB Flash (3MB APP, 1.5MB FAT) if use EEPROM
b) No OTA (2MB APP, 2MB SPIFFS)
c) No OTA (2MB APP, 2MB FATFS) if use EEPROM
Expand Down Expand Up @@ -55,15 +55,18 @@ void set_led(byte status)

void noticeAlive(void)
{
if (USE_BLE)
Blynk_BLE.virtualWrite(V0, F("OK"));
else
Blynk_WF.virtualWrite(V0, F("OK"));
if (Blynk_WF.connected())
{
if (USE_BLE)
Blynk_BLE.virtualWrite(V0, F("OK"));
else
Blynk_WF.virtualWrite(V0, F("OK"));

if (NEAR_PET == 0) //NOT FOUND PET ON SCAN!!!!! ALERT THE BLYNK
Blynk_WF.notify("Hi, i cant find the PET!!!!");
if (NEAR_PET == 0) //NOT FOUND PET ON SCAN!!!!! ALERT THE BLYNK
Blynk_WF.notify("Hi, i cant find the PET!!!!");

NEAR_PET = 0; //SCAN AGAIN
NEAR_PET = 0; //SCAN AGAIN
}
}

void heartBeatPrint(void)
Expand All @@ -74,7 +77,7 @@ void heartBeatPrint(void)
{
set_led(HIGH);
led_ticker.once_ms(111, set_led, (byte) LOW);
Serial.print(F("B"));
Serial.print(F("B"));
}
else
{
Expand Down Expand Up @@ -115,16 +118,17 @@ char BLE_Device_Name[] = "PET-Check-BLE";

int scanTime = 5; //In seconds
BLEScan* pBLEScan;
bool BLE_Initialized = false;

char BLE_Manufacturer_Data[] = "4c000215fda50693a4e24fb1afcfc6eb07647825271b271bc9";

class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks
class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks
{
void onResult(BLEAdvertisedDevice advertisedDevice)
void onResult(BLEAdvertisedDevice advertisedDevice)
{
char* manufacturerdata = BLEUtils::buildHexData(NULL, (uint8_t*)advertisedDevice.getManufacturerData().data(), advertisedDevice.getManufacturerData().length());
Serial.println("Advertised Device: " + String(manufacturerdata));

if (strcmp(BLE_Manufacturer_Data, manufacturerdata) == 0)
{
NEAR_PET++; //just to identify that found the PET near!
Expand All @@ -135,12 +139,38 @@ class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks

void checkPet(void)
{
BLEScanResults foundDevices = pBLEScan->start(scanTime, false);
Serial.print(F("Devices found: "));
Serial.println(foundDevices.getCount());
Serial.println(F("Scan done!"));
// delete results fromBLEScan buffer to release memory
pBLEScan->clearResults();
if (BLE_Initialized)
{
Serial.println(F("Scanning..."));

BLEScanResults foundDevices = pBLEScan->start(scanTime, false);
Serial.print(F("Devices found: "));
Serial.println(foundDevices.getCount());
Serial.println(F("Scan done!"));
// delete results fromBLEScan buffer to release memory
pBLEScan->clearResults();
}
}

void init_BLE()
{
if (Blynk_WF.connected() && !BLE_Initialized)
{
BLEDevice::init("");

BLE_Initialized = true;

//create new scan
pBLEScan = BLEDevice::getScan();
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());

//active scan uses more power, but get results faster
pBLEScan->setActiveScan(true);

pBLEScan->setInterval(100);
// less or equal setInterval value
pBLEScan->setWindow(99);
}
}

void setup()
Expand All @@ -161,7 +191,7 @@ void setup()
#endif

pinMode(WIFI_BLE_SELECTION_PIN, INPUT_PULLUP);

pinMode(LED_BUILTIN, OUTPUT);

if (digitalRead(WIFI_BLE_SELECTION_PIN) == HIGH)
Expand All @@ -172,9 +202,27 @@ void setup()
#if ESP32_BLE_WF_DEBUG
Serial.println(F("USE_BLYNK_WM: Blynk_WF begin"));
#endif
// Set config portal channel, defalut = 1. Use 0 => random channel from 1-13 to avoid conflict
// Set config portal SSID and Password
Blynk.setConfigPortal("TestPortal-ESP32", "TestPortalPass");
// Set config portal IP address
Blynk.setConfigPortalIP(IPAddress(192, 168, 232, 1));

// Set config portal channel, default = 1. Use 0 => random channel from 1-13 to avoid conflict
Blynk_WF.setConfigPortalChannel(0);

// From v1.0.6, select either one of these to set static IP + DNS
Blynk.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0));
//Blynk.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0),
// IPAddress(192, 168, 2, 1), IPAddress(8, 8, 8, 8));
//Blynk.setSTAStaticIPConfig(IPAddress(192, 168, 2, 232), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0),
// IPAddress(4, 4, 4, 4), IPAddress(8, 8, 8, 8));

// Use this to default DHCP hostname to ESP8266-XXXXXX or ESP32-XXXXXX
//Blynk.begin();
// Use this to personalize DHCP hostname (RFC952 conformed)
// 24 chars max,- only a..z A..Z 0..9 '-' and no '-' as last char
//Blynk.begin("PET-Check-BLE");

Blynk_WF.begin(BLE_Device_Name);
#else
//Blynk_WF.begin(auth, ssid, pass);
Expand All @@ -187,8 +235,11 @@ void setup()
else
{
USE_BLE = true;

Serial.println(F("GPIO14 LOW, Use BLE"));

Blynk_BLE.setDeviceName(BLE_Device_Name);

#if USE_BLYNK_WM
if (Blynk_WF.getBlynkBLEToken() == NO_CONFIG)
{
Expand Down Expand Up @@ -219,35 +270,25 @@ void setup()
}
}

Serial.println(F("Scanning..."));

BLEDevice::init("");
//create new scan
pBLEScan = BLEDevice::getScan();
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());

//active scan uses more power, but get results faster
pBLEScan->setActiveScan(true);

pBLEScan->setInterval(100);
// less or equal setInterval value
pBLEScan->setWindow(99);

init_BLE();

// Important, need to keep constant communication to Blynk Server at least once per ~25s
// Or Blynk will lost and have to (auto)reconnect
timer.setInterval(10000L, noticeAlive);

// Scan for Pet every 5.1s
timer.setInterval(5100L, checkPet);
// Scan for Pet every 60s (5.1s)
timer.setInterval(60000L, checkPet);
}

void loop()
{
init_BLE();

if (USE_BLE)
Blynk_BLE.run();
else
Blynk_WF.run();

timer.run();
checkStatus();
}
10 changes: 7 additions & 3 deletions examples/Async_PET_Check/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
// Those above #define's must be placed before #include <BlynkSimpleEsp32_Async_WFM.h>

#include <BlynkSimpleEsp32_Async_BLE_WF.h>
#include <BLEDevice.h>
#include <BLEServer.h>
#include "BLEScan.h"
//#include <BLEDevice.h>
//#include <BLEServer.h>
//#include "BLEScan.h"

#define USE_BLYNK_WM true
//#define USE_BLYNK_WM false
Expand All @@ -77,6 +77,10 @@

#endif

#include <BLEDevice.h>
#include <BLEServer.h>
#include "BLEScan.h"

#ifndef LED_BUILTIN
#define LED_BUILTIN 2 // Pin D2 mapped to pin GPIO2/ADC12 of ESP32, control on-board LED
#endif
Expand Down

0 comments on commit 819462c

Please sign in to comment.