Working With Wifi and BLE (Problem)
Posted: 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);
}
}
}
}