Skip to content

micropython (mch2022 badge) cannot import bluetooth #244

@rambo

Description

@rambo

USB REPL:

>>> import bluetooth
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: no module named 'bluetooth'
>>> import ubluetooth
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: no module named 'ubluetooth'

Does not work any better in an app (not that I really expected it to)

USB console:

Starting app '/apps/python/nightshift'...
No bluetooth, trying ubluetooth
Traceback (most recent call last):
  File "boot.py", line 26, in <module>
  File "/apps/python/nightshift/__init__.py", line 4, in <module>
  File "/apps/python/nightshift/nshift.py", line 7, in <module>
ImportError: no module named 'ubluetooth'
Fatal exception in the running app!
␀ets Jul 29 2019 12:21:46

init.py:

"""Control LightMode Nighshift"""
import buttons
import mch22
from .nshift import main
import uasyncio

# Register reboot button callback
def handle_reboot(pressed):
  if pressed:
    mch22.exit_python()

buttons.attach(buttons.BTN_A,handle_reboot)

uasyncio.get_event_loop().run_until_complete(main())

nshift.py

"""BLE and NS stuff"""
import uasyncio
try:
    import bluetooth
except ImportError:
    print("No bluetooth, trying ubluetooth")
    import ubluetooth as bluetooth


async def main():
    while True:
        print("Foo")
        await uasyncio.sleep(10.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions