Skip to first unread message

Skyler

unread,
Sep 26, 2017, 8:44:52 PM9/26/17
to mitappinv...@googlegroups.com

I've been working with a BLE arduino board to send data from a sensor to App Inventor. My device uses a UART protocol to send information and when I connect with BLEScanner I can see this output:

 


The value on HEX under notify does indeed change repeatedly, usually corresponding to a Value (despite not being pictured here there is usually a "Value:" field corresponding to the HEX input). However, when I try to take this and connect it with app inventor it appears that StringValueChanged never gets called (nor did Byte Value Changed when I tried to send just a byte of information). My blocks for BLE look like this:


Device Label successfully reads the MAC address of my connected device
Label 4 successfully outputs whether the device is connected. This is corraborated by ListPicker1 and the UI, which almost completely changes in response to the connection. 
The only things that don't happen is Label1 having the BG color or text change, which leads me to believe the string value does not seem to be changing. Anybody have any ideas what error I seem to be making?

Evan Patton

unread,
Sep 26, 2017, 9:38:02 PM9/26/17
to MIT App Inventor Forum
Hi Skyler,

It looks like from your blocks that you are using an older version of the BLE extension. You should consider upgrading to the newer version, which you can download here. Documentation of the newer blocks can be found on our IOT website. In the newer version, you will want to use the method RegisterForStrings to request events when the BLE devices makes changes to the characteristic.

Evan

Skyler

unread,
Sep 28, 2017, 4:14:06 PM9/28/17
to MIT App Inventor Forum
Hi Evan. Thanks for that direction. Things are working now somewhat, however on the app inventor side I've observed my data listener is freezing up. Currently I had about 75 entries per second streaming, and after about 3000-4000 broadcasts the program starts freezing up and become unresponsive. All I am doing so far with this is modifying 1 label (a real time readout of the data string). The program seems to then want to crash around 8000 entries.
Relevant Blocks:

Abraham Getzler

unread,
Sep 28, 2017, 4:29:34 PM9/28/17
to MIT App Inventor Forum
I notice this particular app is not polling for input,
but running purely on data arrival events.

The circumstances suggest data is piling up somewhere upstream of your AI2
app.

Does the BlueToothLE component have Designer attributes to
speed up its polling for input?

If there's no handle on the problem there,
you would have to go upstream to the transmitter,
and slow it down.

ABG

Evan Patton

unread,
Sep 29, 2017, 12:31:59 AM9/29/17
to MIT App Inventor Forum
The RegisterFor* methods interface with Android's BLE stack by setting up a listener that responds to notifications from the connected BLE device. The method only needs to be called once per desired characteristic after the device connects.  Then, as the device changes the characteristic's value, the notification of the change will be propagated up through to the BLE extension. There isn't a polling mechanism in the BLE extension, rather, when the data changes on the remote device it sends a packet to the phone/tablet which then processes the information. This is how the low energy part works because being awake to poll frequently is very power intensive.

So with that detailed explanation in mind:
1. ABG's recommendation to reduce the rate at which you're sending data might be useful. While I think, given your code, App Inventor should be able to keep up in general, most devices at best will probably do screen refreshes at 60 fps. Sending 75 samples/sec and updating a label is just extra processing power wasted since the data won't be rendered that quickly.
2. Rather than using a clock to check for connected states, you should use the Connected/Disconnected events of the BLE extension to respond to changes in the connection state.
3. What might be happening here depending on how your Clock's timer is set is that you are registering many (N per second) listeners that eventually cause you to run out of memory. If you refactor your code so that you only call RegisterForStrings once your app will probably live a lot longer.

Evan

Abraham Getzler

unread,
Sep 29, 2017, 12:49:02 PM9/29/17
to MIT App Inventor Forum

Skyler

unread,
Oct 4, 2017, 7:34:22 PM10/4/17
to mitappinv...@googlegroups.com

From the arrangment below the first time I connect a get a notification saying that "Not connected to a Bluetooth low energy device", but upon trying to connect a second time it works sometimes. I've been seeing this error when the connection successfully establishes:

Attempt to invoke virtual method 'void android.bluetooth.BluetoothGatt.close()' on a null object reference<br/><i>Note:</i>&nbsp;

 Thanks for the pointers Evan, runnning in companion mode I experienced none of that slowdown we spoke of before with you suggested modificiations. However, when I try to compile the app I now get this error:

ERROR: appinventor/ai_SkylerBSaleebyan/TempReader/Screen1.yail line 237: caught exception in inliner for #<procedure gnu.kawa.functions.AppendValues> - java.lang.RuntimeException: no such class: edu.mit.appinventor.ble.BluetoothLE
I couldn't help but see you've responded to someone else seeing the error though it wasnt quite resolved what was causing it. Here are my blocks: 


Evan Patton

unread,
Oct 6, 2017, 1:13:46 PM10/6/17
to MIT App Inventor Forum
Hi Skyler,

Would you be able to email a copy of your AIA? I can poke around and try and figure out why it is giving you that error on the buildserver. It should be the case that the app compiles correctly, but this sounds to me like it is unable to find the extension code in the project.

Thanks,
Evan

Skyler

unread,
Oct 10, 2017, 4:41:14 PM10/10/17
to MIT App Inventor Forum
attached here
TempReader_copy (1).aia

Skyler

unread,
Oct 10, 2017, 8:17:27 PM10/10/17
to MIT App Inventor Forum
Also your point about the extension code is good but also a point of concern for me. The original project had all the blocks stop rendering and lost connection to the BLE library, when I exported and reimported I got this code base with the blocks intact. I've been a bit apprehensive of losing all my progress so I haven't played with the imported BLE library since then.
Reply all
Reply to author
Forward
0 new messages