Sending data from mobile device to micropython device over bluetooth

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
digitalblur
Posts: 11
Joined: Mon Jan 13, 2020 5:31 am

Sending data from mobile device to micropython device over bluetooth

Post by digitalblur » Fri Dec 25, 2020 10:48 pm

Hi,

I am trying to understand the options for sending data to a micropython device over bluetooth from a mobile device. I want to send configuration data to this device from a mobile phone. I have the UART example working but is this the only option or is there another non-UART option?

Thanks in advance

User avatar
hcet14
Posts: 14
Joined: Sat Dec 19, 2020 12:59 am

Re: Sending data from mobile device to micropython device over bluetooth

Post by hcet14 » Sun Dec 27, 2020 3:23 pm

What's your device? Does it got bluetooth?
I'm a beginner with this stuff and no programmer at all.

digitalblur
Posts: 11
Joined: Mon Jan 13, 2020 5:31 am

Re: Sending data from mobile device to micropython device over bluetooth

Post by digitalblur » Sun Dec 27, 2020 6:39 pm

Yes Im using the dfrobot beetle esp32 here: https://www.dfrobot.com/product-1798.html

Bluetooth Protocols supported: BR/EDR/BLE standard of Bluetooth v4.2.

Is sending data over UART the only option? I only see an example for UART.

thanks

User avatar
hcet14
Posts: 14
Joined: Sat Dec 19, 2020 12:59 am

Re: Sending data from mobile device to micropython device over bluetooth

Post by hcet14 » Sun Dec 27, 2020 8:18 pm

What do you want to do? Establish a wirelesss connection between ESP and your mobile? And then, what is the ESP supposed to do?
I'm a beginner with this stuff and no programmer at all.

digitalblur
Posts: 11
Joined: Mon Jan 13, 2020 5:31 am

Re: Sending data from mobile device to micropython device over bluetooth

Post by digitalblur » Sun Dec 27, 2020 8:54 pm

I want to use my mobile to configure the software I have installed on the ESP device. For example, change wifi settings, change sleep time configuration, enable/disable software features, etc...

Is Bluetooth UART the only option? I have UART working to send data but I was told there is a non Bluetooth UART option for sending data to the device but I don't see any examples alternative to UART using micropython.

User avatar
mattyt
Posts: 336
Joined: Mon Jan 23, 2017 6:39 am

Re: Sending data from mobile device to micropython device over bluetooth

Post by mattyt » Mon Dec 28, 2020 1:29 am

Take a look at L2Cap; it's a way to perform connection-oriented transfers with BLE. It's worth noting that L2Cap is specified as the transfer protocol for BLE Object Transfer Service and, as such, is a key protocol in the BLE stack.

The problem you'll have is that this is a very recent addition to MicroPython, not particularly well documented (though the main methods are covered) and with no examples yet. However, it's an active area of development and I can help with some basic examples. Damien presented an overview at a recent Melbourne MicroPython Meetup but, unfortunately, we couldn't organise a recording of it at the time. He did mention he could repeat the session and record it, particularly if there's demand...

Briefly, L2Cap provides a bi-directional communication channel between two BLE devices. The channel is intended to be initiated and signalled by using standard GATT characteristics - for example in OTS a file can be requested using OLCP and OACP characteristics to select and operate on a file object.

I'm also not sure how solid the ESP32 L2Cap implementation is - we're using the STM32 WB55 and the Pyboard D. That said, the ESP32 was next on the list for support if it's not already there...

So, it's not yet a mature solution on MicroPython but probably the right one for sending data between two BLE devices.

digitalblur
Posts: 11
Joined: Mon Jan 13, 2020 5:31 am

Re: Sending data from mobile device to micropython device over bluetooth

Post by digitalblur » Tue Dec 29, 2020 4:09 am

Thanks mattyt, I think this makes sense. Since it uses Bluetooth standards a generic Bluetooth app such as nRF Connect should be able to utilize the L2Cap feature and send/receive data to the device, correct?

Im not super fluent with Bluetooth functionality but I am interested in trying to do this the right way. I am working on a prototype and this is one of the last pieces I need in order to do user testing. I am in contact with an app developer to build an app and Im trying to figure out what is the best way to move forward on this. Like I mentioned I have Bluetooth UART working for what I need but Im not sure if there are downsides to using this method (UART vs ?).

If you or someone else is able to provide a simple example for sending/receiving data using L2Cap I would definitely be interested in implementing this functionality.

thanks
Last edited by digitalblur on Thu Dec 31, 2020 12:43 am, edited 1 time in total.

Tupps
Posts: 2
Joined: Tue Dec 29, 2020 10:43 am

Re: Sending data from mobile device to micropython device over bluetooth

Post by Tupps » Tue Dec 29, 2020 10:55 am

From an App Developers perspective, BLE is the easiest option for communicating with a device. An app developer has the APIs and the control to talk to the device. Using other protocols are difficult on to implement.

One other thing to look at is Web BLE which is a Chrome (as in browser) feature instead of building custom Apps. This will make your configure tool available to Windows/Mac/Linux via Chrome (although Linux isn't 100% on all versions) and Android. The only downside I have seen with WebBLE is that the some older versions of chrome setup a low MTU (think under 50 characters) which is a PITA for SSID passwords (which can be 63 character long). However this seems to have been fixed in the later builds on Android Chrome.

Only downside is the Web BLE isn't officially supported on iOS (there are a few options).

User avatar
jimmo
Posts: 2262
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Sending data from mobile device to micropython device over bluetooth

Post by jimmo » Mon Jan 11, 2021 12:14 am

digitalblur wrote:
Fri Dec 25, 2020 10:48 pm
I want to send configuration data to this device from a mobile phone. I have the UART example working but is this the only option or is there another non-UART option?
If you want to send configuration data then I suspect a UART (or L2CAP) are overkill. You can define a characteristic that you can read/write your configuration data from/to.

I've seen people do this with packed binary data, or json blobs, etc.

If your configuration is really huge (like kilobytes) then you could split it over multiple characteristics (or perhaps then look at something like l2cap or uart).

digitalblur
Posts: 11
Joined: Mon Jan 13, 2020 5:31 am

Re: Sending data from mobile device to micropython device over bluetooth

Post by digitalblur » Sat Jan 30, 2021 6:41 am

jimmo wrote:
Mon Jan 11, 2021 12:14 am

If you want to send configuration data then I suspect a UART (or L2CAP) are overkill. You can define a characteristic that you can read/write your configuration data from/to.

I've seen people do this with packed binary data, or json blobs, etc.

If your configuration is really huge (like kilobytes) then you could split it over multiple characteristics (or perhaps then look at something like l2cap or uart).
Thanks jimmo, this is an option I would like to explore but I could not find any examples of how to write to a characteristic with micropython, only read examples. Are there any examples someone can point me to?

Post Reply