Mobile application built on Ionic 2 featuring Bluetooth Low Energy (BLE) capabilities

I am in the process of developing an Ionic 2 application that displays a list of all accessible Bluetooth devices and establishes connections with them effortlessly. I began by setting up a new Ionic v2 project and adding the BLE plugin to it.

Your help would be greatly appreciated, thank you!

Answer №1

If you are looking to discover and connect with available Bluetooth devices, there are a few steps you can take.

One approach is to utilize the Bluetooth API as demonstrated in the code snippet above. Alternatively, you can refer to examples provided by the API's author for further guidance.

var deviceToConnect = "12:34:56:78";
ble.scan([], 10, onSuccess, onFailure);

function onSuccess(device){
  console.log(device);
  if (device.id == deviceToConnect){
    ble.connect(device.id, connectSuccess, connectFailure);
  }
}

function onFailure(error){
  console.log(error);
}

function connectSuccess(){...}
function connectFailure(){...}

If you're still uncertain, consider trying a simpler API call like ble.isEnabled(), which will deliver a success or failure callback response.

Answer №2

I'm in the same boat, but it seems like you might not be too familiar with this programming language.

To start off, you need to bring the Plugin into your page (such as home.ts or any other relevant page) by entering the following code:

import { BLE } from '@ionic-native/ble';

According to the documentation, there are multiple functions available for use with this plugin, such as BLE.isEnabled() which provides a promise that is resolved if Bluetooth is enabled on the device.

The documentation is quite easy to understand, but if you need more examples, feel free to visit the GitHub repository.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Concerns with uploading images in Angular 2:

Having Trouble with Image Upload in Angular 2: We are facing difficulties uploading images into MySQL as 'blob data' using Angular 2. We are unsure of how to convert the image into blob data. image.html: <input type="file" class="fileinput ...

Elevate your Material UI Avatar with an added level of

Attempting to give a MUI Avatar component some elevation or shadow according to the documentation provided here. <Avatar alt="Cindy Baker" src="/static/images/avatar/3.jpg" /> Enclosing the Avatar within a paper or Card element increases the size o ...

Using TypeScript to Initialize Arrays with Objects

Why is it that in TypeScript 1.8, the following code blocks with initializers are considered legal syntax: class A { public textField: string; } var instanceOfClass = new A { textField = "HELLO WORLD" }; var arrayCollection = new A[] { new A ...

Sending template reference from one Angular component to another

I have a main grid component that includes smaller grid-item components. The majority of these grid items navigate to a specific route when clicked. However, there is one particular item that should open a modal window instead of navigating. Is there a wa ...

Closing ngx-bootstrap modal from nested component

I am facing a situation where I need to close the Bs-modal popup after saving data to the database. The saving process is done in the child component, so I passed the Bs-modal to the child component using ()Input. However, I am encountering an issue where ...

Remove all keys of type BaseType from objects that are children of BaseType

There are two types: BaseType and BabyType. export type BaseType = { id: string } export type BabyType = BaseType & { name: string }; In a generic layer where <T extends BaseType> is used, the item being dealt with is actually a 'B ...

Modifying data within nested objects using Typescript

Imagine having an object like this: { b954WYBCC4YbsMM36trawb00xZ32: { activity1: "pending", activity2: "pending" }, ​ pby0CAqQ1hTlagIqBTQf6l2Ti9L2: { activity1: "pending", activity2: "pending" } } with the in ...

Unable to associate with 'ngIF' as it is not recognized as a valid property of 'ion-item'

I am facing a challenge in implementing *ngIF within the code of my Ionic4 project. I have come across some solutions, but none seem to be compatible with ionic 4 and angular 7. I attempted to import the imports: [CommonModule] part, but unfortunately, it ...

Alert in Typescript: "Consider using an interface instead of a type literal"

When linting my code, a TS warning is triggered regarding the definition of InternalStateType [line 8] export type InternalStateType = { [key: string]: any, appName: string, darkMode: boolean, de ...

Enhancing SQLite syntax in Ionic 2: A fresh approach!

Having trouble with updating my SQLite table using this script, I've edited the query but it still doesn't work. try{ this.sqlite.create({ name: 'data.db', location: 'default' }) .then((db: SQLiteObject) => ...

"Exploring the world of subscribing in Angular's reactive

I'm struggling with Angular's reactive form valueChanges event. I want to react to user inputs in order to prevent or correct them, but every approach I've tried so far has resulted in a Maximum call stack size exceeded error when subscribin ...

Personalize your Stackblitz Angular project template

Currently, I am in the process of forking and customizing the Stackblitz Angular CLI project template which can be found at github.com/stackblitz/angular-cli-template. The main goal here is to adjust the TypeScript configuration by changing the target fro ...

Guide on making multiple setupIndication calls using RxAndroidBle

After calling rxBleConnection.setupIndication(UUID), I need to retrieve the value. I have multiple UUIDs for different characteristics and I want to synchronize them using RxJava similar to how we use Single.Zip or Observable.zip. For instance, with RxAnd ...

All-encompassing NextJS App router with a focus on Internationalization

I am currently working with a folder structure that includes an optional catch-all feature. The issue I am facing is that the page does not change when the URL is altered to include ""/"" or ""/about-us"". It consistently remains on the ...

Display a button in ngx-datatable on mouse hover in Angular 9

My goal is to display a link on mouseover of the corresponding cell in ngx-datatable. However, the link appears on all rows within that column instead. Below is the code I am currently using: <ngx-datatable class="material ml-0 mr-0" [r ...

The Radio Button's value appears in a distinct way on Ionic Angular

I am currently working with the Ionic framework and I am trying to display data values on radio buttons. However, I am facing difficulties in retrieving the correct value and setting it appropriately. index.html <td> <label>{{learn ...

The error message states that the argument type '(src: Observable<any>) => Observable<any>' cannot be assigned to a parameter of type 'OperatorFunction<Object, any>'

Encountering a typescript error when trying to start the app. Not sure where I'm going wrong. It seems like it could be an issue with the rxjs version, but struggling to find the right solution. Seeing incompatible types on my system and not getting r ...

The action dispatched by "AuthEffects.register$" is not valid and will have no effect

After implementing a new effect for the register action, I encountered the following error message: Effect "AuthEffects.register$" dispatched an invalid action Below is the code for my effect: @Effect() register$ = this.actions$.pipe( ofType<Regis ...

Angular is facing an issue with Canvas DataGrid because it cannot locate the /dist/types.d.ts file

I've been encountering an error while trying to implement canvas-datagrid in my angular project. I've attempted various solutions like deleting node_modules and package.lock.json, but the issue persists. node_modules/canvas-datagrid/dist/types.d. ...

Having trouble displaying child nodes in MatTreeView with Angular 14?

In an Angular project, I am attempting to display a private group's data from GitLab (utilizing a public one for testing purposes). To achieve this, I have implemented the NestedTreeView component. While the parent nodes are displaying correctly, I am ...