Help with mergBLE

This is the place to get technical support and discuss all things to do with MergEXT

Moderators: FourthWorld, heatherlaine, Klaus, robinmiller, monte

Help with mergBLE

Postby ctflatt » Thu Jul 13, 2017 9:49 pm

Hello!

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 :)

Thanks!

Todd
ctflatt
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
 
Posts: 240
Joined: Sun Dec 06, 2009 12:24 am
Location: Fredericktown, MO

Re: Help with mergBLE

Postby monte » Thu Jul 20, 2017 11:28 pm

Hi @ctflatt

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

Cheers

Monte
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/
monte
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
 
Posts: 1558
Joined: Fri Jan 13, 2012 1:47 am

Re: Help with mergBLE

Postby ctflatt » Fri Jul 21, 2017 1:46 am

Monte,

Thank God!

I have it... would you help? My client is chomping at the bit...
ctflatt
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
 
Posts: 240
Joined: Sun Dec 06, 2009 12:24 am
Location: Fredericktown, MO

Re: Help with mergBLE

Postby ctflatt » Fri Jul 21, 2017 2:29 pm

Monte,

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

https://christopherflatt.com/monte/ibeacon_manual.pdf

Many thanks!

Christopher (Todd)
ctflatt
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
 
Posts: 240
Joined: Sun Dec 06, 2009 12:24 am
Location: Fredericktown, MO

Re: Help with mergBLE

Postby monte » Tue Jul 25, 2017 3:19 am

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
   else
      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
   else
      repeat for each line tCharacteristic in pCharacteristics
         switch
            case pService begins with "FFF0" and tCharacteristic begins with "FFF1"
              -- password
              mergBLEPeripheralWriteValueForCharacteristic pPeripheral, pService, tCharacteristic, "fff"
              break
            -- 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.
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/
monte
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
 
Posts: 1558
Joined: Fri Jan 13, 2012 1:47 am


Return to MergEXT

Who is online

Users browsing this forum: No registered users and 1 guest