crownstone / bluenet

Bluenet is the in-house firmware on Crownstone hardware. Functions: switching, dimming, energy monitoring, presence detection, indoor localization, switchcraft.
https://crownstone.rocks
91 stars 62 forks source link

Bug in setup #131

Closed mrquincle closed 2 years ago

mrquincle commented 3 years ago

Calling make setup (after make write_config and make reset) calls under the hood in the build directory:

csutil keys.json setup C2:81:75:46:D8:F1 config.json

The csutil code (https://github.com/mrquincle/csutil) is updated to use all new BLE python stuff with async etc. and is quite similar to https://github.com/crownstone/crownstone-lib-python-ble/blob/master/examples/setup_example.md.

Still, setup doesn't succeed. There's some ABORT_NOTIFICATION_STREAM_W_ERROR error on setup.

Scanning dependencies of target setup
Setup Crownstone via csutil
-- Cannot find configuration file: /home/anne/workspace/bluenet/config/default/CMakeBuild.runtime.config
-- Connect to device with address C2:81:75:46:D8:F1
-- Set up Crownstone (timeout is 60 seconds)
-- csutil "keys.json" "setup" "C2:81:75:46:D8:F1" "config.json"
-- Output: ===========================================

csutil

===========================================
Setup Crownstone at address: c2:81:75:46:d8:f1
Something went wrong with the notifications (<BleError.ABORT_NOTIFICATION_STREAM_W_ERROR: 'ABORT_NOTIFICATION_STREAM_W_ERROR'>, 'Aborting the notification stream because the resultHandler raised an error.')

-- Error: Unexpected notification data. Aborting...
Traceback (most recent call last):
  File "/home/anne/workspace/bluenet/source/conf/cmake/modules/../../../../tools/csutil/csutil", line 84, in <module>
    asyncio.run(setup())
  File "/usr/lib/python3.8/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "/home/anne/workspace/bluenet/source/conf/cmake/modules/../../../../tools/csutil/csutil", line 59, in setup
    if await core.waitForMode(address, CrownstoneOperationMode.NORMAL, scanDuration=10):
  File "/home/anne/.local/lib/python3.8/site-packages/crownstone_ble/core/CrownstoneBle.py", line 214, in waitForMode
    raise CrownstoneBleException(BleError.DIFFERENT_MODE_THAN_REQUIRED, f'During the {scanDuration} seconds of scanning, the Crownstone was not in the required mode..')
crownstone_core.Exceptions.CrownstoneBleException: (<BleError.DIFFERENT_MODE_THAN_REQUIRED: 'DIFFERENT_MODE_THAN_REQUIRED'>, 'During the 10 seconds of scanning, the Crownstone was not in the required mode..')

-- Status: 1
-- + Are you e.g. sure that you ran cmake with -DDOWNLOAD_CSUTIL?
-- + Did you set KEYS_JSON_FILE to a file with keys?
Built target setup
vliedel commented 2 years ago

Are you sure the crownstone was in setup mode? Because this seems to suggest it wasn't:

raise CrownstoneBleException(BleError.DIFFERENT_MODE_THAN_REQUIRED, f'During the {scanDuration} seconds of scanning, the Crownstone was not in the required mode..')
crownstone_core.Exceptions.CrownstoneBleException: (<BleError.DIFFERENT_MODE_THAN_REQUIRED: 'DIFFERENT_MODE_THAN_REQUIRED'>, 'During the 10 seconds of scanning, the Crownstone was not in the required mode..')
mrquincle commented 2 years ago

The line refers to https://github.com/mrquincle/csutil/blob/master/csutil#L59


    # Wait for setup to finish and the crownstone to reboot in normal mode.
    if await core.waitForMode(address, CrownstoneOperationMode.NORMAL, scanDuration=10):
        await asyncio.sleep(1)
    else:
        print("Something went wrong? Crownstone didn't come in normal mode")

I don't understand how you conclude that it's in normal mode.

vliedel commented 2 years ago

The python lib works with exceptions, you don't get a boolean return here. See https://github.com/crownstone/crownstone-lib-python-ble/blob/e7c04da4649ba0551dbc1444acac80a4bdd1b432/crownstone_ble/core/CrownstoneBle.py#L199

mrquincle commented 2 years ago

Then it still is the case that after setup the Crownstone is not in normal mode. Hence, that the setup failed.

PS: You should adjust your example then as well: https://github.com/crownstone/crownstone-lib-python-ble/blob/master/examples/setup_example.md

vliedel commented 2 years ago

Good point, I updated the example. Can you check if that works for you?

mrquincle commented 2 years ago

With the updated example code this works. It would be great to have a bunch of python tools that can be used for these common tasks like setup, factory reset, and eventually updating the firmware or microapps.