Using bluetooth to collect data to app

Hi,

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

Thanks
Preben

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

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

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

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

1 Like

Thanks for the quick replies :+1:

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:

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));
});