I Cannot Get BLE WriteStrings to Work with iOS

Hello, everyone!

I recently developed an Android app using App Inventor, and it is published on the Google Play Store and running well.

I have been trying to transition my app to iOS instead of starting from scratch with an Apple-specific development platform like XCode.

I have scrapped all of the Extensions (except for BLE) out of my project since they are not compatible with iOS builds as described by several posts that I have read here. However, @ewpatton’s post here suggests that the BLE Extension is built in to the App Inventor Companion on iOS and should not be an issue. I use the BLE Extension to communicate with an ESP32 in my project, and everything works perfectly well in the Android version of my app. I have not changed the ESP32 program at all.

I am using the TestFlight version of the App Inventor Companion on iOS (iPhone 13) to test my app during development. I am able to connect to the ESP32 and read strings perfectly fine; however, my biggest trouble has come from writing strings to the ESP32. None of the BLE.WriteStrings blocks in my project work. Here is an example block that does not work:

My ESP32 does a Serial Print whenever it receives data over BLE; nothing is coming through after running these blocks. The StringsWritten block also never gets called in my app. This just simply appears to silently fail.

Here is my app project file if you need a closer look. I apologize in advance for it being a little messy. :sweat_smile:

LevelSensorApp_iOS_V1_5_1.aia (2.4 MB)

I am more than willing to provide any other information that may be necessary.

Thanks in advance for any help with this matter!

Adam :slight_smile:

Are there any opinions on this issue? This is the last major obstacle for the iOS version of my app. I find it puzzling that I am able to connect and read over BLE perfectly fine. I tried the BLE.WriteBytes block as well, but nothing appeared to send with that either.

Thanks!

Adam :thinking:

I'm just coming back from a vacation but I'll queue this to as something to catch up on.

Thank you for the response!

No worries; I just did not want this to get lost in the sea of posts.

Adam :+1:

Has there been any progress on this?

Do not worry if it is still in the backlog; I am just checking in.

Adam

I will attach my PlatformIO project here as well in case that is useful for whoever is looking in to this issue. This is the program that runs on my ESP32 that interacts with this App. I am using the

#include <BLEDevice.h>

#include <BLEUtils.h>

#include <BLEServer.h>

libraries in this code (standard ESP32 BLE libraries). I would not think that these would be causing issues with iOS, but I am open to suggestions. If anybody needs me to highlight a specific section of the Program or App, I would be more than happy to clear things up. I know these projects like the back of my hand basically.

Any kind of update would be appreciated even if you have not taken a look at this problem yet.

Adam :slightly_smiling_face:

Google Drive Link to ESP32 Code

Attached is a test app I use with a BBC micro:bit to test the iOS read/write capabilities. The micro:bit is running a simple firmware that echos back the string it receives via the WriteStrings block. Check to see if you can create a similar firmware for the ESP32 and confirm it works for you. Note that I am testing this with the version of the companion in TestFlight, but I don't believe there are any pending BLE changes in that version versus what you would get in the App Store.

BLE_iOS_Test(1).aia (200.7 KB)

Thank you for the response.

I will test that out and report my findings!

Adam

Not sure it is of any help, but you could recompile your esp32 sketch setting tools→core debug level→debug and comparing the logs connecting to android and ios

P.S.

you can also try the WriteBytes and WriteBytesWithResponse instead of WriteStrings

@ewpatton

I tried your test project, but I got the same results. Connecting and reading work fine, but I am still unable to write. It may actually be an issue with my ESP32 BLE library. I will work on this some more tomorrow and update you with any results.

Adam :-1:

What's the failure mode when you adapt my app with your UUIDs? Do you get an error of any kind?

RegisterForStrings throws an error code (Attribute Not Found), but WriteStrings does not throw anything. I simply do not see anything coming through my ESP32 after the write. I did not try WriteBytes yet. I will be able to give you screenshots and more specific details when I am back at my setup tomorrow.

Adam

Thanks. Also, what version of iOS are you currently running? That can help us further narrow down if a specific API is problematic.

@ewpatton

I am back at my computer and setup for the day. I am running iOS Version 26.5.2 on my iPhone 13. I am also running the TestFlight version of the App Inventor Companion which is currently Version 2.78.3 (Build 8).

Here is the exact error that the RegisterForStrings block throws. It does not appear when I remove that block, so I am assuming that they are related.

Here is proof that I am still able to read strings using the BluetoothLE.ReadStrings block.

Here is what my ESP32 outputs. As you can see, it successfully registers connections and disconnections but no write events.

Hopefully that gives you some information to work on. Let me know if you want me to run any other tests. I will be around all day.

Adam

Any thoughts?

Adam

For a little bit of extra confusion, the App Inventor Companion recognizes my Write Characteristic as truly writable. :upside_down_face:

Additionally, I tried the WriteBytes block with the same results. No error was thrown, but no data came through my ESP32 either.

I will be back tomorrow.

Adam :waving_hand:

So I'm looking at the arduino-esp32 BLE library and it looks like PROPERTY_WRITE is the equivalent of our WriteWithResponse blocks, so you can either try changing that to PROPERTY_WRITE_NR (write no response) and keep the same blocks or swap the blocks for WriteStringsWithResponse and see if that makes a difference.

1 Like

THANK YOU!!! :joy::joy::joy::folded_hands:

That was indeed the issue. As soon as I switched to PROPERTY_WRITE_NR in my ESP32 code, the BLE.WriteStrings data came right through! I will simply enable both PROPERTY_WRITE and PROPERTY_WRITE_NR in my program to maintain compatibility across Android/Apple.

Thank you for your time and help in this matter. This is a huge relief for me!

I will let you know if I have any more issues as I continue development, but this was the biggest hurdle. Perhaps this should get tagged somewhere to help any other people who may be having the same issue?

Adam :tada::tada::tada:

@ewpatton

For your information, the BluetoothLE.WriteStringsWithResponse block does not appear to be implemented for iOS. I am getting the “Unrecognized Method *irritants(WriteStringsWithResponse)” error when I use the block. My App is able to do everything that it needs to do with the regular WriteStrings block, but I thought that this was an interesting observation considering that you suggested the WithResponse block as a potential solution to my problem.

Let me know if you have any thoughts on this.

Adam

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