Code only runs once
Based on the tutorials I cobbled together my first 'own' Python script such as this:
from mbientlab.metawear import MetaWear, libmetawear from mbientlab.metawear.cbindings import * import sys address = "c1:df:15:9e:4d:7b" device = MetaWear(address) device.connect() pattern= LedPattern(repeat_count= 10) libmetawear.mbl_mw_led_load_preset_pattern(byref(pattern), LedPreset.BLINK) libmetawear.mbl_mw_led_write_pattern(device.board, byref(pattern), LedColor.GREEN) libmetawear.mbl_mw_led_play(device.board) device.disconnect()
This runs and flashes the LED 10 times on the MMR as desired, but when I run the code again there is an unintelligible error that feels like it is trying to communicate that it cannot connect:
(I already know to ignore the blestatemachine.cc error. Who is responsible for fixing that?)
>>> %Run test.py error 1598280591.852555: Error on line: 296 (src/blestatemachine.cc): Operation now in progress Connected Services disconvered Characteristics discovered Descriptors found >>> %Run test.py error 1598280604.313508: Error on line: 296 (src/blestatemachine.cc): Operation now in progress Traceback (most recent call last): File "/home/pi/Python/test.py", line 7, in <module> device.connect() File "/usr/local/lib/python3.5/dist-packages/mbientlab/metawear/metawear.py", line 195, in connect raise result mbientlab.warble.WarbleException: (status = 2)
Funny enough when I push the button after the first run then the code runs again ok, or after waiting several minutes.
1) Is device.disconnect() not enough to cleanly reset it to a stage where it can accept a new connection request?
2) What exactly does the button do? So far I thought it is only needed to wake the sensor up from sleep. https://mbientlab.com/tutorials/CppDevelopment.html#disconnect does not mention it puts the sensor to sleep.
Thanks for any insights that help me better understand the interaction with the sensor.