Access IoT dongle sensor data while in advertising mode

11 posts / 0 new
Last post
jeremynwong
Offline
Last seen:4 years 1 week ago
Joined:2017-01-16 14:09
Access IoT dongle sensor data while in advertising mode

Hi,

I am working with the Dialog IoT development kit. I am trying to detect whether or not the dongle has moved over a certain time interval and place a flag into the advertisement data. What would be the best way of doing this? Is there an interrupt that I can write a handler for each time the dongle moves? If so, how can I set this up? Or is there a function that I can call that will tell me if the dongle has moved or not (which I can reset after each time I read it)

I've tried calling the bmo160_get_any_motion_stat() and bmi160_get_step_counter() functions to try to detect motion but this doesn't seem to work. Is there another function that I can use or is there any other setup required for me to use these functions while in advertising mode?

I am working off the wrbl_sfl project.

谢谢,
杰里米

Device:
MT_dialog
Offline
Last seen:2 months 2 weeks ago
Staff
Joined:2015-06-08 11:34
Hi jeremynwong,

Hi jeremynwong,

The IoT project gets a interrupt of any kind of movement right after the advertising is finished, in the advertising complete callback the user_bmi160_config_anymotion_intr() function sets the accelerometer in that mode, so when the accelerometer senses any kind of motion triggers an interrupt to the 583 and the wkup_intr_non_connected_cb() gets triggered in order for the device to start advertising again, so you could place a flag at that interrupt handler, or since the device every time it gets moved it starts the advertising you can even set a flag that the device is moved in the user_adv_start() function and modify your advertising string accordingly. If you would like to count while you are advertising you can use this configuration in order to be available at all times and trigger an interrupt at any movement.

另请注意,如果不存在,SFL项目中的写入额外代码的空间非常有限,问题是keil的限制,因为它不会通过32k编译额外的代码,所以我建议除非原始项目您希望传感器融合功能。

Thanks MT_dialog

michaelmeng998
Offline
Last seen:4 years 1 month ago
Joined:2017-01-11 07:46
Hi MT_dialog! you mentioned

Hi MT_dialog! you mentioned that the IOT project gets a interrupt of any kind of movement right after the advertising is finished, so if there is motion detected the interrupt handler gets triggered in order for the device to start advertising again. What if we want to have the interrupt to be enabled all the time and not only after the 14583 has gone to sleep? We currently disabled our 14583's sleep mode.

Also, you mentioned we could write a flag in the user_adv_start function. How would we use the anymotion or stepcounter functions available to help us achieve our goal. We have tried writing a flag in the user_app_adv_undirect_complete function using the read_step_counter statement but it's not working at all.

谢谢,

Michael

MT_dialog
Offline
Last seen:2 months 2 weeks ago
Staff
Joined:2015-06-08 11:34
Hi michaelmeng998,

Hi michaelmeng998,

If you would like to have the interrupt enabled all the time then you will have to configure the sensor to provide an interrupt from the time that the device operates and after getting that interrupt you can consider it as a movement, also what you are going to consider as a movement that depends on how you have configured the interrupts on the IMU, the BMI interrupts operate under permanently, temporarily or not latched mode (please check the BMI160 datasheet for more info on this).

关于如何执行此操作,请告知传感器的数据表,该模块IT Self提供了一系列配置和中断,这些配置和中断在某些情况下触发,因此您应该检查什么适合您并启用BMI模块中的相应功能。关于user_adv_start_function中的写作标志,我提到的是,如果您想宣传设备正在移动,因为设备在永久睡眠状态下落下时,设备可以启用中断,并且可以设置a计数器或标志作为设备移动和宣传的指示。

Thanks MT_dialog

michaelmeng998
Offline
Last seen:4 years 1 month ago
Joined:2017-01-11 07:46
Hi MT_dialog:

Hi MT_dialog:

I am still a bit confused. I checked the datasheet.h source file and it has some specific IRQn's like the Wakeup from low power interrupt, receipt interrupt at end of each received packet, and the end of advertising interrupt, but there is no interrupt corresponding to when we first start the device.

同时,bmi160在线数据表,它说其他e is a anymotion interrupt register (INT_MOTION, 0x5F-0x62). I am trying to find out how to enable this interrupt. Also, do we need to write an individual interrupt handler, or can we call one of the pre-written interrupt handlers like the wkup_intr_non_connected_cb?

MT_dialog
Offline
Last seen:2 months 2 weeks ago
Staff
Joined:2015-06-08 11:34
Hi michaelmeng998,

Hi michaelmeng998,

当代码开始在设备上运行时,没有中断,如果您想知道您可以在哪里设置中断以便触发,则可以将其放在.app_on_init回调中,或者您甚至可以将其放置在广告启动时。

