Always runtime error when requesting Microbit data updates

107 views
Skip to first unread message

Kelvin Lee

unread,
Sep 18, 2019, 9:17:48 PM9/18/19
to MIT App Inventor Forum
Dear Sir/Madam,

I follow the steps from http://iot.appinventor.mit.edu/assets/howtos/MIT_App_Inventor_Microbit_Temperature.pdf but I want to read Accelerometer data.

Screenshot 2019-09-19 at 9.06.23 AM.png

There is no problem if I don't call the RequestAccelerometerDataUpdates in the BluetoothLE1.Connected, once I called, I got runtime error. 


Attempt to invoke virtual method 'void edu.mit.appinventor.ble.BluetoothLE.ExRegisterForShortValues(java.lang.String, java.lang.String, boolean, edu.mit.appinventor.ble.BluetoothLE$BLEResponseHandler)' on a null object reference
Note: You will not see another error reported for 5 seconds.


May I know what the potential issue? Does the issue from my phone, Microbit or AppInventor itself? 

Here is my setting:

Phone: Samsung A8+
Model: SM-A730F
Android version: 9
Kernal version: 4.4.111-16386177

Microbit
Interface Version: 0250

App Inventor Connect: USB

Kelvin Lee

unread,
Sep 18, 2019, 11:20:11 PM9/18/19
to mitappinv...@googlegroups.com
I still found runtime error for Safari browser, my browser version is 

Version 12.1.1 (14607.2.6.1.1)

Ghica

unread,
Sep 19, 2019, 3:48:21 PM9/19/19
to MIT App Inventor Forum
Which version of the BLE extension and of the micro:bit extension are you using?
Cheers, Ghica
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted

Kelvin Lee

unread,
Sep 22, 2019, 11:35:46 AM9/22/19
to MIT App Inventor Forum
Dear Ghica,

Thanks for your help.


I guess the error might be caused by USB connection, I tried to install the .apk but also failed. I attached the screenshot from my mobile. As I can't upload the .aia from this Google group, I attached the image of the blocks for your reference. 

Best regards,

Kelvin.





Screenshot_20190922-232801.jpg
blocks (2).png

Ghica

unread,
Sep 22, 2019, 12:22:11 PM9/22/19
to MIT App Inventor Forum
Ah! That one is simple: go to the design screen and to the micro:bit extension. Set the BLE extension as the bluetooth device.

If you want to post an .aia then edit an *existing* post and add it there. Of course you can also share it from a Google drive.
Cheers, Ghica.
Message has been deleted

Kelvin Lee

unread,
Sep 22, 2019, 12:40:43 PM9/22/19
to MIT App Inventor Forum
Dear Ghica,

Many thanks for your prompt reply. I missed this important step. I set the BluetoothDevice to BluetoothLE1, I got another runtime error

Is my phone not compatible to AppInventor? I still can't add the .aia file here, here is the link https://drive.google.com/open?id=1YbLF0rujg2XDDVaLETLepZMJzsLYTQBm

Best regards,

Kelvin.
Screenshot_20190923-003221.jpg

Kelvin Lee

unread,
Sep 22, 2019, 12:48:27 PM9/22/19
to MIT App Inventor Forum
Dear Ghica,

For your more information, I tested with another Samsung SM-A700YD, Android 5.0.2, got the same runtime error. 

Best regards,

Kelvin.

Chris Ward

unread,
Sep 22, 2019, 1:25:17 PM9/22/19
to MIT App Inventor Forum
Hello Kelvin

How did you get a space character in your Project File Name? No spaces allowed!

The when Microbit_Accelerometer1 Accelerometer Data Received  Block has some typos. Correct it thus:

DataReceived.png


Add a Notifier re the two important phone settings required:


Initialize.png


It's possible that data is not received because:

1) Phone Location and or Bluetooth is not switched on

2) Micro bit is not set to accept data requests without requiring Service/Characteristic Uuids.



Ghica

unread,
Sep 22, 2019, 1:27:09 PM9/22/19
to MIT App Inventor Forum
Hi Kelvin,
Did you load a .hex file onto your micro:bit that starts the Accelerometer service? Because that is basically what the error message says.
So far, I do not see a problem with your .aia
Cheers, Ghica.

Chris Ward

unread,
Sep 22, 2019, 1:31:01 PM9/22/19
to MIT App Inventor Forum
Kelvin

I should add that since your phone is connect to the PC via USB, build your App as an APK and install it on the phone. The phone will require Developer/Debug Mode to be set.
See my website:

Kelvin Lee

unread,
Sep 22, 2019, 1:52:54 PM9/22/19
to MIT App Inventor Forum
Dear Chris Ward,

I named the project as Microbit only, there is not space between the name, App Inventor does not allow this happen.

Yes both Phone Location and Bluetooth are ON

What should I do to requiring Service/Characteristic Uuids?

Best regards,

Kelvin.
Screenshot_20190923-014822_One UI Home.jpg

Kelvin Lee

unread,
Sep 22, 2019, 1:58:29 PM9/22/19
to MIT App Inventor Forum
Dear Ghica,

Yes, I load the attached .hex file.

Best regards,

Kelvin
microbit-BL_Service (1).hex
microbit-screenshot (30).png

