Bluetooth LE from Cordova app to Linux device - linux

I need some guidance. In a nutshell, I need to be able to configure and control a device with the smart phone app over BLE.
For example, change IP address of my Raspberry Pi. To make that happen, I need 2 things.
Simple Android/iOS app that takes IP address parameters as an input, and then communicates over Bluetooth to the RPi. Note that the device needs to be discovered and connected from within the app (without going to "Settings" and pairing).
Build some server process on the Raspberry Pi that listens to USB Bluetooth dongle, receives the command with parameters and acts accordingly.
So I need help building the BLE portion of this project.
I have several years of smartphone app development experience, and 10+ years of Linux system programming. In other words, building a simple Cordova app, as well as Linux process that changes IP address is really not an issue.
However, I am totally new to Bluetooth. Can you point me to the right direction? I am sure this problem has already been solved few thousand times. Is there a tutorial? Or maybe a skeleton code I use as a starting point? Also, any recommendation for BLE USB dongle?
Thanks a lot!

I think it will be harder to find a better guide to implement low energy technology on the RaspberryPi than this one :
https://learn.adafruit.com/downloads/pdf/pibeacon-ibeacon-with-a-raspberry-pi.pdf
After this , you can download a random app on the Playstore/Appstore and check that your RaspberryPi is actually acting as a BLE device.
Finally you can start creating your own app using several available BLE plugins like :
https://github.com/randdusing/BluetoothLE
https://github.com/don/cordova-plugin-ble-central

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

Receiving data from a BLE device to a raspberry Pi3

I never used a raspberry pi before and I have a project part of which includes receiving data from a BLE blood pressure device over Bluetooth to a raspberry pi 3. I can pair the device to my raspberry but I have no idea what to do next. I need to be able to receive the measurements in my raspberry please help and thank you in advance.
PS: the device I'm trying to use is very similar to this one:
https://ibb.co/71365k5
Thanks for your answers, I have tried "Gatt" and "Gatttool" but the problem is after pairing the device is meant to send the measurement to its application on an android phone, without it I cannot read the blood measurement characteristic or it just does not exist.
Linux uses BlueZ as a default bluetooth stack. It exposes DBus APIs for implementing software using Bluetooth.
If you don't want to use this API directly, which can sometimes feel a bit low level you have many libraries that wrap it, such as https://github.com/getsenic/gatt-python that also comes with examples.
All other solutions requires replacing the Bluetooth stack on Linux and hence your other existing Bluetooth pairings to the system will stop working.

Reading Bluetooth data and command (Raspberry pi 3)

I am currently working on a project that make me control media center and a few domotic parts in my living room.
I have connected on my raspberry pi 3 a NAS, my Spotify account (with hifiberry, controls to close my amp, my PC and a few lights...
At first to control it all I programmed a web server that I can access on my phone. That made the job but it is not completely user friendly since I have to have my phone go to the interface and do whatever I have to... And I'm not a web designer 😁 it's far from perfect!
I've made some research and I have decided to build a bluetooth remote control (raspberry pi 3 do have Bluetooth low energy).
Since nothing exist as I want, it is going to be a custom one made with Arduino mini and hm10 module.
But I'm stuck on the raspberry part!
How can I read the Bluetooth data send by my remote and launch scripts according to the command sent?
Via a serial listener of some kind?
Yes, in fact, you should use a serial port to connect your pi with Bluetooth module.
You then use software input information for your purposes, but you must first implement the hardware and hardware interface first.
You can build application software with the Python programming language.

Simplest solution in arming/disarming your Raspberry Pi home alarm

I have built a home surveillance and alarm system with raspberry pi's.
What I need now is an easy and safe remote control to arm the system and disarm it.
The most workable solution is to have a wireless router in the middle.
Before stepping out in the door, take out my phone, connect to my home network and via a custom built web page arm my system. (Web page would run the arming scripts)
But for this I need to have a wireless router (currently I have a non wireless Ubiquiti Router Station Pro, no radio card on it) and need to enable wireless on my phone (it is not enable-d, battery reasons) before leave, connect and so on. It is not one click unfortunately...
Other solution is to have just a wireless dongle in the Raspberry PI and do an Ad Hoc WiFi connection with my phone. My phone is Sony Ericson Xperia. Over here my technical knowledge hits the limit. It is possible to broadcast an Ad Hoc network over Raspberry PI I do not know if I can reach it from my Sony Ericson Xperia phone.
Third option is Bluetooth. I know very little about Bluetooth. I do not know how safe it is, and how to program it, to have on and off switch on my phone. However this might be the most promising.
Fourth option is to use the Pi Face. Link one or two switches to some type of receiver device. Have a sender device on my key chain and control it from there.
However I do not know from where I can buy such a safe remote control and if it is compatible with Pi Face.
Fifth option. To get home alarm system components and link those with the Pi Face. But I do not know what component might fit.
The best user scenario is the following.
User takes out out a device (phone or remote control) and presses arm/disarm.
User has appropriate time (30 sec) to get out or shut down.
If the remote device had run out from battery still have something to shut it down.
So my question does any body knows a fast, easy, cheap solution how to do this?
Though Bluetooth's security is questionable, it seems like the best option for your goal. Next to an adhoc
Bluetooth is not complicated.
On your mobile phone, if you don't want to make your own app you can look for some sort of Bluetooth Terminal or Bluetooth Chat. On your raspberry pi you'll have to setup a bluetooth rfcomm server with bluez.
How to configure Linux to act as a Bluetooth RFCOMM SPP server?
RFCOMM without pairing using PyBluez on Debian?
Modify these servers which do nothing by default, to listen for commends "arm" and "disarm". Make sure the ID of the device is the ID of your phone.
Ad-Hoc is even less complicated (assuming you know how to make a webserver and are going to make it secure enough, and have a dongle which supports adhoc):
Here is a post about ad-hoc networking with a raspberry pi.
In terms of distance, you'll have to see the specifications on your dongle(s) but I would say they're relatively the same.. your bluetooth dongle will have a class see Bluetooth Basics: Range. This will require more research but if you have either one of the dongles I would use that method.
I hope this helps, good luck setting up your alarm.
In the mean time I realized that a fast arming could be done via the Pi Face and pressing a button.
Disarming could go by other ways.
However the fastest solution would be a fingerprint button linked safely to Pi Face.
Updates. Finally went with the Ad-Hoc method:
This is the tutorial for it:
http://elinux.org/RPI-Wireless-Hotspot

Remote device by smartphone android

I'm a newbie in this world.
I wanna build an application to remove some device.
Ex:
I wanna turn on or off lights and use my smartphone (Android) to do.
But, I don't know how to do? Can you show me all of steps?
Thank you so much!
Use a Raspberry Pi (runs linux).
You can have the RPi general purpose I/O lines to control, say, relays for lights etc. and then use the many Android apps to remotely control it.

Resources