Page 1 of 1

scanned BLEAdvertisedDevice to BLEBeacon

Posted: Mon Mar 12, 2018 5:22 pm
by GKroon
Hi, Last week I drowned my rpi-zero in a terrible yeast overflow (Brewing beer) and now I try to replace it with a smaller ESP32.

In my fermenter I've got a tilt hydrometer floating around which is an iBeacon broadcasting the gravity and temperature reading in the major and minor.
When I use the BLE_Scan sample I do indeed see the message of this sensor among the other BLE readings.
Now my question is: How do I convert the BLEAdvertisedDevice from the scan result into the BLEBeacon so that I can send the sensor readings to the web.

Re: scanned BLEAdvertisedDevice to BLEBeacon

Posted: Tue Mar 13, 2018 3:05 am
by kolban
It looks like the BLEBeacon class has a method called setData() which can be passed a representation of a Beacon record. Once that data is ensconced in a BLEBeacon object, you can use the getters of BLEBeacon to retrieve the relevant properties.

Re: scanned BLEAdvertisedDevice to BLEBeacon

Posted: Wed Mar 14, 2018 10:51 am
by GKroon
I did indeed find the SetData() method and it is indeed working.
also found out that I have to use __builtin_bswap16 to get the correct values from the major and minor.

Next step is to push the data to influxdb :)

Re: scanned BLEAdvertisedDevice to BLEBeacon

Posted: Sun Apr 15, 2018 5:12 pm
by BrunDog
Hi @kolban,

I am trying to do something similar... Using ESP32 for Arduino, I have followed your excellent book and examples, but getting stuck...

Is it possible to have a non-blocking call for iBeacon scanning? In my application, I need the code to continue execution and the callback called when a new result is issued. Thanks in advance!

Re: scanned BLEAdvertisedDevice to BLEBeacon

Posted: Mon Apr 16, 2018 4:15 am
by kolban
Currently, the design of the BLEScan::start() function is blocking until the scan has completed. We could re-design the solution so that BLEScan::start() can optionally return immediately. At that point you would have had to have registered callback functions to be able to be informed when a scan response is available. I'm also imagining you will want to know when the scan duration has completed.

We might want to change the implementation signature from the current:

BLEScan::start(duration)

to

BLEScan::start(duration, completionCallback)

The completionCallback would be optional and, if omitted, the semantics would be as they are today. However, if the completionCallback were supplied, that would indicate that you want BLEScan::start() to return immediately and invoke completionCallback when the scan has completed.

Re: scanned BLEAdvertisedDevice to BLEBeacon

Posted: Mon Apr 16, 2018 4:54 am
by chegewara
Maybe i dont understand something but:
- you can scan continually with BLEScan::Start(0),
- you can have callback for Scan::onResult which is called every time when new scan is performed and found any device
https://github.com/nkolban/esp32-snippe ... n.cpp#L116,
also you may want to scan all devices even device has been seen previously.

Re: scanned BLEAdvertisedDevice to BLEBeacon

Posted: Mon Apr 16, 2018 1:56 pm
by kolban
@chegewara

I think what the original poster wants is to make a call to BLEScan::start(0) and have that call return immediately while continuing to scan in the background. My understanding is that if we call BLEScan::start() today, it will block until the scan interval expires or otherwise the scanning is explicitly terminated.

Re: scanned BLEAdvertisedDevice to BLEBeacon

Posted: Mon Apr 16, 2018 5:37 pm
by chegewara
I am using BLEScan::start(0) and i am running BLEServer at the same time. Again, i may not understand the nature of this problem, but if BLEScan::start(0) really is blocking then to achieve this (
to make a call to BLEScan::start(0) and have that call return immediately while continuing to scan in the background
) there is very simple solution:

Code: Select all

BLEScan *pScan;

void scanTask(void*){
pScan->start(0);
}

xCreateTask(&scanTask, "task", ....);
//more user code
We have scan performed in background in another task, and we can continue executing code.

Re: scanned BLEAdvertisedDevice to BLEBeacon

Posted: Mon Apr 16, 2018 10:21 pm
by kolban
Apparently the user is working in Arduino land and has explicitly chosen not to use threading/tasks. However, your thinking appears solid to my eyes.