2 Replies Latest reply on Jun 28, 2016 10:18 PM by userc_2727

    AWS & BLE with 3.5.2

      I try the aws shadow example in 3.5.2 and it worked fine .Now I want to add BLE function to the example.Here is my code:

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

      *               Function Definitions

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

      void application_start( void )

      {

        wiced_result_t   ret = WICED_SUCCESS;

        int              connection_retries = 0;

       

       

        wiced_init( );

       

       

        ret = aws_app_init(&app_info);

       

       

        wiced_JSON_parser_register_callback(parse_json_shadow_status);

       

       

        wiced_gpio_input_irq_enable( SETUP_BUTTON, IRQ_TRIGGER_RISING_EDGE, setpoint_control_keypad_handler, NULL );

        wiced_gpio_init(USER_LED, OUTPUT_PUSH_PULL);

       

       

        do

        {

        ret = aws_mqtt_conn_open( app_info.mqtt_object, mqtt_connection_event_cb );

        connection_retries++ ;

        } while ( ( ret != WICED_SUCCESS ) && ( connection_retries < WICED_MQTT_CONNECTION_NUMBER_OF_RETRIES ) );

       

       

        aws_mqtt_app_publish( app_info.mqtt_object, WICED_MQTT_QOS_DELIVER_AT_LEAST_ONCE, (uint8_t*)app_info.shadow_state_topic, (uint8_t*)SHADOW_INIT ,sizeof(SHADOW_INIT) );

       

       

        wiced_rtos_delay_milliseconds( MQTT_DELAY_IN_MILLISECONDS * 2 );

       

       

        aws_mqtt_app_subscribe( app_info.mqtt_object, app_info.shadow_delta_topic , WICED_MQTT_QOS_DELIVER_AT_LEAST_ONCE );

      /* Initialize Bluetooth controller and host stack */

      wiced_bt_stack_init( ble_scan_management_callback, &wiced_bt_cfg_settings, wiced_bt_cfg_buf_pools );

      while ( 1 )

          {

              /* Wait forever on wake semaphore until the wake button is pressed */

              wiced_rtos_get_semaphore( &app_info.wake_semaphore, WICED_NEVER_TIMEOUT );

       

       

              /* Toggle the LED */

              if ( strcasecmp( led_status, "ON" ) == 0 )

              {

                  wiced_gpio_output_low( USER_LED );

                  led_status = "OFF";

                  strcpy(req_led_status, led_status);

                  aws_mqtt_app_publish( app_info.mqtt_object, WICED_MQTT_QOS_DELIVER_AT_LEAST_ONCE, (uint8_t*)app_info.shadow_state_topic, (uint8_t*)SHADOW_PUBLISH_MESSAGE_STR_OFF_DESIRED_AND_REPORTED ,sizeof(SHADOW_PUBLISH_MESSAGE_STR_OFF_DESIRED_AND_REPORTED) );

              }

              else

              {

                  wiced_gpio_output_high( USER_LED );

                  led_status = "ON";

                  strcpy(req_led_status, led_status);

                  aws_mqtt_app_publish( app_info.mqtt_object, WICED_MQTT_QOS_DELIVER_AT_LEAST_ONCE, (uint8_t*)app_info.shadow_state_topic, (uint8_t*)SHADOW_PUBLISH_MESSAGE_STR_ON_DESIRED_AND_REPORTED ,sizeof(SHADOW_PUBLISH_MESSAGE_STR_ON_DESIRED_AND_REPORTED) );

              }

          }

      }

       

      After I set the cer/ private key/router config,I set the BLE as central too scan some peripheral device.But got error .Here is the information it print

      [MQTT] Connecting to broker 52.77.134.96 ...

       

       

      Thing Name:....

      Shadow State Topic: $aws/thing...

      Shadow Delta Topic: $aws/thing...

      Reading the certificate and private key from DCT...

      [MQTT] Connecting to MQTT Broker...

      [MQTT] Successfully connected MQTT Broker

      Publish SUCCEEDED for topic...

      Subscribe SUCCEEDED for topic...

      00020784 GKI_create_task func=0x803ddb9  id=1  name=BTU  stack=0x0  stackSize=6144

       

       

      00020792 GKI_create_task func=0x8044465  id=0  name=HCISU  stack=0x0  stackSize=4096

       

       

      00020800 GKI_create_task thread_id failed(8), HCISU!

       

       

      00060905 GKI_exception(): Task State Table

       

       

      00060909 GKI_exception 65524 getbuf: out of buffers

       

       

      00064905 GKI_exception(): Task State Table

      Who can tell me the reason?Thanks

        • 1. Re: AWS & BLE with 3.5.2

          Hi.

           

          Did you check to make sure you have enough buffers allocated for BLE?

           

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

          * wiced_bt_stack buffer pool configuration

          *

          * Configure buffer pools used by the stack

          *

          * Pools must be ordered in increasing buf_size.

          * If a pool runs out of buffers, the next  pool will be used

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

          const wiced_bt_cfg_buf_pool_t wiced_bt_cfg_buf_pools[WICED_BT_CFG_NUM_BUF_POOLS] =

          {

          /*  { buf_size, buf_count } */

              { 64,       4   },      /* Small Buffer Pool */

              { 360,      4   },      /* Medium Buffer Pool (used for HCI & RFCOMM control messages, min recommended size is 360) */

              { 360,      12  },      /* Large Buffer Pool  (used for HCI ACL messages) */

              { 360,      0   },      /* Extra Large Buffer Pool - Used for avdt media packets and miscellaneous (if not needed, set buf_count to 0) */

          };

           

          Also make sure you instantiate the BLE Stack first. Then you can try to bring up WiFi in STA mode. If that works fine, try MQTT. Please repurpose the ble_proximity_reporter as is. What I see in your code is just a wiced_bt_stack_init() ...

           

          Also remember that the MQTT protocol needs a context of its own. You cannot expect a while(1) loop to share context with BLE. Have a network priority worker thread give context to MQTT (and not the main application).

           

          Hope that helps!

           

          Regards,

          Manish

          1 of 1 people found this helpful
          • 2. Re: AWS & BLE with 3.5.2

            mkochhal wrote:

             

            Hi.

             

            Did you check to make sure you have enough buffers allocated for BLE?

             

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

            * wiced_bt_stack buffer pool configuration

            *

            * Configure buffer pools used by the stack

            *

            * Pools must be ordered in increasing buf_size.

            * If a pool runs out of buffers, the next  pool will be used

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

            So how to calculate the number of required buf_count in various use cases?

            I don't find any documentation about this and no response from the

            forum about this question.

             

            The above comment says "If a pool runs out of buffers, the next  pool will be used",

            this makes developers hard to set exactly the required buffer count.

            Usually, users just set a larger buf_count but the side effect is wasting memory.