Developer Portal Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    How to get highest sampling rate (500HZ) in BMA280 (or any sensor) in XDK

    mainul
    Member

    How to get highest sampling rate (500HZ) in BMA280 (or any sensor) in XDK

    I  am using SendDataOverMQTT and getting 7-10 reading from accelerometer sensor. I can not find where the sampling rate or bandwidth is fixed. Can anyone help to increase the sampling rate?   

     

     

    6 REPLIES 6
    LlobetAtWork
    Long-established Member

    Re: How to get highest sampling rate (500HZ) in BMA280 (or any sensor) in XDK

    Hi Mainul,

    as noted in a similar thread: https://community.developer.bosch.com/t5/Technical-Support/Questions-on-AwsSendDataOverMQTT/m-p/2050...

    The sampling rate is controlled using a soft-timer which proceeds to sample and publish as set by the APP_MQTT_DATA_PUBLISH_PERIODICITY definition.
    Soft timers can have a resolution up to 1ms in the RTOS configuration used by the XDK (1kHz) .

    Best regards,

    Francisco Llobet

    mainul
    Member

    Re: How to get highest sampling rate (500HZ) in BMA280 (or any sensor) in XDK

    Hi, yes, I already set the APP_MQTT_DATA_PUBLISH_PERIODICITY  to 1 but still getting 7-10 reading on subsciber side. 

    I  am using a local MQTT server (Mosquitto 1.5.7). 

    To test the server speed and subscriber performance I created another publisher (using python and Paho library), and replace that with the XDK publisher, and that got more than 400 readings (also saved at the same time) without any issue. So, the server and subsciber is not a problem. 

    What I am thinking is, in XDK, it is sending data after each reading and during sending may be the sensor reading process is blocked. This might hamper the throughput. So, may be I should collect lets say 100 reading each time (save it in an array) and then send that. 

    Allthough, the test python publisher also doing the same (sending single data point) but that is on my computer with lot higher computation power (than XDK) and also may be sensor reading is bit more time consuming than creating just fake data.

    What do you think? 

    LlobetAtWork
    Long-established Member

    Re: How to get highest sampling rate (500HZ) in BMA280 (or any sensor) in XDK

    Hi Mainul,

    your reasoning is correct! Doing sampling and sending data inside the same thread does not scale well for high performance applications.

    Since sending data has a high set-up time (preparing protocol headers, initiating transmission) I usually prefer to accumulate measurement points into a block transmission. 

    Usually this is realized in an embedded program by having one task reading sensor data and enqueueing it into a stream or ring buffer. Another task can be activated when the stream buffer reaches a certain threshold and will send out the data (see the excellent FreeRTOS documentation and examples for that https://www.freertos.org/Documentation/RTOS_book.html).

    Also MQTT brokers in cloud application are a little bit limited. Some will only accept transactions up to 100 Transactions/s and some brokers might not scale well past 10kTransactions/s, so my advice is to try to bundle sensor points into larger windows or packets.

    Best regards,

    Francisco Llobet

    mainul
    Member

    Re: How to get highest sampling rate (500HZ) in BMA280 (or any sensor) in XDK

    Hi, I am concatenating each reading (accelometer and accustic) in a buffer array and sending them via wifi. Problem is, I am getting 7-8 milisecond (on average) time duration between two consecutive readings (reading and concatenating to the array but not sending it to wifi), even if set the  

     APP_MQTT_DATA_PUBLISH_PERIODICITY=1

    here is my code for saving:

    if (RETCODE_OK == retcode)

    {  if (whileCounter<33){

      tickNumber= xTaskGetTickCount();

     length += snprintf((char *) publishBuffer+length, APP_MQTT_DATA_BUFFER_SIZE, publishDataFormat,

          tickNumber,

       (long int)sensorValue.Accel.X,

      (long int)sensorValue.Accel.Y,

      (long int)sensorValue.Accel.Z,

        sensorValue.Noise);

            whileCounter=whileCounter+1;

        }

        else{

     

        printf("in the else publishBuffer len %d\n",length);

        printf("in the else publishBuffer size %d\n",strlen(publishBuffer));

        whileCounter=0;

        MqttPublishInfo.Payload =  publishBuffer;

       MqttPublishInfo.PayloadLength = length;

       length=0;

        retcode = MQTT_PublishToTopic(&MqttPublishInfo, MQTT_PUBLISH_TIMEOUT_IN_MS);

    if (RETCODE_OK != retcode)

    {

    printf("AppControllerFire : MQTT publish failed \n\r");

    }

     }

    Any idea, Whyhy?

    Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist