Page 1 of 1

Help with mergBLE

Posted: Thu Jul 13, 2017 9:49 pm
by ctflatt

I am using mergBLE in a new project but honestly do not know where to go from here. I am trying to connect/pair with a beacon and have gotten this far:

I have initialized mergBLE and am able to ScanForPeripheralsWithServices. I do get a device UUID.

I need to connect to this device and enter a password to complete the process. I need to be able to change its name and read certain characteristics from the device.

Where do I go from mergBLEDidConnectPeripheral?

Can anyone help?

A point in the right direction would be most appreciated :)



Re: Help with mergBLE

Posted: Thu Jul 20, 2017 11:28 pm
by monte
Hi @ctflatt

You really need the documentation of the hardware you are connecting to to get much further.



Re: Help with mergBLE

Posted: Fri Jul 21, 2017 1:46 am
by ctflatt

Thank God!

I have it... would you help? My client is chomping at the bit...

Re: Help with mergBLE

Posted: Fri Jul 21, 2017 2:29 pm
by ctflatt

Here is the documentation/manual... I believe everything is there, I just don't know what to do with it...

Many thanks!

Christopher (Todd)

Re: Help with mergBLE

Posted: Tue Jul 25, 2017 3:19 am
by monte
OK so once you get your device UUID you need to:

Code: Select all

on mergBLEDidDiscoverPeripheral pPeripheral, pName, pRSSI
    mergBLEConnectPeripheral pPeripheral
end mergBLEDidDiscoverPeripheral

on mergBLEDidConnectPeripheral pPeripheral
   mergBLEPeripheralDiscoverServices pPeripheral
end mergBLEDidConnectPeripheral

on mergBLEPeripheralDidDiscoverServices pPeripheral, pServices, pError
   if pError is not empty then
      answer "Error discovering services:" & cr & pError
      repeat for each line tService in pServices
         mergBLEPeripheralDiscoverCharacteristicsForService pPeripheral, tService
      end repeat
   end if
end mergBLEPeripheralDidDiscoverServices

on mergBLEPeripheralDidDiscoverCharacteristicsForService pPeripheral, pService, pCharacteristics, pError
   if pError is not empty then
      answer "Error discovering characteristics for "&sPeripheralA[pPeripheral]["name"] & cr & pError
      repeat for each line tCharacteristic in pCharacteristics
            case pService begins with "FFF0" and tCharacteristic begins with "FFF1"
              -- password
              mergBLEPeripheralWriteValueForCharacteristic pPeripheral, pService, tCharacteristic, "fff"
            -- other characteristics from docs
         end switch
      end repeat
   end if
end mergBLEPeripheralDidDiscoverCharacteristicsForService
Note that the docs are a bit funny for the password. It says 2 bytes but then 0x666666 which is 3 bytes converts to "fff". Anyway the above should show you how to write to a characteristic. If there's a problem with it I'd recommend logging all the services and characteristics found so you can see what's going on.