# Using bluetooth to collect data to app

**URL:** <https://community.appfarm.io/t/using-bluetooth-to-collect-data-to-app/551>\
**Category:** Ask the community\
**Tags:** app-data, web-request\
**Created:** [June 28, 2023, 5:35am UTC](https://community.appfarm.io/t/using-bluetooth-to-collect-data-to-app/551 "2023-06-28T05:35:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Preben](https://dub1.discourse-cdn.com/flex013/user_avatar/community.appfarm.io/preben/32/545_2.png) [@Preben](https://community.appfarm.io/u/Preben)\
**Post date:** [June 28, 2023, 5:35am UTC](https://community.appfarm.io/t/using-bluetooth-to-collect-data-to-app/551/1 "2023-06-28T05:35:40Z")

</div>

Hi,

Is there any way to use a device’s Bluetooth connection to fetch data in Appfarm?

Thanks  
Preben

---

<div class="post-metadata">

**Author:** ![Joanna](https://dub1.discourse-cdn.com/flex013/user_avatar/community.appfarm.io/joanna/32/122_2.png) [@Joanna](https://community.appfarm.io/u/Joanna)\
**Post date:** [June 28, 2023, 6:49am UTC](https://community.appfarm.io/t/using-bluetooth-to-collect-data-to-app/551/2 "2023-06-28T06:49:03Z")

</div>

Hi Preben,

Could you share a bit more details on what kind of data and how you’re planning to collect it? Are you thinking of an IoT device?

Best,  
Joanna

---

<div class="post-metadata">

**Author:** ![Preben](https://dub1.discourse-cdn.com/flex013/user_avatar/community.appfarm.io/preben/32/545_2.png) [@Preben](https://community.appfarm.io/u/Preben)\
**Post date:** [June 28, 2023, 6:51am UTC](https://community.appfarm.io/t/using-bluetooth-to-collect-data-to-app/551/3 "2023-06-28T06:51:16Z")

</div>

In this it is a weight that has the possibility to send weight data to a device through Bluetooth.

---

<div class="post-metadata">

**Author:** ![Joanna](https://dub1.discourse-cdn.com/flex013/user_avatar/community.appfarm.io/joanna/32/122_2.png) [@Joanna](https://community.appfarm.io/u/Joanna)\
**Post date:** [June 28, 2023, 7:00am UTC](https://community.appfarm.io/t/using-bluetooth-to-collect-data-to-app/551/4 "2023-06-28T07:00:03Z")

</div>

There’s no built-in functionality to handle Bluetooth data in Create, but it should be possible to achieve using a Coded Component or `Run Code` triggered by an operation in your app, where you’d use JavaScript to request data and process it.

Perhaps this is helpful: [Communicating with Bluetooth devices over JavaScript - Chrome Developers](https://developer.chrome.com/articles/bluetooth/)

---

<div class="post-metadata">

**Author:** ![Thomas](https://dub1.discourse-cdn.com/flex013/user_avatar/community.appfarm.io/thomas/32/9_2.png) [@Thomas](https://community.appfarm.io/u/Thomas)\
**Post date:** [June 28, 2023, 7:41am UTC](https://community.appfarm.io/t/using-bluetooth-to-collect-data-to-app/551/5 "2023-06-28T07:41:06Z")

</div>

Unfortunately, Web Bluetooth is not fully supported on all devices yet, including iOS:

> **[Web Bluetooth | Can I use... Support tables for HTML5, CSS3, etc](https://caniuse.com/web-bluetooth)**
>
> "Can I use" provides up-to-date browser support tables for support of front-end web technologies on desktop and mobile web browsers.

---

<div class="post-metadata">

**Author:** ![Preben](https://dub1.discourse-cdn.com/flex013/user_avatar/community.appfarm.io/preben/32/545_2.png) [@Preben](https://community.appfarm.io/u/Preben)\
**Post date:** [June 28, 2023, 8:02am UTC](https://community.appfarm.io/t/using-bluetooth-to-collect-data-to-app/551/6 "2023-06-28T08:02:04Z")

</div>

Thanks for the quick replies 👍

---

<div class="post-metadata">

**Author:** ![Preben](https://dub1.discourse-cdn.com/flex013/user_avatar/community.appfarm.io/preben/32/545_2.png) [@Preben](https://community.appfarm.io/u/Preben)\
**Post date:** [October 13, 2023, 7:25pm UTC](https://community.appfarm.io/t/using-bluetooth-to-collect-data-to-app/551/7 "2023-10-13T19:25:55Z")

</div>

Hi again,

I have started to look into this a bit more, and my javascript skills are not very good. But I have been able to log a value in the console, but what is the best way to get it to a datasource or app variable in appfarm?

Thanks

code example:

```auto
navigator.bluetooth.requestDevice({
  filters: [{ services: ['battery_service'] }]
})
.then(device => device.gatt.connect())
.then(server => server.getPrimaryService('battery_service'))
.then(service => service.getCharacteristic('battery_level'))
.then(characteristic => characteristic.readValue())
.then(value => {
  console.log('Battery percentage:', value.getUint8(0));
});

```
