After applying a few fixes and running the app in app inventor, the first time I connect to the device I receive an error stating "Not connected to a Bluetooth low energy device" however often on the second or third try I would receive a different error stating: "Error 3300: Error 9007 in extension BluetoothLE: You cannot connect to a device when the device list is empty! Try scanning again." This time around though the device actually connects via BLE upon receiving that error and I can successful my (string) data from my device. This is the block there:
I tried to go after this device list error with some further (minor) reorganizing of my code base, as you can see in the block here:
So with this relatively minor change for some reason my BLE refuses to connect outright, on first connection I still get that "Not connected to a Bluetooth low energy device" error on first connection. Repeated connections either display no error eventually I see a new error: " Attempt to invoke virtual method 'void android.bluetooth.BluetoothGatt.close()' on a null object reference".
My most recent change I tried adding in when BluetoothLE1.Disconnected a call Bluetooth.StopScanning method, and now after 5-15 connections I started getting the "Error 3300: Error 9007 in extension BluetoothLE: You cannot connect to a device when the device list is empty! Try scanning again." again. I also added a small bit of logic that displays Connected or Disconnected in their respective while loops. However, this display reads Connected when the device isn't reading the data and Disconnected when the device is streaming me data. What the heck is going on and what should I be doing to fix these errors?