简体   繁体   English

在后台接收数据(flutter_reactive_ble)

[英]Receive data in background (flutter_reactive_ble)

I have an arduino nano 33 ble that sends data from sensors every second or so.我有一个 arduino nano 33 ble,大约每秒从传感器发送数据。 Right now I also have an app, written with Flutter and flutter_reactive_ble that receives the data.现在我还有一个应用程序,用 Flutter 和接收数据的 flutter_reactive_ble 编写。 The problem is that I need to continue receiving data in background, but I am too inexperienced with Dart/Flutter, so I have trouble to do it.问题是我需要在后台继续接收数据,但是我对Dart/Flutter的经验太少,所以很难做到。 For now I am using am implementation found on https://github.com/ubiqueIoT/flutter-reactive-ble-example I am using the subScribeToCharacteristic method.现在我正在使用在https://github.com/ubiqueIoT/flutter-reactive-ble-example上找到的实现我正在使用 subScribeToCharacteristic 方法。 My understanding is that it checks for new data only when there is something on the screen (using StreamBuilder<List>).我的理解是它仅在屏幕上有内容时才检查新数据(使用 StreamBuilder<List>)。 Is there a way to perform some basic math operations on the data in background and to dump it all to an array?有没有办法在后台对数据执行一些基本的数学运算并将其全部转储到数组中? I read about isolates and some other interesting techniques, but I was wondering whether there is a simpler solution, because those look a bit too difficult.我阅读了 isolates 和其他一些有趣的技术,但我想知道是否有更简单的解决方案,因为这些看起来有点太难了。 I saw that apparently if I don't close my app completely (iOS) there is a way for it to continue to receive data for some time like 15-30 minutes, which is enough for my purpose, but there was no code/examples/etc.我看到显然如果我不完全关闭我的应用程序(iOS),有一种方法可以让它继续接收数据一段时间,比如 15-30 分钟,这足以满足我的目的,但是没有代码/示例/ETC。

I tried to put Stream out of StreamBuilder and to receive data just in the main body of Widget build, but nothing worked, I stopped receiving any data.我试图将 Stream 从 StreamBuilder 中取出并仅在 Widget 构建的主体中接收数据,但没有任何效果,我停止接收任何数据。

Thanks in advance!提前致谢!

here is a good starting point for you just use this plugin这是一个很好的起点,你只需使用这个插件

import 'package:flutter_background_geolocation/flutter_background_geolocation.dart'
as bg;

 // Initialize the plugin.
bg.BackgroundGeolocation.ready(bg.Config(
 desiredAccuracy: bg.Config.DESIRED_ACCURACY_HIGH,
 distanceFilter: 10.0,
 stopOnTerminate: false,
 startOnBoot: true,
 ));

  // Start tracking location in the background.
  bg.BackgroundGeolocation.start();

  // Subscribe to the BLE device's characteristic to receive data.
  bg.BackgroundGeolocation.subscribeToCharacteristic(
  'DEVICE_ID',
  'CHARACTERISTIC_ID',
   (bg.CharacteristicEvent event) {
   // Do some basic math operations on the data.
    double data = event.value;
    double result = data * 2 + 3;

// Dump the data to an array.
List<double> dataArray = [result];

// Do something with the data (e.g., save it to a database, send it to a server, etc.).
    },
           );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM