Giter VIP home page Giter VIP logo

mybluetoothconnectedapp's Introduction

#MyBluetoothConnectedApp

Goal

I created this very small app so I can start experimenting with bluetooth connectivity using react-native. I wanted to see what kind of information I could retrieve from devices connected to the phone.

  • My aspirational goal was to be able to connect and control a mini printer via this app, which I knew there was a big risk it wouldn't be possible at all.

Run the app

npm run android, npm start You need to accept permissionso popups. After that you can click scan for devices and you'll get a list of all the available BLE device names you can potentially connect to.

  • This app has only been tested with an android physical device.

Bluetooth library

There are two main libraries that handle bluetooth connectivity. On this app I have used react-native-ble-plx, but depending on the use case it might be best to use react-native-ble-manager instead as it does have a few extra features for Android, like bonding peripherals.

Bluetooth limitations

Where do I start...

Bluetooth versions

There are different bluetooth versions used by different devices and depending on the manufacturer and capabilities of each device, retrieved information can vary greatly. A big difference you might encounter between devices is whether they use Bluetooth Classic or Bluetooth Low Energy (often referred to as BLE). As it's probably obvious by their names and quite clearly documented, the libraries I'm citing above can only handle BLE. Luckily I had two devices on BLE so I was able to continue experimenting.

IOS / Android

As each operating system has their own way of interpreting/handling/connecting to bluetooth it's probably best (and advised by the library docs) to use the ios/android subfolders for most of the bluetooth specific development. As I didn't have time and resources to look into ios I kept everything in the main App.js with the knowledge that the app will probably crash on an ios device.

Permissions

This is probably less specific to bluetooth and more related to general phone permissions. I had trouble figuring out the correct bluetooth permissions in order for my app to start working at all the As is stated on the android docs, the set of permissions that you declare in your app depends on your app's target SDK version. The operating system on the device I'm using to test my app is Android 13, so I had to setup the correct permissions in my AndroidManifest.xml but also very importantly ask for specific user permissions after the app starts, following the camera permissions example in the react-native docs - permissionsandroid. I'm new to this so there might be a more efficient way to handle permissions, or I may have possibly not needed all the permissions I set, but this was what worked for me after quite a bit of fiddling with different options.

Result

The only useful(?) information I managed to retrieve at this point was the name of the device.

Other Notes

There is a warning about the calling of new NativeEventEmitter(), which is probably due to the way I'm initiating new BleManager();. I looked at doing it from within the App component but it didn't really make a difference to this warning so I kept it simple.

mybluetoothconnectedapp's People

Contributors

estherixz avatar

Stargazers

Roman avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.