How to track mobile devices around beacon - bluetooth

I saw a video about a Pi 0 that has been coded to track the amount of people that are in a location at a certain time to report the data to an app that tell's people if the area is busy. This does not require for the tracked devices to be connected to a wifi.
How would one go by that? Are there specific node modules?
Thank you in advance

The RPi Zero is able to discovery nearby Bluetooth devices if those devices are advertising there presence.
The command line tool bluetoothctl allows you to scan for devices to test this.
To do this with code, BlueZ has a set of APIs which are documented at:
https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/adapter-api.txt
There is an example of how to discovery with the API using Python at:
https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/test/test-discovery
The BlueZ API uses D-Bus so can be used with any language that has D-Bus bindings.
https://www.freedesktop.org/wiki/Software/DBusBindings/

Related

What language/libraries best for BLE connectivity?

Operating system: MacOS
Just for some context on what I am trying to do, I have an Ikea standing desk which has bluetooth. I am able to control the desk with a built in app. I want to create a server running on a raspberry pi that connects to desk and controls it, I then want to create an Alexa skill which will control the desk by calling the server endpoints.
What's the best language/library you would suggest I use? Ideally something that would run on MacOS and Ubuntu.
I don't know anything about BLE yet which is why it is hard for me to find a good answer. If you have resources, books or tutorials that will help me get running with BLE please recommend them.
My use case:
Get desk to go up
Get desk to go down
Get current position of desk
If you want to write one app that works for both MacOS and Ubuntu then as ukBaz said, python and Bleak are your best options. If you want to use the native way of writing BLE apps for each OS, then you can use CoreBluetooth on MacOS and BlueZ on Ubuntu. The advantage of the former is that you can get an application up and running quickly, and the advantage of the latter is that you will find a lot more resources and advanced functionality.
Below are some resources that can help you in your development:-
Theoretical Bluetooth:
Bluetooth Low Energy: A Primer
Getting Started with Bluetooth Low Energy
Ellisys Bluetooth Series
CoreBluetooth
Getting Started with CoreBluetooth
Ultimate Guide to Apple's CoreBluetooth
iOS App Full Example
BlueZ
Configuring Bluetooth devices with bluetoothctl
Ubuntu: Accessing GATT services
Python
Ikea IDÅSEN desk API and CLI
Idasen controller example
Using Python for Bluetooth

How to interact with BLE devices through Linux using C programs?

I am fairly new to the BLE world. Assuming I have a BLE device Eg: A heart rate monitor, How do I interact with that BLE device using C code.
I am able to see the Heart rate data using the command line tool 'bluetoothctl'. If I want connect to the same device through C code and see the Notified data, how do I go about it?
Though some codes on the Internet and GitHub helped me to scan for the device, I do not have any idea on how to connect to the device, read the GATT characteristics of the BLE device. I'd even appreaciate it if anyone points me to the API documentations of BlueZ, I literally have no clue what the programs are all about. Any assistance would be of great help.
The preferred API for BlueZ uses the D-Bus bindings. The documentation for those APIs are at:
https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc
There are Python examples of how to use the D-Bus API at:
https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/test
bluetoothctl is written in C and the source is available at: https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/client

webUSB Relay Driver hardware

Over the last couple of years I have been looking for an easy way to control a few relays from Javascript. I want to build a web App to control starting sequence horns for sailing races.
I recently discovered webUSB and it seems like exactly what I need. A direct connection from JS in chrome to the USB world. Simple coding in a language I already use.
On the hardware side I am having trouble finding a product that is compatible. Googling USB Relay finds 100's of products that all seem to rely on some proprietary SW for the OS. I can find lots of educational demo's that turn an LED on and off.
Does anyone have any ideas where to find such a product?
While I'm sure you will be able to find USB relays that can be controlled via WebUSB, most USB relays will probably come with some kind of serial port driver, e.g. https://numato.com/product/1-channel-usb-powered-relay-module uses a CDC serial port driver. These can be controlled using Web Serial, available in Chrome 77 and later behind a feature flag. For a tutorial, see https://codelabs.developers.google.com/codelabs/web-serial/
Explainer: https://github.com/WICG/serial/blob/gh-pages/EXPLAINER.md
API docs: https://wicg.github.io/serial/
If you search for "5V USB Relay Programmable Computer Control For Smart Home" on eBay, you will also find low-cost relays that use HID instead. The advantage of these is that you don't need any serial port or USB drivers, as it will use the operating system's built-in HID drivers. For that you can use WebHID. For more info, see https://github.com/robatwilliams/awesome-webhid.

Bluetooth Connection and Fileshaing

Is it possible to track bluetooth connections that are connected to eachother? and if yes, is it possible to see that they're sharing files/sending data with bluetooth?
It is for a personal chat program, that me and my friends are working on in C#.
The Bluetooth devices and related status can be found using APIs of Windows.Devices.Enumeration namespace that are available for C#. They shall help in getting general information about devices connected to or discoverable by the system. It shall help in finding devices internally connected to the system, externally connected, or nearby over wireless or networking protocols and get information about them. The DeviceWatcher in turn shall help in finding and receiving updates for devices (like getting notifications when devices get added, connected, disconnected, change online status, or change other properties.)

Is there a way to connect to iBeacon while my Bluetooth device is invisible?

I'm researching iBeacons. Can I connect to iBeacons while my Bluetooth is invisible (to be protected from hacks)?
I don't have beacons to test myself and can't find any clear explanation online.
iBeacons connect to mobile phones using Bluetooth, so it is essential to have that turned on. You also need to have installed an app with iBeacon support in order to receive communication from them.
If you'd wish to use a solution that does not utilize Bluetooth, you could try out IndoorAtlas. It's an indoor navigation technology based on Earth's geomagnetic fields. It's also completely hardware-free solution, just requires you to collect fingerprints in the area you are going to use for your project.
Three points:
iBeacon technology does not rely on a bluetooth connection to your phone. Beacons are one way transmitters. They do not listen to or otherwise receive any info from your device. Beacon technology following this model is inherently privacy friendly.
Mobile devices cannot detect Bluetooth beacons with the Bluetooth radio turned off. Sorry, it is just not possible.
Properly built beacon apps will not expose your mobile device's Bluetooth info because they are receive only. Of course, other apps on your phone might use bluetooth for other purposes, so your best bet is to audit apps using bluetooth and remove any that are not doing what you want.
I just bought some beacons and tested that, The answer is YES. it is possible to read beacons mac addresses while using the phone's Bluetooth connection as invisible. Using this you will get access to your beacon in any open place without getting hacked through Bluetooth.
Thanks all for your answers.

Resources