This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

connect to bonded device using Masteremulator C#

Hi all,

I am using a C# application with the masteremulator dll to connect to a nRF51822 with S110 V8.0.0

I can bond with a new device, and communicate with it in a secure way. But I don't know how to reconnect later with this bonded device.

I did not find useful info in the examples.

How can the c# application know whether or not the bond() function has to be called?

Any information or example is welcome.

I use function RestoreBondInformation and GetBondInformation to save and restore the bonding information.

  • Hi Kuhn,

    You would need to store the device address and try to reconnect later with that device. If bond information is not cleared the MasterEmulator will try to re-encrypt the link automatically.

    If you for example deleted bond information or close the program and reopen it, you would need to call RestoreBondInformation () with the string you get earlier with GetBondInformation .

    If you want to support multiple bonded devices, you would need to create a table that match the address of the device and the string you get from GetBondInformation () when you are bonding with that device.

  • I was having the same issue and go it working in the OnConnected event with the following code, although I have to reseat the dongle some of the time to get it to work.

          Task.Run(() =>
            {
            try
            {
                SecurityParameters securityParams = new SecurityParameters();     
                masterEmulator.DeleteBondInformation();
                isBonded = masterEmulator.Bond(securityParams);
                if (isBonded)
                {
                    s = masterEmulator.GetBondInformation();
                    if (File.Exists(@"C:\temp\bond.txt"))
                    {
                        File.Delete(@"C:\temp\bond.txt");
                    }
                    File.WriteAllText(@"C:\temp\bond.txt", s);
                }
                else
                {
                    if (File.Exists(@"C:\temp\bond.txt"))
                    {
                        masterEmulator.DeleteBondInformation();
                        masterEmulator.RestoreBondInformation(File.ReadAllText(@"C:\temp\bond.txt"));
                        masterEmulator.RefreshKeys();
                    }
                }
                
                DiscoverPipes();
                OpenRemotePipes();
            }
            catch (Exception ex)
            {
                LogErrorMessage(string.Format("Exception in OnConnected: {0}", ex.Message),ex.StackTrace);
            }
            });
    
  • Is the issue that you need to reset the dongle directly related to the bonding feature ? Or it happens regardless what you do with the emulator ?

  • No, the code above works well and solved another issue I was having.

Related