Page 1 of 1

If Bluetooth and ubluetooth modules coexist.

Posted: Thu Nov 21, 2019 9:28 am
by net0040
In esp32 micropython firmware,such as v.20191121.

I want to know if Bluetooth and ubluetooth modules coexist. I see that the example is based on Bluetooth module.
And How long will this co-existence last?

thanks

Code: Select all

 import ubluetooth
 import bluetooth

Re: If Bluetooth and ubluetooth modules coexist.

Posted: Thu Nov 21, 2019 10:07 am
by jimmo
Simple version: The module is called "ublueooth", but "import bluetooth" and "import ubluetooth" are the same thing. You should use "import bluetooth" (same as "import machine, time, json, os")

Longer version:
In MicroPython most of the core libraries are named ufoo (including umachine, ubluetooth, etc), but if you "import foo", then it will automatically find the "u" version if "foo" doesn't actually exist.

There are two reasons for this:
- For the libraries which have the same name as equivalent libraries from the CPython standard library (e.g. json, os, etc), it makes it clear that it's the "micro" version.
- It allows someone to provide a pure-Python alternative version, named module.py (which can itself "include umodule" to get the low-level implementation).

Re: If Bluetooth and ubluetooth modules coexist.

Posted: Thu Nov 21, 2019 1:30 pm
by net0040
jimmo wrote:
Thu Nov 21, 2019 10:07 am
Simple version: The module is called "ublueooth", but "import bluetooth" and "import ubluetooth" are the same thing. You should use "import bluetooth" (same as "import machine, time, json, os")

Longer version:
In MicroPython most of the core libraries are named ufoo (including umachine, ubluetooth, etc), but if you "import foo", then it will automatically find the "u" version if "foo" doesn't actually exist.

There are two reasons for this:
- For the libraries which have the same name as equivalent libraries from the CPython standard library (e.g. json, os, etc), it makes it clear that it's the "micro" version.
- It allows someone to provide a pure-Python alternative version, named module.py (which can itself "include umodule" to get the low-level implementation).
thanks,I see :D