Connecting to a specific Bluetooth classic device (no list picking)

Is there a guide available for connecting to a specific HC-05 Bluetooth classic device?

I have made an App that successfully connects using list picking, but now I just want to auto-connect to the same device every time, as soon as App starts.

As related question: if I start a new project, and drag in BluetoothClient, then in Block editor BluetoothClient1 only offers one "When .. Do" block as shown:

Why can't I see or pick other Bluetooth "When .. Do" options?
For example:

Just store the mac address of that Bluetooth device, i.e. the listpicker selection in TinyDB and read that address next time after starting the app to connect directly

You only can use events which exist... you can't invent arbitrary events...

Taifun

You need to pull in a Clock Timer from the Sensors Drawer.

I was planning to simply hard code the bluetooth address into the code, may not need tinyDB.
But I'm really asking what blocks to use to set up Bluetooth classic link to just one device, and how to find them in the tool.

"You only can use events which exist" Can you expand on this please. For example the only way I've got a block like "when BluetoothList.BeforePicking" into my project is by uploading some else's aia found in the forum. I'm asking how to find blocks like this myself within the tool, they seems to be well hidden !

That is probably a renamed ListPicker component

It would help if developers identified renamed components with a prefix, or such like:

lpBluetoothList where lp indicates a listpicker, and e.g. bt for button, lb for label...

You can find the listpicker in the user interface drawer User Interface

A very good way to learn App Inventor is to read the free Inventor's Manual here in the AI2 free online eBook http://www.appinventor.org/book2 ... the links are at the bottom of the Web page. The book 'teaches' users how to program with AI2 blocks.
There is a free programming course here Course In A Box and the aia files for the projects in the book are here: App Inventor 2 Book: Create Your Own Android Apps
How to do a lot of basic things with App Inventor are described here: How do you...? .

Also do the tutorials Our Tutorials! to learn the basics of App Inventor, then try something and follow the Top 5 Tips: How to learn App Inventor

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by icon24 Taifun.

Please don't give me general answers, I'm asking a speciifc question:

What are the steps to get those (bluetooth) blocks to appear in my blocks editor?

I promise you that for the last few weeks I've been looking at tutorials , reading the documentation (including the free book), searching the forum for answers. I've made good progres but this one quesion has stopped me in my tracks:

What are the steps to get those blocks to appear in my blocks editor?

For example the Client:Connect: section of A Simple Bluetooth Chat with AI2 has beforepicking and afterpicking blocks.

I'm only asking for suggestions on how to connect to specific bluetooth device with a known address, without picking.

If this is not possible, tell me.

We have already told you.

From the guide:

The first few words tell you.

lipConnect is a listpicker component. There are no other blocks in the Bluetooth component.

To answer your question: use a listpicker.

Drag a listpicker into the working area to get a Listpicker1 component
Then rename it to whatever you want, for example to BluetoothList to get the blocks you are looking for

Again: do the tutorials to learn some basics!

Taifun

Read again my answer from here

Taifun

If I have correctly understood your question, i.e. that you already know the address of your HC05 shield, by elaborating what @Taifun has already suggested, instead of storing that value in the TinyDB, you can assign that value to a text variable, like the image below. In this way you really "hardcode" the address in your app.
image

Having assigned that, to connect always the same address, you can use the following blocks:
image

In my example, only after a successful connection, I enable a 10 ms clock (Ck_BT_Rx) that manages the BT communications.

That's all.

1 Like

Excellent thank you uskiara, that works a treat:

BT blocks

I haven't looked into clock timers yet, but I'd really really really like to see how you setup a 10ms timer :slightly_smiling_face:

Do you understand about the blocks now (listpickers etc.) ?

1 Like

Glad it works. :grin:

As far as the BT clock is concerned, tpically I do like that:

  • In the designer page
    image
    -in the blocks page:
    image

In addition, as @TIMAI2 and @Taifun have already said, you can also find a great help by digging the forum or having a look to their web sites.

The MiT App Inventor (MAI) is a really good tool and very comprehensive so there's a lot to uncover. Fortunately I'm comfortable with progamming (C++ mainly), so I found the basics very easy to pick up. Downloading & reading the docs, doing tutorials and asking on the forum over recent weeks has been helpful.

But there are some things that just aren't covered. For example if you search the web, docs or forum on bluetooth classic in MAI pretty much every example uses a listpicker = not what I needed. Hence this thread.

Every time I use MAI I find another trick or subtlety (that's a good thing!). For example through this thread discussion I realised why many of the blocks are not listed in the "Built-In" section of the blocks editor and are instead available by clicking on each component (in the left pane of the blocks editor).

So yes, I understand the block better now, thanks :slightly_smiling_face:

Ahah, thanks again uskiara. That's too easy ...

thanks also to Taifun and TIMAI2 (metricat? :slightly_smiling_face:) for your helpful suggestions.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.