Bluetooth Issue in IoT (Internet of Things) Tutorial

When I was following the tutorial of this IoT topic (The Internet of Things: Data Acquisition and Analysis), I founded out that whenever I sent a message from the phone to the micro:bit via Bluetooth, the corresponding micro:bit event handler was called up twice every time.

Does anyone encounter the same problem as mine?

Sorry, there have been some time since my last post. So, could any member from the MIT team answer this? As this is an official tutorial.

What exactly happens? Why do you think the microbit event handler is called twice? Can you attach your aia and your hex file?

Thanks for the reply. Please see the following code blocks:

The 1st one is the AppInventor --

The left side are the collapsed boilerplate blocks (provided by the tutorial) for bluetooth connection. The right side are the ones I use for the test. When "Button1" is clicked, it sends a message (the message's content is not important for the purpose of the test) to the micro:bit. And also the number of clicks is recorded and shown in "Label1".

The 2nd one is the Micro:bit --

I use a variable "pass" to count how many times micro:bit has received the message (Be noted: the received message's content is stored in the variable "notUse", but it is irrelevant to the issue).

And the result is when I click the button once, the count on the phone's screen goes up by 1, but goes up by 2 on the micro:bit's screen!

The following are the related aia and hex files:
AppInventor_MicroBit_connect_issue.aia (310.3 KB)
AppInventor_MicroBit_connect_issue.hex (1.3 MB)

What I think that happens is that you send two times a comma (,) and therefore the microbit also counts two times a comma. This is also done in the examples in the iot tutorial and maybe it is wrong.
I will try for you later today.

I indeed tried your example. I just removed the first , in the string that is sent. And, as expected, your number increases nicely by one each time.

Thanks Ghica. I've tried your solution, and got the same result as yours. But now I want to make sure the correct message is indeed received by the micro:bit, after an extra pass is eliminated. So, I modified both sides' codes a bit :

On the App Inventor side, it becomes --

The change, is now a single letter 'a' is sent and one comma only (trailing comma as you advised). Other things unchanged.

On the Micro:bit side, it becomes --

The change, is now the "message" received is also shown on the screen of the micro:bit, alongside with the number of the pass.

The result : At the 1st time I click the button, the correct message "a" is indeed shown. But strangely, when I click it again (pass 2), no "a" appeared. And all subsequent clicks also show no "a". Although the number of the pass is still shown correctly.

Now I really begin to think the extension codes is written poorly by whoever wrote it. :disappointed:

I think you should wait with your opinion.
These things all happen asynchronously and maybe it is different from what you think. Please attach your updated .aia and .hex, I will try to try it tomorrow.

OK, the followings are my updated codes:

microbit-AppInventor_MicroBit_connect_issue.hex (1.3 MB)
AppInventor_MicroBit_connect_issue.aia (310.2 KB)

It seems I have no time today to try out a solution, but I am pretty sure that I know what the problem is.
First of all, update your BLE extension with the one found here: MIT App Inventor Extensions
Just load it as if it was a new one, and it will update your old one.
Then, microbits are slow devices, you should not send anything new before you are sure that the previous message is received and handled.
So, send something back at the end of your handling of the message and disable the button until you have received a reply using, for example,

Let us know.

Sorry, still no luck after replacing with a new BLE extension.

And for the speed of micro:bit, I think it's fairly responsive, from my use experience. Anyway, I've edited the codes from both sides as you suggested. And only press the button again after receiving response from the micro:bit. But sadly, the result is still the same.

Upon investigation I agree that something strange is going on and that you somehow need double delimiters, which was not the case earlier. I will do some more experimenting but not before tomorrow night.

OK, take your time :grinning_face_with_smiling_eyes: I have not in hurry. I am not doing any project relating to this tutorial currently.

I still do not have a clue why your example does not work, but at least here is a working example.

I dug out my tutorial, updated it with the latest BLE extension and I made sure that I was using the same microbit extension as in the IOT tutorials. I changed my microbit hex to show the number of messages recieved. It looks like this:

This is the .hex file,
microbit-UART_RW_2.hex (1.3 MB)
and here is the .aia
BTReadWrite4_strings.aia (296.6 KB)

Some note about speed though: if you try to control a robot car using an accelerometer on your phone, or a robot arm, then you shold really make sure that the microbit has done all processing, or it will soon jam. Another note: it seems that the maximum message length is around 20 characters, so not too much. I hope this helps.

Thanks, I will try your files a bit later, and let's see if I can find out something worthy to take note of.

Hi Ghica, I've tested with your files and indeed works. But from looking at the method calls your files use, it seems that the Bluetooth and microbit extensions (on the App Inventor side) are probably different than the ones in that tutorial. Should the tutorial writer update it to use your version instead?? :grinning_face_with_smiling_eyes:

I do not know, but maybe @robert_parks, the author of the tutorial knows!