This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2541 Observer/Broadcaster role & OAD

Other Parts Discussed in Thread: CC2541, CC2540, BLE-STACK

Hi


I just want to find out if I am using the right profiles.

Device A (SmartPhone) is the Broadcaster and Device B is the Observer.


1.  Device A will send out an advertisement.  Device B will read the advertisement and then turn into a Broadcaster to send the desired sensor information.  So I assume Device A will then need to become an Observer to read the sensor info.


2.  Will it be possible to send information from Device A Broadcaster to the Observer to change the Device B GAP_ADTYPE_LOCAL_NAME for example from SensorTag1 to SensorTag5.  I would like the Smartphone to only target the Sensortag number of my choosing.

3.  Is OAD possible in all profiles or do you have to pair to do an Over the air download?

Thanks.

  • Hi,

    There are four different main types of roles within Bluetooth low energy:

    • Peripheral
      • An advertiser that is connectable
      • Operates as a slave in a connection
      • Example: Heart Rate Sensor
    • Central
      • Scans for advertisements and initiates connections
      • Operates as a master in connections.
      • Example: Smartphone
    • Broadcaster
      • An advertiser that is non-connectable
      • Example: Temperature Sensor
    • Observer
      • Scans for advertisements, but cannot initiate connections
      • Example: Temperature Display

    So you are probably looking for Peripheral/Central role where you connect and achieve the two-way communication, am I right? You need to be connection to do OAD. Note that Profiles only applies to connected devices (Not Broadcasters/Observers).

    Best Regards

    Joakim

  • Thanks Joakim.


    The project doesn't allow for any connections, but will have to make an exception for the OAD somehow.

    The device must only listen for advertisements (Observer) and only respond when a particular advertisement is received for instance a matching device name. eg Frontdoortag.


    Then it must respond with a few sensor readings (Broadcaster).  Because no physical connection is allowed that is why I am thinking of switching between Observer and Broadcaster mode.

    Regards

    Francois

  • Hi Joakim

    I've successfully gotten the dual Observer/Broadcaster roles working together.  For the OAD I obviously need to

    implement a Peripheral or Central role into my application.   Will the stack actually allow this to be done as

    I've seen you can only call GAP_DeviceInit once to start the dual mode, but I don't see any options for a tri-mode.

    Is there maybe a way of cancelling a profile and re-initialising a different profile in other words cancelling dual Observer/Broadcast and then starting the Peripheral or Central role.

    Regards

  • Hi François,

    I'm trying to implement the observer/broadcaster mode to my cc2541 by several ways but it hasn't worked so far. Could you help me by giving me the main steps please? Thank you in advance for your help!

  • Hi Boris


    It's extremely tricky to get right, as I had to start over a couple of times. 


    What I did in essence is I took  a project as my base and then merged the SimpleBroadcaster with it.  I will add all the details of how I did it over the weekend, as it's quite a long process.

    The first thing you need to get right is your library files. You need to change your .lib files in your project to:

    CC2540_BLE_peri_observ.lib                  Peripheral/Observer

    CC254x_BLE_HCI_TL_peri_observ.lib     Peripheral/Observer

    On the .cfg file in your project Buildcomponents.cfg stays the same but

    buildConfig.cfg will look like this

    // BLE Host Build Configurations

    //-DHOST_CONFIG=BROADCASTER_CFG
    //-DHOST_CONFIG=OBSERVER_CFG
    //-DHOST_CONFIG=PERIPHERAL_CFG
    //-DHOST_CONFIG=CENTRAL_CFG
    //-DHOST_CONFIG=BROADCASTER_CFG+OBSERVER_CFG
    -DHOST_CONFIG=PERIPHERAL_CFG+OBSERVER_CFG
    //-DHOST_CONFIG=CENTRAL_CFG+BROADCASTER_CFG
    //-DHOST_CONFIG=PERIPHERAL_CFG+CENTRAL_CFG

    // GATT Database being off chip
    //-DGATT_DB_OFF_CHIP

    // GAP Privacy Feature
    //-DGAP_PRIVACY
    -DGAP_PRIVACY_RECONNECT

    // Include GAP Bond Manager
    //-DGAP_BOND_MGR

    which will tell your system to start up in dual mode.  I will look through my code and compile a tutorial as best as I can.  I can't send the project directly as it's company property.  The first step you can do for me is select which project from TI you want as the base for example, sensortag, keyfob etc.   I would advise against using simpleobserver and simplebroadcaster as the base because the osal timers don't work properly in those projects.  Maybe it's just me.  Let me know what project you are using as base. 

  • Hi François,

    Thank you for your quick answer. I'm using the Sensortag as base project.

  • OK, so a discussed the first steps are:

    1.  Replace the .lib files

    CC2541_BLE_peri_observ.lib             

    Leave this lib file the same for now CC254x_BLE_HCI_TL_None.lib  otherwise you will get errors

    2. Change buildConfig.cfg

    //-DHOST_CONFIG=PERIPHERAL_CFG  (Comment this line out)
    -DHOST_CONFIG=PERIPHERAL_CFG+OBSERVER_CFG

    Compile and see that you get 0 errors

    Your sensortag's default code will make it an peripheral which you can use to advertise, so the next step is to add you observer/Rx functionality

    3.  Open SimpleBLEObserver in a separate window so that you can copy paste from it, into Sensortag.

    4.  Now comes the hard part, if you look at the app folder of sensortag and simplebleobserver you will see they each
     contain 4 project files.

    Sensortag_main and simpleblemain you don't have to merge as they are almost identical so you can ignore these 2 files.

    5.  Open Osal_Sensortag and Osal_SimpleBle in two different IAR windows  You will see Osal_sensortag has a few more tasks than osal_simplebleobserver, this is fine. if you look at the task functions between the 2 projects you will see they are the same i.e LL_Init, Hal_Init, HCI_Init, upto SM_Init.

    Go to GapRole_Init function in Sensortag project and GAPObserverRole_Init in simpleble.  You will see that in the simpleble function you have the line GAP_RegisterForHCIMsgs( taskId );  this already exist in the sensortag function so you don't need to do anything.    GAPBondMgr_Init and  GATTServApp_Init you don't need to do anything with as they don't exist in simpleble, so leave them as is.

    6.  Open the Sensortag_init and SimpleBLEObserver_Init funtion in 2 separate windows.  Copy this part to your sensortag_init  Just copy it beneath sensorTag_TaskID = task_id;

      /**************************OBSERVER PROFILE****************************/
      // Setup Observer Profile
      {
        uint8 scanRes = DEFAULT_MAX_SCAN_RES;
        GAPRole_SetParameter ( GAPOBSERVERROLE_MAX_SCAN_RES, sizeof( uint8 ), &scanRes );
      }
     
      // Setup GAP
      GAP_SetParamValue( TGAP_GEN_DISC_SCAN, DEFAULT_SCAN_DURATION );
      GAP_SetParamValue( TGAP_LIM_DISC_SCAN, DEFAULT_SCAN_DURATION );
     
      /******************************************************************************/

    Compile this and you will get errors for missing defines resolve this by coping this to your sensortag.c file

    /***********************OBSERVER CONSTANTS***************************/
    // Maximum number of scan responses
    #define DEFAULT_MAX_SCAN_RES                  8

    // Scan duration in ms
    #define DEFAULT_SCAN_DURATION                 1000

    // Discovey mode (limited, general, all)
    #define DEFAULT_DISCOVERY_MODE                DEVDISC_MODE_ALL

    // TRUE to use active scan
    #define DEFAULT_DISCOVERY_ACTIVE_SCAN         FALSE

    // TRUE to use white list during discovery
    #define DEFAULT_DISCOVERY_WHITE_LIST          FALSE

    #define GAPOBSERVERROLE_MAX_SCAN_RES   0x401  //!< Maximum number of discover scan results to receive. Default is 0 = unlimited.

    /***********************************************************************/

    Compile this and you should not get any errors.  Let me know if you succeed then we will continue.

  • Hi Francois,

    Thank you again for this well-detailed tutorial, I suceeded in compiling everything without any errors. I would like to know how to switch to the observer role cause when I press the side button I'm in advertising mode only. 

  • There is still a couple of things you need to add.


    1.  Under Profile Callbacks (The callbacks are grouped together) in sensortag.c you have to add

    // GAP Observer Role Callbacks
    static gapObserverRoleCB_t simpleBLERoleCB =
    {
     NULL,                     // RSSI callback
      simpleBLEObserverEventCB  // Event callback
    };

    This will generate an error when you compile.  You will have to build in the following functions into your sensortag.c

    static void simpleBLEObserverEventCB( gapObserverRoleEvent_t *pEvent )

    static void simpleBLEAddDeviceInfo( uint8 *pAddr, uint8 addrType ) 


    you can get these functions from Simplebleobserver.  When you build it in it will generate about 20 errors.  You can resolve these errors by coping the needed defines from simplebleobserver.  You will have to copy a portion of observer.h to also resolve these errors.  You don't need observer.c.  Building in this functions is a good way to learn about the BLE-stack as they call it.


    Once you have this working without any errors you have to change the following line in the code to make sure it starts up in dual mode. 

    Goto VOID GAPRole_StartDevice( &sensorTag_PeripheralCBs ) under this function you will find gapRole_SetupGAP.

    Under this function change   VOID GAP_DeviceInit( gapRole_TaskID,
              gapRole_profileRole, 0,
              gapRole_IRK, gapRole_SRK,
              &gapRole_signCounter );    to this

      VOID GAP_DeviceInit( gapRole_TaskID,
              GAP_PROFILE_PERIPHERAL | GAP_PROFILE_OBSERVER, gapObserverRoleMaxScanRes,
              gapRole_IRK, gapRole_SRK,
              &gapRole_signCounter );

    Once this is all done you can finally start a observer event.  You do this by calling these lines of code.  You can add it to a button.

      if ( !simpleBLEScanning )
        {
          simpleBLEScanning = TRUE;
          simpleBLEScanRes = 0;
          
          GAPObserverRole_StartDiscovery( DEFAULT_DISCOVERY_MODE,
                                          DEFAULT_DISCOVERY_ACTIVE_SCAN,
                                          DEFAULT_DISCOVERY_WHITE_LIST ); 

    This code is linked to a button in SimpleBleobserver so it might be a good idea to play around with the project.

    When it receives a bluetooth transmission it will triigger an event at     case GAP_DEVICE_INFO_EVENT:
          {
            simpleBLEAddDeviceInfo( pEvent->deviceInfo.addr, pEvent->deviceInfo.addrType );

    in the static void simpleBLEObserverEventCB( gapObserverRoleEvent_t *pEvent )  function.

    Let me know once you resolve the errors then I can help to process the incoming data for you.   I will try and assist you

    if you get stuck on an error  as I can't publish my entire project.

    Regards

  • Hi Francois,


    I got stuck on 3  warnings before replacing this step:

    . -

    Goto VOID GAPRole_StartDevice( &sensorTag_PeripheralCBs ) under this function you will find gapRole_SetupGAP.

    Under this function change   VOID GAP_DeviceInit( gapRole_TaskID,
              gapRole_profileRole, 0,
              gapRole_IRK, gapRole_SRK,
              &gapRole_signCounter );    to this

      VOID GAP_DeviceInit( gapRole_TaskID,
              GAP_PROFILE_PERIPHERAL | GAP_PROFILE_OBSERVER, gapObserverRoleMaxScanRes,
              gapRole_IRK, gapRole_SRK,
              &gapRole_signCounter );

    Here are the 3 warnings:

    ------ Warning[Pe550]: variable "simpleBLEScanIdx" was set but never used C:\Texas Instruments\BLE-CC254x-1.4.0\Projects\ble\SensorTag\Source\SensorTag.c 310

    Warning[Pe550]: variable "simpleBLEScanning" was set but never used C:\Texas Instruments\BLE-CC254x-1.4.0\Projects\ble\SensorTag\Source\SensorTag.c 316

    Warning[Pe177]: variable "simpleBLERoleCB" was declared but never referenced C:\Texas Instruments\BLE-CC254x-1.4.0\Projects\ble\SensorTag\Source\SensorTag.c 444


    Some more questions:


    1°) As simpleBLEScanning and simpleBLEScanIdx are mostly used in the   simpleBLEObserver_HandleKeys function. Do I have to add it?

    2°) When you replace the profiles within the GAP_Deviceinit() function, do you only initialize the new variable "gapObserverRoleMaxScanRes" to 0?

    3°) I didn't understand  how you can add the observer mode to a button

     

    Thanks in advance for your help.

  • The first warning you can ignore as you in your case you will not be needing it,  you can probably do remove this code in sensortag.c.  You have to adjust the project according to your needs.

       if ( simpleBLEScanRes > 0 )
            {
             // LCD_WRITE_STRING( "<- To Select", HAL_LCD_LINE_2 );
            }

            // initialize scan index to last device
            simpleBLEScanIdx = simpleBLEScanRes;
          }

    The second warning should disappear once you call these lines of code

        // Turn on Observing
       if ( !simpleBLEScanning )
        {
          simpleBLEScanning = TRUE;
          simpleBLEScanRes = 0;
          
          GAPObserverRole_StartDiscovery( DEFAULT_DISCOVERY_MODE,
                                          DEFAULT_DISCOVERY_ACTIVE_SCAN,
                                          DEFAULT_DISCOVERY_WHITE_LIST );    
        }

    All that warning is telling you is that you never used the simpleBleScanning = false you defined.  It's asking you why did you make it false if you are no doing anything with it.

    The third warning you can resolve by add this underneath  VOID GAPRole_StartDevice( &sensorTag_PeripheralCBs );

    VOID Observ_RegisterAppCBs ( &simpleBLERoleCB ); 

    Just resolve the errors you get after adding it.

    Your other questions;

    1.  Yes for now add simpleBLEScanning but you don't need simpleBLEScanIdx

    2.  Yes initialize to 0

    3.  The obsermode is turned on and off just like advertising.  You can't run oberserver and peripheral at the

    same time as the radio is half duplex.

     

    So you will have to cancel advertising if you are waiting for data to come back and enable observing.

  • Hi Francois,

    thank you for this useful tutorial. 

    I am new to this. I have a doubt.

    Should we define Observ_RegisterAppCBs() function in observer.c??

    Because this is giving me the error:

    Error[e46]: Undefined external "Observ_RegisterAppCBs::?relay" referred in SensorTag ( C:\Texas Instruments\BLE-CC254x-1.4.0\Projects\ble\SensorTag\ CC2541DB\CC2541DK-Sensor\Obj\SensorTag.r51 )

    and what exactly we are doing using this callback?

    Thank you

     

  • My observer.c is completely empty of code.

    I have the following for that function

    I am using keyfob but it should be the same.

    Under (events &START_DEVICE_EVT) {  which should be in your sensortag.c

    ............................

    // Start the Observer Profile
        VOID Observ_RegisterAppCBs ( &simpleBLERoleCB );

    .....................

    In observer.h I have this:

    extern bStatus_t Observ_RegisterAppCBs( gapObserverRoleCB_t *appCallbacks);

    In peripheral.c I have this:

    bStatus_t Observ_RegisterAppCBs( gapObserverRoleCB_t *appCallbacks )
    {
      if ( appCallbacks )
      {
        Observ_AppCBs = appCallbacks;
        
        return ( SUCCESS );
      }
      else
      {
        return ( bleAlreadyInRequestedMode );
      }

    }

    That's more or less what I have for that.  Your code doesn't have to look exactly the same you should be able to still use observer.c for the function.  I haven't investigated what the callback does.  Just got it working and went on to other project.  You can try leaving it out and see if it works.

  • Thank you Francois :)

    Now I am able to remove all the errors.

    Could you please help me to test the observer role.

    how you are reading and storing the advertising packet being in observer mode.

     

    Thanks for your help.

    regards,

    snehal

  • HI Snehal

    Do you have a BT4 enabled phone?  I have a app that someone has written that sends out bluetooth packets.  Try looking for an iOS/Android that turns your phone into an iBeacon.  After you have this organised,  I will help you further.  Let me know.  Or alternatively if you have another bluetooth tag that you set up for just advertising.


    Francois

  • HI Francois,

    I have i-pad. I am using an app to make it virtual iBeacon.

  • HI Francois,

    I have i-pad. I am using an app to make it virtual iBeacon. could you please help for further steps.

    Regards,

    Snehal

  • Hi Snehal

    I will only be able to help next week again.  Maybe see if you can find anything helpful on the forum so long.

    To handle the incoming data here is a useful link: http://e2e.ti.com/support/wireless_connectivity/f/538/p/334349/1166529.aspx#1166529

    Regards

  • Thank you Francois.

    Will refer this.