NordicPlayground / nRF51-ble-bcast-mesh

Other
323 stars 121 forks source link

Adding rbc_mesh to ble_app_gls example. #57

Closed rifatmahmud closed 8 years ago

rifatmahmud commented 8 years ago

I have copied the rbc_mesh folder on the top folder, given the reference on makefile. Then, I followed your direction in the main.c on adding the rbc_mesh. But when I run the make command, this error message is shown. How to resolve this issue?

trond-snekvik commented 8 years ago

Okay, quick checklist before we proceed to make sure you didn't forget anything:

rifatmahmud commented 8 years ago

Thanks. Adding the mesh_packet.c in Makefile fixed the issue. But after compiling, I cannot find the mesh from my mobile's nRF Master Control Panel app.

I copied the ble_app_gls as ble_app_custom and changed the source to add a custom service of mine and removing battery and gls service, only utilizing the pairing functionality of the app.

Here is the main.c. Listed the rbc_mesh adding related modification below. Note that, the mesh_start is the conditional variable for starting the mesh service.

  1. On line 168, added the rbc_mesh_event_handler function.
  2. On line 678 added the mesh to evt_dispatch.
  3. On line 698 added mesh_sys_evt.
  4. On line 1005 started rbc_mesh in main function.

Here is the modified nrf_adv_conn.c. Modifications are-

  1. On line 144 commented out the ble_sd_enable

Here is the modified mesh_gatt.c. Modifications are-

  1. On line 217 changed the security level for MITM protection.
  2. On line 297 changed the security level for MITM protection.

Here is the ble_app_custom folder with modified files. You can compile it with gcc putting it in examples/ble_peripheral folder.

Also, adding, this may be out of your scope, but, so far, I have failed to read uart fron nRF51 DK PCA10028 V1.1.0 2015.25 in all examples. So, if you successfully run this example with the ability to read the uart, please, tell me the nRF51 DK version you used. Thanks.

trond-snekvik commented 8 years ago

Thanks for the detailed report. I ran through your program with the JLink GDB server connected, and discovered some issues with both the mesh and the program:

  1. The err_code at main.c:321 must be initialized, I got an app error at main.c:330, because the error_code just contained stack-garbage.
  2. The timeslot SD-event handler doesn't take too kindly on irrelevant soc-events from the SD. This is a problem with the rbc_mesh, and I've created an issue for it. As a hotfix, change timeslot.c:183 from APP_ERROR_CHECK(NRF_ERROR_INVALID_STATE) to break;.
  3. The error_code in nrf_adv_conn.c:140 has the same issue as the one in timer_init, when the call to sd_ble_enable() is commented out. Either comment out the error check, or initialize the error_code variable.

By fixing these errors, I made your code run, and it shows up in the Master control panel :)

rifatmahmud commented 8 years ago

Thanks a lot! :+1:

Just before closing the issue, I need to clarify one thing.

When I want to compile for PCA10031 by only changing the .ld file to this, I get this error message while linking:

Linking target: nrf51422_xxac_s110.out /usr/local/gcc-arm-none-eabi-4_8-2014q1/bin/../lib/gcc/arm-none-eabi/4.8.3/../../../../arm-none-eabi/bin/ld: region RAM overflowed with stack collect2: error: ld returned 1 exit status make: *\ [nrf51422_xxac_s110] Error 1

Is it objectively not possible to run this example on PCA10031 Board(in my case it is an RBL nRF51822)?

trond-snekvik commented 8 years ago

Yeah, looks like your config needs more than 16kB of RAM. You should be able to reduce it quite a bit by changing some configurations. The assembly-startup file from the SDK defines the size of your STACK and HEAP. If you don't use malloc, you can safely set HEAP size to 0. You might be able to reduce stack size as well, but you would have to experiment a bit. Buffer sizes in the framework are also up for reduction. In particular, the caches in version_handler.h can be reduced to 10% of their sizes.

rifatmahmud commented 8 years ago

Sorry, had to reopen the issue.

Here, I have changed the gap params to have bond and mitm. Also, I had made the security level to have mitm protection here and here. Still, when I make mesh_start = 1 in main.c, the bonding operation [not showing the passkey], as it does in case I make mesh_start = 0.

Here is the changed code.

So, my question is, how do I force pairing before any operation on mesh_gatt service?

rifatmahmud commented 8 years ago

To see the displayed passkey, you have to open Tera Term on the COM port of nRF51 DK, with baud rate 38400, flow control none, parity none and stop bit 1.

rifatmahmud commented 8 years ago

Hi @trond-snekvik , do you have any suggestion?

trond-snekvik commented 8 years ago

Hi, sorry, I haven't had time to look at it yet. If I understand you correctly, I think the write-authentication might be what you're looking for. You will get an auth-event on each read or write request, which you have to authorize. It's not the one-time authorization you might have been looking for, but it should solve your problem.