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.
To repeatedly call a function while the device is connected,
obniz.onloop is useful.
A function set here will be called repeatedly as long as the device is online.
This function calls pingWait() internally every time to check for communication and to ensure that the communication channel does not accumulate a large number of buffers. Therefore, if you want to iterate faster, you can do so by looping or iterating in your program instead of using onloop, but there are some caveats
- 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.