When you want to pause a device like for waiting a response from a sensor use wait(). It pause both device and program.
Remove await to keep working program side.
You need to care when you do repeatable task.
- When disconnected from a device, break a loop.
- avoid freeze.
Most safety loop is below.
connectionState represents connection status for a device.
pingWait() send a data and wait for a response.
Above code will break a loop if offline and avoiding a freeze and also clean up communication line by using ping.
But pingWait() take a time because it wait until response received. If distance is too far like oversea, it take over 10 msec. For improving loop performance, instead of pingWait(), use setTimeout() or obniz.wait(). But It never mind data transfer, you need to care that when you need to send or receive mass data.