Working With Wifi and BLE (Problem)

sammaeliv
Posts: 2
Joined: Mon Aug 10, 2020 4:26 am

Working With Wifi and BLE (Problem)

Postby sammaeliv » Mon Aug 10, 2020 4:33 am

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

martinius96
Posts: 33
Joined: Thu Dec 13, 2018 1:39 am

Re: Working With Wifi and BLE (Problem)

Postby martinius96 » 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.

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.

dhiraj_gehlot
Posts: 8
Joined: Thu Jul 30, 2020 11:23 am

Re: Working With Wifi and BLE (Problem)

Postby dhiraj_gehlot » Mon Aug 17, 2020 9:45 am

I had similar issue.
See if this helps you: https://www.esp32.com/viewtopic.php?f=19&t=16747

chegewara
Posts: 2364
Joined: Wed Jun 14, 2017 9:00 pm

Re: Working With Wifi and BLE (Problem)

Postby chegewara » Thu Aug 20, 2020 8:26 am

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

Who is online

Users browsing this forum: No registered users and 93 guests