Browse Source

Parametrizado el tiempo de escucha y simplificado codigo

master
Jorge Lopez 8 months ago
parent
commit
d6c8b0a252
4 changed files with 26 additions and 46 deletions
  1. +22
    -42
      Equip.ino
  2. +1
    -1
      IBeaconProvider.h
  3. +2
    -2
      IBeaconProvider_ESP32.cpp
  4. +1
    -1
      IBeaconProvider_ESP32.h

+ 22
- 42
Equip.ino View File

@@ -12,10 +12,7 @@ uint8_t episNeeded = 3;
IBeaconTransmitter* iBeaconTransmitter;
IBeaconProvider *iBeaconProvider;
struct timeval now;
unsigned long lastTime;
unsigned long lastTimeActivate;
bool iBeaconMode = false;
void setup() {
Serial.begin(115200);
@@ -28,7 +25,10 @@ void setup() {
//Obtiene los iBeacons del entorno
iBeaconProvider = new IBeaconProvider_ESP32();
lastTime = 0;
//Se inicia el envio del beacon del area
iBeaconTransmitter->start();
lastTimeActivate = 0;
pinMode(2,OUTPUT);
}
@@ -40,49 +40,30 @@ void loop() {
void manageBluetooth() {
gettimeofday(&now, NULL);
//Se inicia un escaneo con la duracion del mismo
iBeaconProvider->start(1);
if(now.tv_sec - lastTime <= 2){
return;
}
//Se recogen los resultados
IBeaconList *iBeacons = iBeaconProvider->getResults();
if(lastTime > 0){
iBeaconMode = !iBeaconMode;
}
struct timeval now;
gettimeofday(&now, NULL);
if(iBeaconMode){
if(lastTime > 0)
iBeaconProvider->stop();
iBeaconTransmitter->start();
if(lastTime > 0){
IBeaconList *iBeacons = iBeaconProvider->getResults();
struct timeval now2;
gettimeofday(&now2, NULL);
printf("--------------------------------------------------------------------------------\n");
for(int i = 0; i < iBeacons->size; i++){
IBeacon *iBeacon = iBeacons->list[i];
printf("UUID: %s\tMAJOR: %d\tMINOR: %d\tTX_POWER: %d\tRSSI: %d\tDISTANCE: %lf\n", iBeacon->uuid.c_str(), iBeacon->major, iBeacon->minor, iBeacon->txPower, iBeacon->rssi, iBeacon->getDistance());
if(checkIBeacon(iBeacon)) {
lastTimeActivate = now2.tv_sec;
}
}
printf("--------------------------------------------------------------------------------\n\n");
if(now2.tv_sec - lastTimeActivate > 5){
digitalWrite(2, LOW);
}
//Se imprimen los resultados y se checkean para ver si hai un operario valido
printf("--------------------------------------------------------------------------------\n");
for(int i = 0; i < iBeacons->size; i++){
IBeacon *iBeacon = iBeacons->list[i];
printf("UUID: %s\tMAJOR: %d\tMINOR: %d\tTX_POWER: %d\tRSSI: %d\tDISTANCE: %lf\n", iBeacon->uuid.c_str(), iBeacon->major, iBeacon->minor, iBeacon->txPower, iBeacon->rssi, iBeacon->getDistance());
if(checkIBeacon(iBeacon)) {
lastTimeActivate = now.tv_sec;
}
}
else {
if(lastTime > 0)
iBeaconTransmitter->stop();
iBeaconProvider->start();
printf("--------------------------------------------------------------------------------\n\n");
//Si pasaron 5 segundos sin volverse a detectar un operario valido se desconecta el actuador
if(now.tv_sec - lastTimeActivate > 5){
digitalWrite(2, LOW);
}
lastTime = now.tv_sec;
}
bool checkIBeacon(IBeacon *iBeacon){
@@ -90,7 +71,6 @@ bool checkIBeacon(IBeacon *iBeacon){
return false;
}
digitalWrite(2, HIGH);
return true;

+ 1
- 1
IBeaconProvider.h View File

@@ -13,7 +13,7 @@ class IBeaconProvider {
protected:
IBeaconList *iBeacons;
public:
virtual void start() {};
virtual void start(uint32_t time_s) {};
virtual IBeaconList* getResults() {};
virtual void stop() {}
};

+ 2
- 2
IBeaconProvider_ESP32.cpp View File

@@ -61,12 +61,12 @@ IBeacon* IBeaconProvider_ESP32::parseBeacon(uint8_t *data, uint8_t length){
return iBeacon;
}

void IBeaconProvider_ESP32::start() {
void IBeaconProvider_ESP32::start(uint32_t time_s) {
for(uint8_t i = 0; i < this->iBeacons->size; i++){
delete this->iBeacons->list[i];
}

BLEScanResults foundDevices = pBLEScan->start(2, true);
BLEScanResults foundDevices = pBLEScan->start(time_s, true);
this->iBeacons->size = 0;

for(uint16_t i = 0; i < foundDevices.getCount(); i++){

+ 1
- 1
IBeaconProvider_ESP32.h View File

@@ -14,7 +14,7 @@ class IBeaconProvider_ESP32: public IBeaconProvider {
IBeacon* parseBeacon(uint8_t* data, uint8_t length);
public:
IBeaconProvider_ESP32();
void start();
void start(uint32_t time_s);
IBeaconList* getResults();
void stop();
};

Loading…
Cancel
Save