macos/ios <-> raspberry pi data transfer over L2CAP le. the mac uses CBL2CAPChannel. at the pi end, a python prog with a c-extension module sends OBEX commands over l2cap_le to implement file transfer.
mac requirements:
- macos (tested on 12.7.6)
- xcode (tested on 14.2)
pi requirements:
- a model with bluetooth
- python 3.x
- bluez (i think it is built into bullseye)
- bluez_peripheral if need l2cap host socket on pi.
the L2CAP channel operates in basic mode.
tested only on mac powerbook. in theory, the comms should work with ios
because it uses the same corebluetooth framework, but this is untested.
by choosing the obx_server_le_ios scheme you can compile for, and download
to an ios device. the ios app is sandboxed so there may be nothing
to download unless the code is modified to create/move some files first.
bear in mind that bluetooth does not work in the ios simulator.
settings on the mac:
- firewall off
- bluetooth sharing on
- receiving items: accept and save
- folder for accepted items: Downloads
- browse: allways allow
transfer setup.py, l2cap_le_py.c, obxget_le.py, obx_const.py and demopihost.py
to the same raspberry directory.
edit line 8 of obxget_le.py :
MACADDR="AA:BB:CC:DD:EE:FF"
so the bd_addr is that of your mac. you can find this with hcitool scan.
make sure bluetooth is on (both devices) and mac + pi are close to each other.
on raspberry do:
python setup.py build_ext --inplace
this builds the _L2CAP_le extension module.
maybe adjust xcode-build-settings-deployment install group + owner.
compile/run obx_server_le on the mac.
when you see added service, do:
python obxget_le.py <filename_to_get> in raspberry terminal.
you might get pop-ups asking for connect- and dir-access- perimissions.
probably a good idea to switch bluetooth sharing off when you are done.
the mac complains: "no central present! creating new object. this shouldn't happen." but things still work. the mac is expecting an apple peer to connect to it first. technically, the client should retrieve the psm via a gatt enquiry. get_psm.py is one way to do this.
the default l2cap psm depends on which version of macos you use. i have seen 193 and 192. the psm that obxget_le.py uses must match the server's psm so edit obxget_le.py accordingly.
demopihost.py is an example of making the raspberry the L2CAP le server, to which corebluetooth can connect. the Correspondent class acts as a test-partner to demopihost.