0

I'm writing an app with flutter to communicate with a weather station. The smartphone/tablet have to send via usb a command every one minute, recieve data from the station, and then send this data in a Firebase database.

I know that a smartphone is not the best device for do this, but I'm using an old device and I don't care about battery health (maybe a raspberry could be a better solution).

I'm using usb_serial package to communicate via usb and cron package for timing the events. And all works fine.

The problem is that the app have always to run in foreground. The first solution that i tried is using two apps: (1) one that keeps the screen on (2) and another that makes the screen black to reduce the energy consumpion. This is not the best solution.

I think that a better way is to use a background execution. I made some attempts with workmanager package but the minimum frequency is 15 min, with android alarm manager package but I'm not sure that wakes up also the network connection.

Anybody can suggest me witch is the best way to achieve my goal?

Thanks.

Abi86
  • 1
  • 1

1 Answers1

1

Refer this answer https://stackoverflow.com/a/14946013/13892187

In Dart for setting a recurring function we use the Timer class

Abdul Malik
  • 1,158
  • 6
  • 15
  • Thanks for answer. I don't have a timing problem, I use Cron package that works fine. My problem is doing this as background operation. – Abi86 Jul 09 '20 at 08:38
  • 1
    I don't have experience with this, but i will redirect you to something known as "isolates" in the Dart language which run in the background. I suggest you to check them once. – Abdul Malik Jul 09 '20 at 08:44