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)
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:
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.
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...
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
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.
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.
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.
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'.