Page 1 of 1

Working With Wifi and BLE (Problem)

Posted: Mon Aug 10, 2020 4:33 am
by sammaeliv

Code: Select all

#include <BLEAdvertisedDevice.h>
#include <BLEDevice.h>
#include <BLEScan.h>
#include <WiFi.h>
#include <FirebaseESP32.h>

#define WIFI_SSID "SSID"
#define WIFI_PASSWORD "PASS"
#define FIREBASE_HOST "URL"
#define FIREBASE_AUTH "SECTREC"

FirebaseData firebaseData;
FirebaseJson json;

void setup() {
  BLEDevice::init("LOWE_P2");
  Serial.begin(115200);
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(300);
  }
  Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
  Firebase.reconnectWiFi(true);
  Firebase.setReadTimeout(firebaseData, 1000 * 60);
  Firebase.setwriteSizeLimit(firebaseData, "tiny");
}

void loop() {
  BLEScan *scan = BLEDevice::getScan();
  scan->setActiveScan(true);
  BLEScanResults results = scan->start(1);
  for (int i = 0; i < results.getCount(); i++) {
    BLEAdvertisedDevice device = results.getDevice(i);
    String dispositivo = results.getDevice(i).getName().c_str();
    int distancia = device.getRSSI();
    if(dispositivo.equals("LOWE_P1")){
      Serial.println("Dispositivo: "+dispositivo+", Distancia: "+distancia);
      if(distancia > -60){
        Serial.println("Registrando interacción ...");
        json.clear().add("Persona" , "LOWE_P1").add("Fecha" , 'timestamp');
        Firebase.pushJSON(firebaseData, "/Interaciones", json);
        delay(1000);
      }
    }
  }
}
I got this code, part of the code works fine wifi + firebase it works, but as soon a mix it wifi seems to fails didnt sent anything ... , how can i scan ble and stop using to turn on wifi and send values ... i want to report ble around esp32 so i need to scan and report to firebase

Re: Working With Wifi and BLE (Problem)

Posted: Sat Aug 15, 2020 11:02 pm
by martinius96
You can NOT use WiFi and Bluetooth in same time.
You have only one 2,4 GHz antenna onboard.
When you want to use WiFi, you need to stop Bluetooth and vice versa.

In your case, do it like: each XY milliseconds, disable bluetooth, start WiFi, send datas to Firebase, disable WiFi.
When program is not in that if statement that is running each XY milliseconds, run normally bluetooth with everything that you want.

Re: Working With Wifi and BLE (Problem)

Posted: Mon Aug 17, 2020 9:45 am
by dhiraj_gehlot
I had similar issue.
See if this helps you: https://www.esp32.com/viewtopic.php?f=19&t=16747

Re: Working With Wifi and BLE (Problem)

Posted: Thu Aug 20, 2020 8:26 am
by chegewara
martinius96 wrote: ↑
Sat Aug 15, 2020 11:02 pm
You can NOT use WiFi and Bluetooth in same time.
You have only one 2,4 GHz antenna onboard.
When you want to use WiFi, you need to stop Bluetooth and vice versa.
Then i am doing something wrong, because i have many apps with ble + wifi and i am not stopping wifi or ble.
This is old example and may not work properly right now:
https://github.com/nkolban/esp32-snippe ... thWiFi.cpp