B4R Question [Solved] Unable to Get RSSI value at B4R from Inline C

AndroidMadhu

Active Member
Licensed User
I am using the below thread for getting the RSSI ID from Beacons scanning by ESP32.

https://www.b4x.com/android/forum/threads/esp32-ble-scanning-inline-c.111675/#content

But I am not able to get the value of RSSI ID at B4R logs from Inline C...


B4X:
#if C

/*
  https://github.com/espressif/arduino-esp32/blob/master/libraries/BLE/examples/BLE_scan/BLE_scan.ino
*/

#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEScan.h>
#include <BLEAdvertisedDevice.h>

int scanTime = 10; //In seconds
BLEScan* pBLEScan;

class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
    void onResult(BLEAdvertisedDevice advertisedDevice) {
      Serial.printf("Advertised Device: %s \n", advertisedDevice.toString().c_str());
      Serial.print(" RSSI: ");Serial.println(advertisedDevice.getRSSI()); =====>>> This Line I am getting stuck
    }
};

Please advice how to get the RSSI value from Inline C at B4R.

Thanks
 

AndroidMadhu

Active Member
Licensed User
What do you see in the logs?
Sorry for late reply.... I found the below values at my Logs...

B4X:
Scan done!
Devices found: 0
Scan done!
Devices found: 0
Scan done!
Devices found: 0
Scan done!
Devices found: 0
Scan done!
Devices found: 0
Scan done!
Devices found: 0
Scan done!
Advertised Device: Name: , Address: 0a:c1:ca:0c:f6:23, manufacturer data: 060001092002d3daf1835c138b789c0a08a219232443bfda1cd6094c94
 RSSI: -69
Devices found: 1
Scan done!
Advertised Device: Name: , Address: 0a:c1:ca:0c:f6:23, manufacturer data: 060001092002d3daf1835c138b789c0a08a219232443bfda1cd6094c94
 RSSI: -49
Devices found: 1
Scan done!
Advertised Device: Name: , Address: 0a:c1:ca:0c:f6:23, manufacturer data: 060001092002d3daf1835c138b789c0a08a219232443bfda1cd6094c94
 RSSI: -49
Devices found: 1
Scan done!
Advertised Device: Name: , Address: 0a:c1:ca:0c:f6:23, manufacturer data: 060001092002d3daf1835c138b789c0a08a219232443bfda1cd6094c94
 RSSI: -49

Below is my Sketch..... I am able to get the RSSI value at B4R Variables...

B4X:
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 300
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public Serial1 As Serial
    Public GetRSSI As Int
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    RunNative("setup", Null)
    AddLooper("Looper1")
End Sub

Private Sub Looper1
    RunNative("loop", Null)
    Log("B4R RSSI Value is :" ,GetRSSI)
End Sub

#if C

/*
  https://github.com/espressif/arduino-esp32/blob/master/libraries/BLE/examples/BLE_scan/BLE_scan.ino
*/

#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEScan.h>
#include <BLEAdvertisedDevice.h>

int scanTime = 10; //In seconds
BLEScan* pBLEScan;

class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
    void onResult(BLEAdvertisedDevice advertisedDevice) {
      Serial.printf("Advertised Device: %s \n", advertisedDevice.toString().c_str());
      // Serial.print(" RSSI: ");
      // Serial.println(advertisedDevice.getRSSI());
      b4r_main::_getrssi=advertisedDevice.getRSSI();
    }
};

void setup(B4R::Object* o) {
  Serial.begin(115200);
  Serial.println("Scanning...");
  BLEDevice::init("");
  pBLEScan = BLEDevice::getScan(); //create new scan
  pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
  pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster
  pBLEScan->setInterval(100);
  pBLEScan->setWindow(99);  // less or equal setInterval value
 
}

void loop(B4R::Object* o) {
  // put your main code here, to run repeatedly:
  BLEScanResults foundDevices = pBLEScan->start(scanTime, true);
  Serial.print("Devices found: ");
  Serial.println(foundDevices.getCount());
 
  // you can access first device with foundDevices.getDevice(0).getAddress()
 
  Serial.println("Scan done!");
  pBLEScan->clearResults();   // delete results fromBLEScan buffer to release memory
  delay(2000);
}

#End if

I am now start integrating MQTT at ESP32....


Thanks
 
Upvote 0
Top