wiced_sense posture guard app

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hello everybody

I am using wiced_sense for my capstone project to make a posture guard device.

I shared my wiced_sense.c code. Please checked it and see how I modified the firmware code for my project. I add comments to my extra codes.

The app is working fine now.

The user button( which is second button on wiced_sense) is calibration button.

So when you pressed that button . Calibrationdata saves the acceloremetre's  X,Y and Z values. After that its checking the calibration data and the instantaneous data

when there is a diffrence between these values which means that when you changed your posture. The buzzer is playing for user to turn back the true posture.

The project is working fine now . But it works only when you connected to wiced sense with your phone.Without connecting to phone its not working.

I have been trying to solve the problem by my self . Get a help 1 week before from the manegers but still cant fix it.

Could anyone checked the code I shared and show me the way that how can I fix this problem.

Thank you very much .

Regards...

0 Likes
8 Replies
Anonymous
Not applicable

hello raseyns ,

did you tired - commenting this line

wiced_sense_power_down_sensors(); in connection_down and check111.PNG

0 Likes
Anonymous
Not applicable

rsiddhanth

Yes I allready tried it. But didnt work.

The important part of the code here :

#if WICED_SENSE_SUPPORT_ACCEL

/// Get the instantaneous accelerometer data.;

status_t wiced_sense_get_accelerometer_instantaneous_data(AxesRaw_t* dataA)

{

  axesCalData = &axesData;

  if (!ButtonPressed) return MEMS_ERROR;

  if(GetAccAxesRaw(dataA) == MEMS_SUCCESS)

  {

  // if( ( ( axesCalData->AXIS_X - dataA->AXIS_X ) > 20 ) || ( ( axesCalData->AXIS_X - dataA->AXIS_X ) < -20 ) ||

  // ( ( axesCalData->AXIS_Y - dataA->AXIS_Y ) > 20 ) || ( ( axesCalData->AXIS_Y - dataA->AXIS_Y ) < -20 ) ||

  if( ( ( axesCalData->AXIS_Z - dataA->AXIS_Z ) > 10 ) || ( ( axesCalData->AXIS_Z - dataA->AXIS_Z ) < -10 ) )

  {

  highCounter++ ;

  if( highCounter >= 35 )

  {

  wiced_sense_short_beep_buzzer(80);

  }

  }

  else

  {

  highCounter = 0;

  }

  return MEMS_SUCCESS;

  }  //Get AccAcexRaw

  return MEMS_ERROR;

}

#endif

only works when I connected to my phone.

My guess is :

in the connection_up(); function

wiced_sense_connection_handle = (UINT16)emconinfo_getConnHandle();           the problem is in this line .Because when you dont connected it. The code is stucked in this line I dont sure that I am wrong or write. just a guess.

0 Likes
Anonymous
Not applicable

raseyns driver files are perfect. i dont think, it is a problem with GetAccAxesRaw(dataA)

since i used to get raw data (not with accelerometer) from temperature sensor, it worked fine....

it should be logical thing inside the function

may i know why you are doing

highCounter++ ;

if( highCounter >= 35 ){}

in the mean while try to

comment this in main function -  bleprofile_regAppEvtHandler(BLECM_APP_EVT_ADV_TIMEOUT, wiced_sense_advertisement_stopped);

and check

Regards

Sid

0 Likes
Anonymous
Not applicable

@rsiddhanth

with high counter when there is change in the acclerometre and the caldata its just wait 3.5 seconds than it works

so with this fast changes I dont want to make a sound to be clear that user is still in bad posture

0 Likes
Anonymous
Not applicable

rsiddhanth 

I did what you said . But still same

0 Likes
Anonymous
Not applicable

Hello.

You are getting this behavior, because your function wiced_sense_get_accelerometer_instantaneous_data is called inside wiced_sense_poll_agm_and_fill_notification_packet which is in turn called inside wiced_sense_tx_opportunity_notice function, which is a callback that is invoked in every connection intervals before sending notifications. (please refer to lines 747 to 754)

The notifications and therefore the callback function in which you are polling your sensor are only called when you are connected.

That is why you can't use the accelerometer when you are not connected.

In order to avoid this and actually poll your sensor when not connected, please call wiced_sense_get_accelerometer_instantaneous_data function in either of the timer callbacks depending on how frequently you want to get data from sensor. There are regular timer(1s) and fine timer(minimum 12.5 ms). The timer callback functions(wiced_sense_fine_timeout, wiced_ense_timeout) are already registered, so all you need to do is really call your function, wiced_sense_get_accelerometer_instantaneous_data.

// One second timer expired. Read the sensor data.

void wiced_sense_timeout(UINT32 arg)

{

     BLEPROFILE_DB_PDU pdu;

     AxesRaw_t* axes_ptr = (AxesRaw_t*) pdu.pdu;

     // Get accelerometer data first

     if(wiced_sense_get_accelerometer_instantaneous_data(axes_ptr) == MEMS_SUCCESS) {

          //ble_trace3("Accelerometer: X=%6d, Y=%6d, Z=%6d", axes_ptr->AXIS_X, axes_ptr->AXIS_Y, axes_ptr->AXIS_Z);

          header |= WICED_SENSE_NOTIFICATION_HEADER_INCLUDES_ACCELEROMETER;

          axes_ptr++;

          *size += sizeof(AxesRaw_t);  

     } else {

          ble_trace0("Reading Accelerometer failed."); 

     }

     // After the call, the data will be in pdu.pdu.

     // I only used wiced_sense_timeout, because it was empty.

     // you can use wiced_sense_fine_timeout if you want

}

*footnote: if you are going to make the device connectable too, then you may want a boolean to control the polling in the timer, since you don't want to be polling twice. Also, make sure your sensors are on even when you are not connected.

I hope this helps.

Please let me know if you more problems.

James

Anonymous
Not applicable

jamesle1​  Hello Thank You very much for your help. I ve been trying to solve this problem and your help was so beneficial.

As you said  wiced_sense_get_accelerometer_instantaneous_data  is not called before connection.

I put thesee code inside the wiced_sense_fine_timeout()

Because off undeclaired of header and size it gived an error first but.

I add

UINT8 headerAcc = 0;

UINT8* sizeAcc;

these declarations and change the code like this

  BLEPROFILE_DB_PDU pdu;

      AxesRaw_t* axes_ptr = (AxesRaw_t*) pdu.pdu;

     // Get accelerometer data first

      if(wiced_sense_get_accelerometer_instantaneous_data(axes_ptr) == MEMS_SUCCESS) {

           //ble_trace3("Accelerometer: X=%6d, Y=%6d, Z=%6d", axes_ptr->AXIS_X, axes_ptr->AXIS_Y, axes_ptr->AXIS_Z);

           headerAcc |= WICED_SENSE_NOTIFICATION_HEADER_INCLUDES_ACCELEROMETER;

           axes_ptr++;

           *sizeAcc += sizeof(AxesRaw_t);

As you said its working now. Thanks for that very much. You saved my problems. But as your warning, Now the code is having problem when I connect wiced sense with my phone.You said that using boolean I could handle it.

So Is there a connection make the boolean false so that wiced sense will not use the code inside the  wiced_sense_fine_timeout()

Else When there is no connection wiced sense will use the code inside the wiced_sense_fine_timeout()

Did I get the idea true ?

0 Likes
Anonymous
Not applicable

Yes. That's exactly what I meant.