The IoT source code enables that interrupt when the device stops advertising, in the user_app_on_adv_undirect_complete, if you check the user_init_bmi_nc() function you will be able to find an example how to set the BMI with the any motion interrupt, more specifically the user_bmi160_config_anymotion_intr() is the function that sets the interrupt to be triggered. You can check that function and apply the configuration that you would like to your project. Regarding the handling of the interrupt, on the IoT this interrupt is connected to the wakeup timer (the interrupt that is available when the device is in sleep), in order to assign an ISR to that interrupt there is the wkupct_register_callback() api that does that, for example in the IoT after the anymotion interrupt and the IMU has been configured the function config_da1458x_pin_intr_non_connected() is invoked, that function registers the wkup_intr_non_connected_cb to the wakeup timer and sets the pin that expects the interrupt via the wkupct_enable_irq() function.

Thanks MT_dialog

michaelmeng998
Offline
Last seen:4 years 1 month ago
Joined:2017-01-11 07:46
Hey MT_dialog. Thanks for the

Hey MT_dialog. Thanks for the response. I still have a few questions. You mentioned that the user_init_bmi_nc() function is the function that sets the BMI with the any motion interrupt? When I checked the user_wrbl.c file, the user_init_bmi_nc() function was called in the user_app_on_adv_undirect_complete function after advertising was finished. So if we wanted to set the interrupt when the advertising starts, would we just move the user_init_bmi_nc() function to the user_adv_start() function?

Also, since I want to access the dongles motion status (whether it moved or not) and then configure our advertising packets to carry whether or not it moved, (we already have the ability to modify the advertised packets size, we just need to access the motion status information properly) where does the motion status get stored after the bmi160 detects motion? Is there a specific queue that holds this information that we can access?

MT_dialog
Offline
Last seen:2 months 2 weeks ago
Staff
Joined:2015-06-08 11:34
Hi michaelmeng998,

Hi michaelmeng998,

不仅user_init_bmi_nc(),这集的有限公司nfiguration only at the sensors end, you will have also to configure the interrupt on the 583's side also in the user_app_on_adv_undirect_complete, there are some additional configurations that the code does for configuring the IMU device, please read and try to understand the code. If you just place the user_init_bmi_nc() it simply wont work.

Regarding your second question you will be able to find the answer and more information in the datasheet of the IMU, nevertheless when the interrupt gets triggered you can see at the wkup_intr_non_connected_cb() that the devices reads some registers (the INT_STATUS_ registers - 0x1C, 0x1D, 0x1E) in order to determine what is the interrupt that got triggered.

Thanks MT_dialog

jeremynwong
Offline
Last seen:4 years 1 week ago
Joined:2017-01-16 14:09
Hi MT_Dialog,

Hi MT_Dialog,

We've set up our interrupt that gets triggered when the dongle moves. This part works. Instead of executing the default operation of user_adv_start, we want to run another similar but different function.

The reason is that we set the user_adv_start function to start advertising with a flag of 0x00 which gets called on program initialization since "not moved" should be our initial state.

However, the interrupt signifies that motion has occurred and we want to start advertising but with a flag of 0x01. We created a separate function called restart_adv and called this from within our interrupt handler as seen below. However, even though this function is getting called (we verified this in the debugger), the dongle restarts advertising with 0x00 even though we are passing in 0x01 as an argument to our start advertising function.

The relevant code is included below.

谢谢,
杰里米

// in user_platform.c
void wkup_intr_non_connected_cb( void ) // this function successfully gets called when the dongle moves
{
restart_adv();
}

// in user_wrbl.c
void user_adv_start( void ) { // this is what is called on program initialization, advertise with 0x00
user_easy_gap_undirected_advertise_start( FAST_ADV_INTERVAL, 0x00);
}

void restart_adv( void ) { // this is what we want to be called from the interrupt handler, should advertise with 0x01
user_easy_gap_undirected_advertise_start( FAST_ADV_INTERVAL, 0x01);
}

//启动广告的功能,我们为我们要宣传的用户数据添加了额外参数
static void user_easy_gap_undirected_advertise_start(uint16_t adv_intv, uint8_t user_data)
{
struct gapm_start_advertise_cmd* cmd;
timer_hnd app_adv_data_update_timer_used = app_easy_timer(1000, adv_data_update_timer_cb);

cmd = app_easy_gap_undirected_advertise_get_active();
cmd->intv_max = adv_intv;
cmd->intv_min = adv_intv;
user_add_adv_info(cmd->info.host.scan_rsp_data, 10 );
user_add_accel_info(cmd->info.host.scan_rsp_data, user_data); // modifies the byte we are using for advertising data

app_easy_gap_undirected_advertise_start();

// We are now connectable
ke_state_set(TASK_APP, APP_CONNECTABLE);
}

uint8_t user_add_accel_info( uint8_t *padv, uint8_t user_data){
padv[7] = user_data;
return 0;
}

jeremynwong
Offline
Last seen:4 years 1 week ago
Joined:2017-01-16 14:09
Hi MT_Dialog,

Hi MT_Dialog,

We figured out what our problem is. Thanks!

杰里米

MT_dialog
Offline
Last seen:2 months 2 weeks ago
Staff
Joined:2015-06-08 11:34
Hi jeremynwong,

Hi jeremynwong,

感谢您的表明,如果您发现它们有用或甚至随意分享您的解决方案,请接受上述任何答案以便其他人在类似的问题中获得帮助。

Thanks MT_dialog