initial impression on the subject.
1. BLE is not in Connectivity, Is there a plan to move it there?
2. What are prospective of documentation and tutorials on BLE?
--
BLE is what is called an AppInventor Extension. It is not available in an AppInventor project by default. You can add the BLE extension by:
1. Go to MIT App Inventor Extensions
2. Download the BluetoothLE.aix file.
3. Click on "Extension" in the AppInventor palette (it should be the last header)
4. Click the link to "Import extension."
5. Upload the .aix file you downloaded in step 2.
6. Confirm the name "BluetoothLE" for the new extension
Once you have done the above steps you will be able to use BLE like any other non-visible component in AppInventor. A summary document with links to BLE tutorials and other resources is available here.
--
BLE is still an experimental implementation. Originally developed as component, but released as extension because it is easer to change things without too many compatibility issues.
If this becomes more clear, then, who knows, it could be released as a component.
--
When I went to "Controlling Bluetooth Low Energy devices with MIT App Inventor",in "Figure 10: Blocks Used to Get Device Services and Characteristics" was mention there're 4 blocks to get the device's UUIDs,but when I download and import the extension "BluetoothLE.aix" to AI2's palette,these 4 blocks was disappear!Do you know waht's the problem whit it? Thx.
--
These are renamed. The same names, but without the Get in front and using camelcase, i.e. GetCharacteristicsbyIndex becomes CharacteristicsByIndex and so on.
--
But I still don't know how to used them to got those UUIDs,In Fig.10 I couldn't found the example block of the example screen, would you kindly teaching me how to used these blocks to got those UUIDs by AI2?
--
This is still a dark side in the BLE functionality and documentation. I do not know what you intend to do, but quite many of the BLE-sketches seem to use a UART service.
You could test your device for example with this app: https://play.google.com/store/apps/details?id=com.nordicsemi.nrfUARTv2
Or you could try the attached .aia, which allows you to connect to a BLE device and show the supported characteristics and services. if it happens to be UART, it can even read the values and show them.
You could test your device for example with this app: https://play.google.com/store/apps/details?id=com.nordicsemi.nrfUARTv2
Or you could try the attached .aia, which allows you to connect to a BLE device and show the supported characteristics and services. if it happens to be UART, it can even read the values and show them.
--
Thank's for your help! I'm trying to study your .aia APP now,hope can understand it's meaning. What I'm going to do is very simply, just used BLE4.0 device as old BT device(not BLE) as a RF UART module. When used the old BT device,after pairing we only need to connected it at APP,but in BLE,we didn't need to paired first,just connected directly with the used of it's address, and when we want to Trx. or Rec. data,we had to assigned there Secvices&Characteristis UUIDs,this part of job is drive me crazy!So I hoped my APP can manage it automatically. After I choice the BLE device from the ListPicker,my APP will found the 2 UUIDS of it and assigned to the BLE's Read or Write block.
I'd some questions about your .aia APP hope you can explain for me.1'st: I found that you used fixed UUIDs, what kind of BLE is it?when used difference BLE device how to adapt it? 2nd:Can we activated the smartphone's Bluetooth function in our APP?
--
My app allows you to scan for devices and then choose one, but if you already know to which device you want to connect you can skip the selection process.
After you connected, you can check, by pressing the buttons, what the service and characteristic UUID's are that the BLE supports.
You can use this app for many different kind of devices, and if the device uses the UART service, you can read the values it sends out. Many devices like temerature sensors, heart rate meters etc, use this UART service.
I used it for a click switch, that would just send a single number when a button was pressed, and afterwards I used to same app for a device with an accelerometer, that was sending strings like "x=..., y=..., z=...".
Both devices show in the app the data they send. Of course, when you find that you can cummunicate with the BLE device, you must adapt the app to make something meaningful out of it, like showing a graph of values for example.
I do not understand your question about activating the smartphone's Bluetoot function. If you have old BT (not BLE) you must first pair the phone and the device before you can connect to it. With a BLE device, you can scan for devices, as my app does. After starting the scanning process, you can then use the ListPicker button to select a device and connect to it.
--
After you connected, you can check, by pressing the buttons, what the service and characteristic UUID's are that the BLE supports.
You can use this app for many different kind of devices, and if the device uses the UART service, you can read the values it sends out. Many devices like temerature sensors, heart rate meters etc, use this UART service.
I used it for a click switch, that would just send a single number when a button was pressed, and afterwards I used to same app for a device with an accelerometer, that was sending strings like "x=..., y=..., z=...".
Both devices show in the app the data they send. Of course, when you find that you can cummunicate with the BLE device, you must adapt the app to make something meaningful out of it, like showing a graph of values for example.
I do not understand your question about activating the smartphone's Bluetoot function. If you have old BT (not BLE) you must first pair the phone and the device before you can connect to it. With a BLE device, you can scan for devices, as my app does. After starting the scanning process, you can then use the ListPicker button to select a device and connect to it.
--
Thank's for your explanation, now I could found my BLE device's(UART) services & char. UUIDs, but my BLE's UUIDs was difference with your, so I had to change both of them to write or read the data from BLE, and it's what I going to manipulated, I hope my APP can automatically got the UUIDs after I chose the BLE device from the ListPicker.
In your APP I found that "Disconnect" button seen don't work,but if I change the address parameter to variables"global deviceAddress" will fixed it.About my question is that when we start our APP,if we didn't activated the Bluetooth interface of smartphone then the APP would not work,so I wander if there had any way in AI2 can forced the smartphone's BT open when we start the APP?
--
Thank you for spotting my mistake with Disconnect! I think it is because I try to disconnect with a string, from the textbox, and probably something is lost in the conversion.
As far finding the UUID's is concerned, that may be not so easy, I have a device that seemingly supports many services and characteristics. So I choose to build a list and find it by name. But in reality there are one very few UUID's that are used, so if you know it for your device, it would be easier to just set it. And I hope that the AI people at MIT will find ways to make this easier, they are certainly working on it!
I am wondering about your question. The trick to find a BLE device is to scan for it, using the call BluetoothLE.StartScanning block, you could do this at initialize if you wish. Do you need to do other things to make the connection happen?
As far finding the UUID's is concerned, that may be not so easy, I have a device that seemingly supports many services and characteristics. So I choose to build a list and find it by name. But in reality there are one very few UUID's that are used, so if you know it for your device, it would be easier to just set it. And I hope that the AI people at MIT will find ways to make this easier, they are certainly working on it!
I am wondering about your question. The trick to find a BLE device is to scan for it, using the call BluetoothLE.StartScanning block, you could do this at initialize if you wish. Do you need to do other things to make the connection happen?
--
I think I'd solved the problem about that when my APP start running can automatically got the UUIDs after I chose the BLE device from the ListPicker. I'm modified your App to perfomce UART secvice device,in the App can Read/Write data to BLE/UART interface device like HM-10, I would like to shared with you. But there's still a little bug,when the App first connect the BLE device the App can't got the UUIDs,it must connect again! After that the App will work correctly. The attached file is my App,would you like to try and give me some opinions?Maybe you can fixed that bug!
--
I really like your improved design!
As far as the bug is concerned, there are two issues: You do a start scanning twice, but disabling the ListPicker.beforepicking block does not solve the problem.
I think it is maybe a timing issue. You could try to start a clock-timer, when the BLE is connected and do the stuff of finding the UUID's when the timer fires, (also disable the clock again).
Then, finding the UUID's is not as simple as finding the last one in the list as your app seems to think. For my Adafruit that does not work, the UUID's are really different and not the last one in the list. Also, the write UUID characteristic is different from the read UUID characteristic. Further, upper case should not matter, the UUID is a hexadecimal number, but maybe there are device who do this wrong.
See here: https://learn.adafruit.com/introducing-adafruit-ble-bluetooth-low-energy-friend/uart-service.
It is also not a good idea to try and read something immediately after connection in general, because that may not be what you want to do and because of the timing issue I think the UUID's are not available at first.
For my Adafruit I added two listpickers that allows me to make a choice and not to have to type these long numbers. With this I could pick the UUID's and my Adafruit works fine then.
I am out of time now, therefore I attach my .aia with these changes. I hope you can continue with this.
I think it is maybe a timing issue. You could try to start a clock-timer, when the BLE is connected and do the stuff of finding the UUID's when the timer fires, (also disable the clock again).
Then, finding the UUID's is not as simple as finding the last one in the list as your app seems to think. For my Adafruit that does not work, the UUID's are really different and not the last one in the list. Also, the write UUID characteristic is different from the read UUID characteristic. Further, upper case should not matter, the UUID is a hexadecimal number, but maybe there are device who do this wrong.
See here: https://learn.adafruit.com/introducing-adafruit-ble-bluetooth-low-energy-friend/uart-service.
It is also not a good idea to try and read something immediately after connection in general, because that may not be what you want to do and because of the timing issue I think the UUID's are not available at first.
For my Adafruit I added two listpickers that allows me to make a choice and not to have to type these long numbers. With this I could pick the UUID's and my Adafruit works fine then.
I am out of time now, therefore I attach my .aia with these changes. I hope you can continue with this.
--
As you mention that it maybe was the time issue that UUID was not available when BLE device been connected,My first thought was also the same. In my experience I feel that BLE device might need some latency or delay time when receive the asking .SupportedServices command,so I add some delay time after the .SupportedServices procedure,when I increase the delay to 2000ms the APP got the SupportedServices data,so I think this way can fixed the problem! Because my BLE module'UUIDs both on the last position so I used that way,If you know your Adafruit BLE's UUIDs position,after received the UUIDs data,you can extract them and assigned them to the variables,so that your APP's user will not need to choose them manually,and this was my original goal!
The reason that I use the .StartSacnning function in Screen1.Initiallize block is also the same as when find the UUIDs,if you remove that block you have to touched the ListPicker twice,and even I add a long delay time still can't solved it!do you have any good ideal can fixed it?
--
Sorry for my late reply and I still have to work on solving your problem.
But... did we not tell you to NEVER EVER use a delay in App Inventor???
If you need a delay, you use a clock, otherwise you will have a lot of problems. See also here: The simple Virtual life
But... did we not tell you to NEVER EVER use a delay in App Inventor???
If you need a delay, you use a clock, otherwise you will have a lot of problems. See also here: The simple Virtual life
--
Thx for your time Ghica,because I was first time joint this forum,so I never hear about the problem of use delay function. Like Joe said that different blocks can never interrupt each other, so I don't how to link the clock as a delay function in the BLE.Connected block, would you kindly give me some hint? Thank's for all!
--
The problem with your ListPicker is that you do the start scanning in the BeforePicking block. This means there is not enough time to scan for devices before the ListPicker is openend and therefore you have to press it twice. You could solve this by starting the scanning in theScreen.Initialize block but the great disadvantage of this is that your device must be turned on before you start the app, something I always forget.
Therefore it is better to have a button to start the scanning. If you want to be fancy, you could enable the clock in the button.Click event block and in the Clock.Timer event block you set the listpicker elements and open it. If you are not so fancy, there is enough time between pressing the button on clicking on the listpicker and you do not need a clock.
I still have a real problem with the way you determine the characteristic and service to be used. This may work for your device and for the sketch you currently have in your Arduino, but in general it does not work.
If you want a more generalized app, then what you could do is to have listpickers for these, (you need three, one for read, one for wrtie and one for the service). After a choice is made for the first time you store the values in a TinyDB, and the next time you can retrieve the values from there. You could also do that for the device address. But it will make your app rather complicated.
In practice, if you are using one of the standard services, it is completely clear what the service UUID should be and the read or write characteristic that go with it. So, when you write your app, you can just hard code it.
In the future there will be functionality in the BLE component that will make this easier for you, but it is not there yet.
I hope you can solve your problems now, otherwise, I am willing to help further.
Therefore it is better to have a button to start the scanning. If you want to be fancy, you could enable the clock in the button.Click event block and in the Clock.Timer event block you set the listpicker elements and open it. If you are not so fancy, there is enough time between pressing the button on clicking on the listpicker and you do not need a clock.
I still have a real problem with the way you determine the characteristic and service to be used. This may work for your device and for the sketch you currently have in your Arduino, but in general it does not work.
If you want a more generalized app, then what you could do is to have listpickers for these, (you need three, one for read, one for wrtie and one for the service). After a choice is made for the first time you store the values in a TinyDB, and the next time you can retrieve the values from there. You could also do that for the device address. But it will make your app rather complicated.
In practice, if you are using one of the standard services, it is completely clear what the service UUID should be and the read or write characteristic that go with it. So, when you write your app, you can just hard code it.
In the future there will be functionality in the BLE component that will make this easier for you, but it is not there yet.
I hope you can solve your problems now, otherwise, I am willing to help further.
--
Thx for you help Taifun!
--
Does your problem been solved?After these day of discussion and thinking,I think your problem(me too) about determine the characteristic and service to be used maybe is a fake issue. I don't know what's the purpose of you to used the BLE device? But when you choice the BLE module/type the characteristic and service should be fixed,it will change only when you select another type of BLE that manufactured by difference company,so we can used the fixed characteristic and service UUIDs in our APP. It's also mean that in our APP we don't need to support the function that let user select or input the BLE device's characteristic and service UUIDs! Do you agree with me?
It's seem that we had the same problem,I was also frequently forget to turned on the BT device before start the app, and that's the reason why I asked you before that this there any way can force to turn the smartphone's Bluetooth interface in AI2! In my example APP if I don't starting the scanning in theScreen.Initialize block just start scanning in the BeforePicking block,even I add a long delay time with it, it's still can't found any BLE device information. By this result I felt that it's might be not because the lack of time.
--
What can I say? I never had a problem, my main problem is that I do not succeed in showing you how to solve your problem.... :-(
I explained why you needed to press the lispicker twice and (together with Taifun) why the delay you still had in your .aia is really bad.
So, here is a little app, which just can connect and disconnect and which uses a clock instead of a delay.
It seems as if there is only one button in it, because the ListPicker is invisible and automatically opened. The Connect and Disconnect buttons are alternatively visible.
Below you can see the blocks. You can copy the blocks in your app via the backpack if you wish.
Then there is the question about the UUID's and how to find or set them. I think you misunderstood the purpose of my app. It is there for educational purposes and if you want to start an app for a new BLE device, to find out what device address it has, what services and characteristics it offers and to allow basic communication with the device.
Once you have found these UUID's, you should modify your code to just have fixed, hard coded UUID's in your app, because the user of your app should never have to deal with these.
Please study the code and I hope that this clarifies things for
I explained why you needed to press the lispicker twice and (together with Taifun) why the delay you still had in your .aia is really bad.
So, here is a little app, which just can connect and disconnect and which uses a clock instead of a delay.
It seems as if there is only one button in it, because the ListPicker is invisible and automatically opened. The Connect and Disconnect buttons are alternatively visible.
Below you can see the blocks. You can copy the blocks in your app via the backpack if you wish.
Then there is the question about the UUID's and how to find or set them. I think you misunderstood the purpose of my app. It is there for educational purposes and if you want to start an app for a new BLE device, to find out what device address it has, what services and characteristics it offers and to allow basic communication with the device.
Once you have found these UUID's, you should modify your code to just have fixed, hard coded UUID's in your app, because the user of your app should never have to deal with these.
Please study the code and I hope that this clarifies things for
--
What I can say? Except The Thxs there were still the Thxs! Thxs that you spend so many time to teached me. From you last BLE_connect.aia I 'm clarifies how to fixed my problem,I thing I can carry on my study about the BLE, Thxs again!
What I can say? Except The Thxs there were still the Thxs! Thxs that you spend so many time to teached me. From you last BLE_connect.aia I 'm clarifies how to fixed my problem,I thing I can carry on my study about the BLE, Thxs again!
--
I am happy to hear that!
--
댓글 없음:
댓글 쓰기