1 2 Previous Next 16 Replies Latest reply on Aug 10, 2015 6:09 AM by dale.kramer

    BLE basics

    dale.kramer

      I am trying to become a convert from the PIC community.

         

      I have watched almost all Cypress videos on PSoC Creator and BLE.

         

      I am working with the EZBLE PRoC Module in my 'Widget' design.  My widgets only direct interface with the user is the pushbutton that wakes the widget from hibernation and when the user plugs a USB cable in to charge the LIR2032 battery.

         

      I am trying to create a custom BLE profile but I am getting lost in the details.

         

      Here is what I am trying to do:

         

      My widget has about ten 8bit configuration variables that need to to adjusted on my 'iPhone' yet persistently stored on the widget.

         

      I do not need continuous polling, I plan to simply have a user initiated request sent from the iPhone that is labeled 'Obtain Current Settings from Widget NOW'.  Then the user modifies the variables on the iPhone and finishes by initiating an 'Update these Settings to the Widget NOW' action.  The widget would respond with an acknowledgment of receipt of new values and the user would see the acknowledgment on the iPhone or be informed that the widget has not responded.

         

      This method should use minimal energy from the widgets battery if implemented properly.

         

      Some basic questions that I have in creating my custom profile are:

         

      1. Would I select Client and Server as the Profile Role?

         

      2. Would I select Peripheral and Central in the GAP Role?

         

      3. What services would I need in the Client and Server?

         

      4. How would I set up the characteristics to send and receive this data?

         

      5. How would I set up the code on my widget to listen for requests/data from the the iPhone using the least energy? (perhaps I could have the iPhone try sending for 5 seconds and the widget only look for requests from iPhone every 4 seconds or something like that)

         

      6. A non-BLE question, how would I make these configuration variables persistent on my widget when the battery is removed or my program code reloaded.  On my PIC widget, which does not have EEPROM, I reserve some program memory that my linker and programmer does not erase and I write these variables to that program memory area?

         

      7. Is there any sample code project that could help me?

         

      Thanks,

         

      Dale

        • 2. Re: BLE basics
          dale.kramer

          Thanks, never saw that series, I will check them out.

          • 3. Re: BLE basics
            dale.kramer

            I have reviewed the two projects, of the currently 48 projects in that series, which you cited.

               

            Although I found the information valuable I am still not able to answer any more of my questions as a result of their review.

               

            I did find out about SFlash which would seem to answer my question #6.

               

            Also, it appears that project #13: GATT Client and Server could help but my Pioneer Kit is not coming in till later this week and it is always easier to understand example code when one can actually run it, so I may have to wait until then to get more answers.

               

            I do not think there is a specific example in that series that addresses my scenario and if anyone can further help out, please do.

               

            Dale
             

            • 4. Re: BLE basics
              user_242978793

              Have you watched the PSOC BLE videos here http://www.cypress.com/video-library/PSoC. The head program engineer Alan Hawse   explains the client and Server and GAP. He also gives his email address for questions. here is one of the videos http://www.cypress.com/video-library/PSoC/psoc-4-ble-101-3-finishing-find-me-application-firmware/108401?tid=84506&sort_by=created

              • 5. Re: BLE basics
                dale.kramer

                Yes, I believe he made a comment in the relevant video that having a device change roles was complex and beyond including in his videos.

                   

                I will email him this thread if it stalls.

                   

                He also commented that one should not have to learn the internal intricacies of combustion engine design if one is learning to drive and I am hoping to achieve that with BLE (although I am pretty good at ICE's :).

                   

                Thanks,

                   

                Dale

                • 6. Re: BLE basics
                  rohit.kumar

                  Let me try to answer your questions:

                     

                  1. Would I select Client and Server as the Profile Role?

                     

                  ROIT: If you are talking to iPhone, better to support a Server role in your widget. Anyways, as per your widget definition, the data is stored on your widget, which is what a Server does. Client (iPhone) would ask you for the data.

                     

                  2. Would I select Peripheral and Central in the GAP Role?

                     

                  ROIT: Peripheral role for GAP role. There are two reasons for it:

                     

                  a) You want to advertise your presence (which peripheral role does) rather than scan for desired device (which a Central device may do), as advertising is a much much less power consuming process than scanning. Also, you have full freedom to choose the advertising interval that suits your power requirement and latency in connection (though note that iOS has certain restrictions on the interval that a device can set).

                     

                  b) The widget role is more of a slave as Central device would connect to it whenever it desires to.

                     

                  3. What services would I need in the Client and Server?

                     

                  ROIT: Considering my opinion in point one above, you would need services in Server side. As the functionalities you want to achieve in your widget are not standard applications defined by BLE SIG, you will need to support Custom Services and Characteristics. The number of these services/characteristics, their definition , the data type they support (uint8, uint16, array, etc) and properties (read/write/notification, etc) are all which you need to decide, depending on how you want to implement.

                     

                  For example, if I would be doing something like this, I will support a single custom service, say WIDGET_DATA_SER. Under this, I would have two characteristic, the first one being WIDGET_CONFIG that supports Read and Write of 10 bytes of data. Using this, I can read the existing variable values and also send back a new set of values.

                     

                  The second characteristic would be DATA_SET_CONFIRM, which would support 1byte data transfer and support Notification. Using notification, the Client (iPhone) does not need to continuously read the data. The Server (your widget) can send the data (write confirmation) whenever it wants to.

                     

                  Do note that BLE defines a response to the Write request sent to Server. That means, when you write the 10 bytes of data using the first characteristic, you will also receive a response back. In this case, you may not even need the second characteristic.

                     

                  4. How would I set up the characteristics to send and receive this data?

                     

                  ROIT: See my comments in point 3 above

                     

                  5. How would I set up the code on my widget to listen for requests/data from the the iPhone using the least energy? (perhaps I could have the iPhone try sending for 5 seconds and the widget only look for requests from iPhone every 4 seconds or something like that)

                     

                  ROIT: As part of point 3, 4 above as well as this, I would recommend you going through the application note AN91162 at following link. You will get most of your answers there:

                     

                  http://www.cypress.com/documentation/application-notes/an91162-creating-ble-custom-profile?source=search&keywords=AN91162 

                     

                  6. A non-BLE question, how would I make these configuration variables persistent on my widget when the battery is removed or my program code reloaded.  On my PIC widget, which does not have EEPROM, I reserve some program memory that my linker and programmer does not erase and I write these variables to that program memory area?

                     

                  ROIT: I guess you already got the answer for this from the SFLASH project in 100 days repository.

                     

                  7. Is there any sample code project that could help me?

                     

                  ROIT: I guess the AN91162 referred above will help you in designing the project easily. Your project is too specific and I feel such a ready project may not be available. I would suggest you giving it a try yourself, and if you still need help, raise a technical case at www.cypress.com -> 'Design Support' -> Under 'Support', 'Create a Support Case'. 

                     

                  Hope this helps.

                  • 7. Re: BLE basics
                    dale.kramer

                    Wow, now that is a response!!

                       

                    I had a feeling I might see something like that.

                       

                    As a growing convert from PIC I have had a growing feeling since the start of this journey that I have been moving from the 20th century into the 21st.  I hope it continues.

                       

                    In the last couple of days I have been playing 'car mechanic' and had learned a few of my answers but now I have them all and can get back to my 'driving lesson' :)

                       

                    For those that follow with a similar need, I will try to post a sample project that achieves my posted goals (probably after I have a few more lessons :)

                       

                    Can't wait to get my BLE Pioneer Kit and start debugging. I haven't found mention of a simulator yet, is there a way to run/debug basic code without a device hooked up? 

                       

                    Thanks roit!

                       

                    Dale

                    • 8. Re: BLE basics
                      dale.kramer

                      roit,

                         

                      One thing jumps out at me when I re-read your response.

                         

                      I don't understand that you say for the initial connection that advertising from the widget 'is a much much less power consuming process than scanning'.

                         

                      This is counter intuitive for me as listening for rf signals would seem to me to take less power than transmitting would.

                      • 9. Re: BLE basics
                        user_14586677

                        There is an ap note here on power that may be of use.

                           

                         

                           

                        http://www.cypress.com/?id=5509 100 Projects in 100 Days with Bluetooth

                           

                        http://www.cypress.com/?rID=102799&source=psoc4ble     FAQs

                           

                        http://www.cypress.com/?rID=102512     AN91445 - Antenna Design Guide

                           

                        http://www.cypress.com/?rID=102505     AN94020 - Getting Started with PRoC™ BLE

                           

                        http://www.cypress.com/?rID=110007     AN92584 - Designing for Low Power and Estimating Battery Life for BLE Applications

                           

                        http://www.cypress.com/?rID=109900     AN91162 - Creating a BLE Custom Profile

                           

                        http://www.cypress.com/?rID=110107     AN91184 - PSoC 4 BLE - Designing BLE Applications

                           

                        http://www.cypress.com/?rID=102504     AN91267 - Getting Started with PSoC® 4 BLE

                           

                        https://github.com/googlesamples/android-BluetoothLeGatt

                           

                         

                           

                        Regards, Dana.

                        • 10. Re: BLE basics
                          rohit.kumar

                          @KCI

                             

                          For simulator, I would suggest you to use the CySmart PC Tool+BLE Dongle to test and develop your project. This PC Tool (http://www.cypress.com/documentation/software-and-drivers/cysmart-bluetooth-le-test-and-debug-tool?source=search&keywords=cysmart ) runs on windows, along with the BLE Dongle (the black USB Stick that you got as part of your BLE Pioneer kit), and helps you to test a Server+Peripheral project easily.

                             

                          As for your question on Advertisement vs Scanning, Scanning is a continuous RX process, so your average current consumption will always be around that value (which is in mA).

                             

                          But with Advertisement, you can decide at what rate your TX should take place. This could range from 7.5 ms to 4 seconds. And in between those events, you can put the system to low power modes. In this case, the average power consumption is too less. For example, you will observe a avg current consumption of 18 us when advertising at 1 second interval.

                          • 11. Re: BLE basics
                            dale.kramer

                            Thanks Dana,

                               

                            I have been using AN92584 during this, my initial design process.  I do not want to be limited by my PIC widget experience and want to take advantage of all low power tricks here.

                               

                            In that vein it may be possible to expand on what I might expect to achieve with my widget functionality.

                               

                            I had no idea that I could be connected and sending a few bytes of data to the iPhone every 50ms using only 313ua. WOW!

                               

                            This opens new doors to my design in that I can offload some chores to the iPhone if it is nearby!

                               

                            It looks like my connection strategies will be revisited and my initial BLE configuration of post #1 will be obsolete.

                            • 12. Re: BLE basics
                              dale.kramer

                              roit,

                                 

                              Couldn't you scan for only a short period every few seconds in the same way that you can advertise, my point is that the listening process itself should take less power than transmitting.

                                 

                              The BLE 2.10 document describes the parameters scanIntv and scanWindow (each can be from 2.5 ms to 10.24 sec) but I can't seem to find any power usage information for these variables like you publish for advertising and connection modes.

                              • 13. Re: BLE basics
                                user_14586677

                                If you scan and advertise at very low rates, this being async activity, one can imagine a very

                                   

                                high latency rate in the design, a tradeoff you have to make.

                                   

                                 

                                   

                                Basically one would have to use Nyquist to make sure a scan was successful acquiring a

                                   

                                low rate advertisement schedule.

                                   

                                 

                                   

                                Am I right about this Roit ?

                                   

                                 

                                   

                                Regards, Dana.,

                                • 14. Re: BLE basics
                                  dale.kramer

                                  As far as advertising goes, as roit said, IOS has some limitations.

                                     

                                  Looks like 1296ms would be my longest recommended schedule.

                                     

                                  http://stackoverflow.com/questions/14091968/corebluetooth-advertising-detection-time

                                  1 2 Previous Next