Hi All, I am working on a problem for last 2 days and cannot find a solution, I tried everything and read many posts from others however nothing worked so far, either it seems that this specific problem have not been discussed enough or some samples that may lead to solution were not complete so I cannot put them together to work, so I am hoping someone can help to solve this:
I am using BLE_UART example from DK and simply re-tailor it to my needs, which are simple: - receive commands over BLE UART and do some actions to hardware depending on those commands, such as get data via I2C, etc, switch some pins on remote device, etc, the main functionality I all figured out and it works great.
What I need to do is simple authentication process, where once User is connected, he will have 1 - 2 seconds to send authentication package (essentially just a passkey) that will allow further communication via BLE Uart, if authentication was not provided then disconnect will be commenced and user will be disconnected. I do not want to use pairing or whitelist because my authentication is meant not to protect data or ancrypt connection, etc, it is simply designed just to make sure that if someone accidentally connect to BLE device it wont lock it from others, because obviously once you connect to the bluetooth device, it will no longer be discoverable by other users who may have passkey and want to use it.
So, the way I ave it now is this:
I have a function that updates password from Hardware and keeps it in global variable, "devicePasskey", it is called once upon device power up.
Then I have another function that when user sends passkey in form of text command for example: "passkey=qwerty" via nus service, will parse it and recognize that this is a passkey command and will extract that passkey and store it in it in variable called "userPasskey" that function
Then I have another function that compares both variables and if they do not match will execute sd_ble_gap_disconnect command and disconnect user.
My dilemma is, once you connect to device how do I properly implement 1 - 2 seconds timeout before I start checking if passkeys match, I tried to use timer examples but unsuccessfully, there seem to be already a timer init command in main() block,
APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false);
so if I understand correctly I can use it and add my event to it, I tried to follow some examples 1:1 and it did not work, perhaps because most examples I saw were about buttons and led lights, I simply need to execute my passwords compare function and if its true then continue and if false then initiate disconnect.
Any suggestions are welcome, thank you,