Hi all, abit of a n00b here, in fact this is my first serious project. What I am making is a BLE proximity detector which will transmit an ASCII string via RS232 from a Firebeetle to a Mobotix IP Camera RS232 interface.
I have a firebeetle and I have connected Rx2 & Tx2 to a MAX232 chip with the output going to the Camera's rs232 module.
So far I have the unit working and triggering a relay, which is great except I want to make it more secure.
This is the code thus far. I have added some stuff which I thought would output to the RS232 but no joy. I would be ever grateful for any advice and or help
#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEScan.h>
#include <BLEAdvertisedDevice.h>
#define LED1 2
String knownBLEAddresses[] = {"00006666-0000-1000-8000-00805f9b34fb", "ff:ff:10:00:fd:8b", "ff:ff:10:06:91:0f"};
int RSSI_THRESHOLD = -60;
bool device_found = false;
bool poximity_confirmed = false;
bool inhibit = false;
int loopCount = 1;
int scanTime = 1; //In seconds
int num_knowndevice = 0;
int p_knowndevice = 0;
BLEScan* pBLEScan;
class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
void onResult(BLEAdvertisedDevice advertisedDevice) {
device_found = false;
int Current_rssi = -88;
for (int i = 0; i < (sizeof(knownBLEAddresses) / sizeof(knownBLEAddresses[0])); i++)
{
//if (strcmp(advertisedDevice.getAddress().toString().c_str(), knownBLEAddresses[i].c_str()) == 0)
if (strcmp(advertisedDevice.getServiceUUID().toString().c_str(), knownBLEAddresses[i].c_str()) == 0)
{
device_found = true;
Current_rssi = advertisedDevice.getRSSI();
if (Current_rssi > RSSI_THRESHOLD) {
num_knowndevice++;
//poximity_confirmed = true;
break;
}
}
}
if (device_found) {
Serial.print(advertisedDevice.getAddress().toString().c_str());
Serial.print("(");
Serial.print(Current_rssi);
Serial.print(")");
if (Current_rssi > RSSI_THRESHOLD)
Serial.println(" is confirmed.");
else
Serial.println(" is unconfirmed.");
}
}
};
void setup() {
Serial.begin(9600); //Enable UART on ESP32
pinMode(LED1, OUTPUT); //make BUILTIN_LED pin as output
Serial.println("BLE Scanning..."); // Print Scanning
BLEDevice::init("");
pBLEScan = BLEDevice::getScan(); //create new scan
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks()); //Init Callback Function
pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster
pBLEScan->setInterval(100); // set Scan interval
pBLEScan->setWindow(99); // less or equal setInterval value
}
void loop() {
delay(1100);
if (loopCount >= 1000) loopCount = 1; //Reset loopCount hourly
if (loopCount % 1 == 0) inhibit = false; //Debouncing Control
if (!inhibit and poximity_confirmed)
{
inhibit = true;
loopCount = 0; //Set loopCount to 0 to sync the debouncing clock
digitalWrite(LED1, HIGH);
Serial.println("On");
delay(2000);
Serial.println("Off");
digitalWrite(LED1, LOW);
poximity_confirmed = false;
}
num_knowndevice = 0;
BLEScanResults foundDevices = pBLEScan->start(scanTime, false);
pBLEScan->clearResults(); // delete results fromBLEScan buffer to release memory
device_found = false;
if (p_knowndevice < num_knowndevice) poximity_confirmed = true;
p_knowndevice = num_knowndevice;
loopCount++;
}