BLE local device name automated in Sketch

Has it reacted on old app inventor blocks, does not react to new ones?

These are old blocks from the first post.

These are new blocks.

The only significant difference is the values. So why do you think the first block works and the second doesn't. In my opinion it is not possible that the new block does not change the state of arduino, if the old block does.

Unless we have communication problems and misunderstood something.

It's best to paste the arduino code and aia file here, which correctly changes the arduino ON / OFF state.

Hi Patryk. When I wrote "old code" I didn't mean the oldest, I meant the attached code which incorporates some of your and / or Chris' earlier suggestions. It does, indeed, use the "new blocks" you attached above and it works as shown in all the phone screenshots in my last post. I'm sorry I was unclear.
scratch_for_ai2_help_5.aia (195.0 KB)

Try it:

scratch_for_ai2_help (7).aia (195.8 KB)

Truly weird behavior. Here are screen shots and descriptions of the aia file you just sent.

Freshly launched app:

After pressing Scan:

After selecting Dev1 for which the current state is OFF:

After connecting to Dev1:

After pressing the "toggle button":

Now the arduino has correctly been set to ON and is advertising the name Dev1_ON, BUT the button will only work once, i.e. when I press it a 2nd time it stays red and also has no effect at all on the arduino which stays in the ON state.

Similarly, here are the screenshots of going through the same process of connecting to the arduino when it's in the ON state:

Freshly launched app:

After pressing Scan:

After selecting Dev1 for which the current state is ON:

After connecting to Dev1:

After pressing the "toggle button":

Note that the button went from red and showing the OFF state to green and showing the ON state. This had no effect on the arduino, which is good because it was already in the ON state.

When I click the toggle button a 2nd time, the display is unchanged (see below) but the arduino state changes to OFF. As in the other case above, the toggle button is then inactive and cannot change the arduino state back to ON.

So, in both cases (i.e. connecting to the arduino in an OFF state or an ON state) the toggle button can change the state only one time.

It seems that this block:

component_set_get (7)

not return the currently advertised device name, only the one that was at the time of connection.A very simplified method. We will have to modify blocks to detect the current name.

Yes, you are right. That accounts for the behavior and it makes sense that ConnectedDeviceName is static after connection is made - not a live quantity. But the arduino code sets the Notfiy attribute of the characteristic:
BLEStringCharacteristic phoneTooClose(PHONE_TOO_CLOSE, BLERead | BLEWrite | BLENotify, 8);
so that the phone should be able to 'know' when the characteristic has changed (as per the Notify section here ). Somehow the phone code is not wired up to accept this Notification...

I modified blocks so that you can send the value with the toggle button, regardless of the label.

scratch_for_ai2_help (8).aia (196.0 KB)

You can try this AIA with a test button.

scratch_for_ai2_help (9).aia (196.3 KB)

Hi Patryk. Thank you for all your time and help with this. These last two AIA files don't improve the situation, unfortunately. I know that you are flying blind a bit because you don't have the arduino nano ble board(s) to test the AIA code against. Let me look into whether there's a reliable simulator which you or other people on this forum could use in lieu of physical boards to check the code - that would be a broadly useful tool and I would be happy if I could do some giving as well as taking... If there is a decent simulator, I will post it with some explanation and hope to resume our discussion. I will also post any solution I come up with to the problem we've been working on. Thanks again for all your help. I hope to post again soon :smiley:

Yes exactly. I do not have the NANO 33 BLE device. I have an ESP32 for this, I wonder if the sketch from Arduino will work in ESP32. Then I could adjust the blocks faster. I also have HM10, but it can not be changed name dynamically.

According to this, you can program the ESP32 from the Arduino IDE by adding an additional boards manager site and then adding the ESP32 to the list of boards the IDE knows about.

I have an Arduino environment adapted to ESP. Ok, will test your sketch. Experience with dynamic names can be instructive.

Sounds good! :+1:

What BLE Library do you use? Unfortunately, the ESP library is not compatible. It is a pity that they do not make libraries that are configured in the same way.

I use ArduinoBLE version 1.2.0 which I think I got on github here.

Try it:
scratch_for_ai2_help (11).aia (196.9 KB)

I went back to method, reading 5 and 9 after changing the arduino output state.

Hi Patryk. You're a star! This works like a charm. I just got back and tried it, but haven't gone through the sketch yet. Thank you very much for all your time and help. I hope the idea is useful to you, as well. And I hope to be able to return the favor... Best, Alex

The ArduinoBLE lib has a lot of flaws (but you can still compile). I really really dislike the attitude that has crept into programming where developers make zero effort to comply with specs or to consider consequences. I hope these people are not involved in any serious work else we will have aircraft falling out of the sky and autonomous vehicles running riot.

1 Like

I agree with you but I missed whatever raised your ire here. Did someone complain about the library?

New boards go into production without adequate libraries to support them. The quality of coding in some libs is atrocious, even unsupported value types are found. This unfortunately is the downside of Open Source and no 'central control'.

2 Likes

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