Kelvin Lee

unread,
Sep 22, 2019, 2:07:33 PM9/22/19
to MIT App Inventor Forum
Dear Chris Ward

Yes, I enabled the phone with debug mode, I always do the web inspector. I tried to download the .apk or connect to the PC via USB, also runtime error. Here is the screen recording https://youtu.be/YqPSezZuprc

Best regards,

Kelvin

Chris Ward

unread,
Sep 22, 2019, 2:44:49 PM9/22/19
to MIT App Inventor Forum
Hi Kelvin

Strange - the Project file was named "Microbit Accelerometer.aia" when I downloaded it. Hope you corrected it as per my notes.

The actual hex file is of no use - we need to see the script that becomes a hex file.

The hex file should either support BLE Uuids, in which case the App needs to use them too, or, perhaps easier, the hex should explicitly not require Uuids. 

"Microbit Accelerometer.aia", downloaded from your Google Drive, does not use Uuids.

Ghica

unread,
Sep 22, 2019, 4:06:05 PM9/22/19
to MIT App Inventor Forum
@Chris,
The hex file is of use, because it was made with the Microsoft MakeCode app. If you drag that file over its blocks editor, you will see the source code.
Cheers, Ghica.

Ghica

unread,
Sep 22, 2019, 5:31:46 PM9/22/19
to mitappinv...@googlegroups.com
Hi Kelvin,
I tried your code and hex file.
I made some subtle changes, the ones Chris suggested, and I set the project to -no pairing required- in the settings.(see the wheel at the right top and click project settings)
And then it runs fine.

The easiest way to test this, is to connect your micro:bit via micro usb cable to your pc.
Drag the hex file to the micro:bit in the explorer (or whatever this is called when you are on a mac). It will start.
Connect your phone via Wifi to your PC with the companion, scan, connect, and the phone will display the accelerometer values immediately.
Cheers, Ghica

The .aia and .hex are attached.
Microbit_accelerometer_2.aia
microbit-BL_Service_1.hex

Kelvin Lee

unread,
Sep 22, 2019, 8:47:23 PM9/22/19
to MIT App Inventor Forum
Dear Ghica,

Thanks for your suggestion. I download the load the hex file to Micro:bit, I can see the start message and I can connect it via Bluetooth without making the Micro:bit to be paired. When I scan the Bluetooth device, the Micro:bit is shown in the list, I connect it, the Microb:bit change to the heart display. It works now. One very important step I did wrong was sometimes I didn't completely close the app, I got the runtime error with this version also.

I try to change the Project setting to Micro:bit back to the JustWorks pairing, I got runtime error again.  What is the problem? I tried to pair the Micro:bit via the normal Bluetooth pairing before scan the bit from app, or directly scan from app, both got runtime error.

Lastly, I switch back the pairing to no pairing and it works again.

May I know what is the problem? What is the difference between these two pairings? Any idea?

Best regards,

Kelvin


Kelvin Lee

unread,
Sep 22, 2019, 9:00:10 PM9/22/19
to MIT App Inventor Forum
Dear Chris Ward,

The actual hex file is of no use - we need to see the script that becomes a hex file.

Do you mean the make code? It can be imported by uploading the hex file.

The hex file should either support BLE Uuids, in which case the App needs to use them too, or, perhaps easier, the hex should explicitly not require Uuids. 
"Microbit Accelerometer.aia", downloaded from your Google Drive, does not use Uuids.

How do I know the hex file use the Uuids or not? 

Before replying this message, Ghica provided me with the solution, it works if I switch the Micro:bit pairing method from Project Setting, No Pairing Required:

But I still want to know why only this pairing method can work. 

Best regards,

Kelvin. 

Ghica

unread,
Sep 23, 2019, 6:33:50 AM9/23/19
to MIT App Inventor Forum
Hi Kelvin,
The other pairing methods can also work, but you have to jump through one or more hoops to do it. So, if you are just developing or experimenting it is not worth the trouble. If you make a serious app where you do not want free access by everyone to your micro:bit then you have to find out how to do it.
For the just works method it should be enough to pair the micro:bit in the settings of your phone first, for the serious pairing method, you also have to enter codes on your micro:bit, there is a site that explains it, search for it if you want to know.
Cheers, Ghica.

Kelvin Lee

unread,
Sep 23, 2019, 12:23:34 PM9/23/19
to MIT App Inventor Forum
Dear Ghica,

Thanks for your reply, what do you mean I have to jump through one or more hoops to do it? I still have no idea what I can do to let my mobile or my micro:bit can work with the default pairing method. I tested the micro:bit app and I can pair and flash the code without any problem. Do you mind giving me some direction on how I can solve it?

Regarding the site about the serious pairing method, yes I wan to know about it, could you send it to me?

Best regards,

Kelvin.

Chris Ward

unread,
Sep 23, 2019, 12:49:14 PM9/23/19
to MIT App Inventor Forum
Hi Kelvin

There are some useful links on my website:

The one from Lancaster University should help.

Ghica

unread,
Sep 24, 2019, 8:22:02 AM9/24/19
to MIT App Inventor Forum
Reply all
Reply to author
Forward
0 new messages