scanned BLEAdvertisedDevice to BLEBeacon

GKroon
Posts: 2
Joined: Mon Mar 12, 2018 3:31 pm

scanned BLEAdvertisedDevice to BLEBeacon

Postby GKroon » Mon Mar 12, 2018 5:22 pm

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.

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: scanned BLEAdvertisedDevice to BLEBeacon

Postby kolban » Tue Mar 13, 2018 3:05 am

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.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

GKroon
Posts: 2
Joined: Mon Mar 12, 2018 3:31 pm

Re: scanned BLEAdvertisedDevice to BLEBeacon

Postby GKroon » Wed Mar 14, 2018 10:51 am

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 :)

BrunDog
Posts: 1
Joined: Sun Apr 15, 2018 5:07 pm

Re: scanned BLEAdvertisedDevice to BLEBeacon

Postby BrunDog » Sun Apr 15, 2018 5:12 pm

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!

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: scanned BLEAdvertisedDevice to BLEBeacon

Postby kolban » Mon Apr 16, 2018 4:15 am

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.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

chegewara
Posts: 2207
Joined: Wed Jun 14, 2017 9:00 pm

Re: scanned BLEAdvertisedDevice to BLEBeacon

Postby chegewara » Mon Apr 16, 2018 4:54 am

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.

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: scanned BLEAdvertisedDevice to BLEBeacon

Postby kolban » Mon Apr 16, 2018 1:56 pm

@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.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

chegewara
Posts: 2207
Joined: Wed Jun 14, 2017 9:00 pm

Re: scanned BLEAdvertisedDevice to BLEBeacon

Postby chegewara » Mon Apr 16, 2018 5:37 pm

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.

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: scanned BLEAdvertisedDevice to BLEBeacon

Postby kolban » Mon Apr 16, 2018 10:21 pm

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.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

Who is online

Users browsing this forum: No registered users and 56 guests