Laird RM1 Series Instruction Manual

Ble central smartbasic extensions

Advertisement

Quick Links

RM1xx BLE Central
smartBASIC Extensions
RM1xx Series
Document version 1.0

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the RM1 Series and is the answer not in the manual?

Questions and answers

Subscribe to Our Youtube Channel

Summary of Contents for Laird RM1 Series

  • Page 1 RM1xx BLE Central smartBASIC Extensions RM1xx Series Document version 1.0...
  • Page 2 Notes Approver 27 Jan 2017 Initial version Jonathan Kaye 11 Oct 2017 Updates for latest stack Jonathan Kaye Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 3: Table Of Contents

    Acknowledgements ......................... 246 10.1 License Terms ........................246 10.2 Disclaimer ..........................246 Index of smartBASIC Commands ..................... 247 Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 4: Introduction

    All the above documents are found in the documentation tab of the RM1xx product page: http://www.lairdtech.com/products/rm1xx-lora-modules 1.2 What Does a LoRa/BLE Module Contain? Laird’s smartBASIC-based LoRa/BLE modules are designed to provide a complete wireless processing solution and contain the following: ▪...
  • Page 5: Interactive Mode Commands

    1000 error codes, these verbose strings can occupy more than 10 kilobytes of flash memory. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 6: At I

    You can also obtain a verbose description of an error by highlighting the error value, right-clicking, and selecting Lookup Selected ErrorCode in the Terminal window. If you get the text UNKNOWN RESULT CODE 0xHHHH, please contact Laird for the latest version of UWterminal.
  • Page 7 This is an Interactive mode command and must be terminated by a carriage return for it to be processed. ‘Example: AT i 3 2.0.1.2 AT I 4 01 D31A920731B0 AT i is a core command. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 8: At+Cfgex

    OK if file successfully erased. Arguments Integermask Integer corresponding to a bit mask or the “*” character Interactive Command Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 9: At + Btd

    If the address 000000000000 is written then it is treated as invalid and prevents a new address from being entered. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 10: At + Blx

    Note: The module self-reboots so that the bonding manager context is also reset. ‘Examples: AT+BLX AT+BLX is an extension command. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 11: Core Language Built-In Routines

    Highlight the last four characters of the result code in UwTerminal and select Lookup Selected ErrorCode (Figure Figure 3: Lookup Selected ErrorCode Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 12: Information Routines

    How RAND() generates values: 0 for PRNG and 1 for hardware assist 1002 Minimum baudrate 1003 Maximum baudrate 1004 Maximum STRING size Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 13 Number of devices in trusted device database that can Persist 2100 Connect Scan interval (in milliseconds) used when connecting Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 14 The Bluetooth address of the module. It is seven bytes long. First byte is 00 for IEEE public address and 01 for random public address. Next six bytes are the address. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 15: Uart (Universal Asynchronous Receive Transmit)

    N – None ▪ O – Odd (Not Available) ▪ E – Even (Not Available) Databits: 8 Stopbits: 1 Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 16 If this feature is required, then the best way to expedite it is to put UART_TX and an I/O pin configured as an output through an AND gate. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 17: I2C - Two Wire Interface (Twi)

    7-bit slave addressing is supported. 3.5 SPI Interface The RM1xx module can only be configured as a SPI master. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 18: Core Extensions Built-In Routines

    See example for GpioAssignEvent() GpioSetFunc FUNCTION This routine sets the function of the GPIO pin identified by the nSigNum argument. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 19 1..4000000 generates an output signal with 50% duty cycle with that frequency. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 20 This routine configures the PWM (Pulse Width Modulation) of all output pins when they are set as a PWM output using GpioSetFunc() function described above. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 21 = 500 // we want a resolution of 1:1000 in the generated analogue output nMaxValUs = 1000 Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 22 The signal number as stated in the pinout table of the module. Interactive Command //Example :: GpioRead.sb (See in Firmware Zip file) signal Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 23 //set sio pin 5 to PWM output minFreq = 500 PRINT GpioConfigPWM(minFreq,1024);"\n" //set max pwm value/resolution to 1:1024 PRINT GpioSetFunc(5,2,2);"\n" Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 24 The signal number as stated in the pinout table of the module. nPolarity byVal nPolarity INTEGER States the transition as follows: Low to high transition High to low transition Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 25 The GPIO event number (in the range of 0 - N) which is disabled so that it no longer generates run-time events in smartBASIC. Interactive Command //Example :: GpioUnbindEvent.sb (See in Firmware Zip file) FUNCTION Btn0Press() Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 26 In the RM1xx, this function results in approximately 4 uA of continuous current consumption from the power supply. It is impossible to assign a polarity value which detects either level transitions. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 27 //When event 0 is detected, call Btn0Press PRINT "\nPress button 0" WAITEVENT Expected Output: Press button 0 Hello GPIOASSIGNEVENT is a Module function. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 28 PRINT GpioAssignEvent(0,16,1);"\n" ONEVENT EVDETECTCHAN0 CALL Btn0Press ONEVENT EVTMR0 CALL Tmr0TimedOut PRINT GpioUnAssignEvent(0);"\n" PRINT "\nPress button 0\n" TimerStart(0,8000,0) WAITEVENT Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 29: Ble Extensions Built-In Routines

    00112233445566 and a variable can be initialized using a constant string by escaping as follows: Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 30: Events And Messages

    (as opposed to an EVENT, which is akin to an interrupt and has no Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 31 SetPwrSupplyThreshMv() and msgCtx is the current voltage in millivolts. The connection is no longer encrypted and msgCtx is the conn handle Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 32 PRINT "\nUnknown Ble Msg" ENDSELECT ENDFUNC FUNCTION HndlrBlrAdvTimOut() PRINT "\nAdvert stopped via timeout" PRINT "\nExiting..." ENDFUNC FUNCTION Btn0Press() Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 33 Connected to a bonded master Connection 3634 is now encrypted A new pairing has replaced the old key Disconnected 3634 Exiting... Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 34 INTEGER) AS INTEGER PRINT "\nConnection ";hConn;" Closed: 0x";nRsn ENDFUNC ONEVENT EVBLEMSG CALL HndlrBleMsg ONEVENT EVDISCON CALL HndlrDiscon Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 35 //initialise char, write/read enabled, accept signed writes rc=BleCharNew(0x0A,BleHandleUuid16(1),BleAttrMetaData(1,1,20,0,rc),0,0) //commit char initialised above, with initial value "hi" to service 'hSvc' Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 36 //============================================================================== // New char value handler //============================================================================== FUNCTION HandlerCharVal(BYVAL charHandle, BYVAL offset, BYVAL len) charHandle == hMyChar THEN Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 37 5 byte(s) have been written to char value attribute from offset 0 New Char Value: Hello --- Disconnected from client Exiting... Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 38 //initialise char, write/read enabled, accept signed writes, indicatable rc=BleCharNew(0x6A,charUuid,charMet,mdCccd,0) //commit char initialised above, with initial value "hi" to service 'hMyChar' rc=BleCharCommit(hSvc,attr$,hMyChar) Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 39 // Indication acknowledgement from client handler //============================================================================== FUNCTION HndlrCharHvc(BYVAL charHandle INTEGER) AS INTEGER charHandle == hMyChar THEN PRINT "\nGot confirmation of recent indication" Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 40 ONEVENT EVBLEMSG CALL HndlrBleMsg ONEVENT EVCHARHVC CALL HndlrCharHvc ONEVENT EVCHARCCCD CALL HndlrCharCccd ONEVENT EVGPIOCHAN1 CALL HndlrBtn0Pr OnStartup()==0 THEN Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 41 //initialise char, read enabled, accept signed writes, broadcast capable rc=BleCharNew(0x03,BleHandleUuid16(1),charMet,0,mdSccd) //commit char initialised above, with initial value "hi" to service 'hMyChar' Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 42 "\n--- Connected to client" ENDIF ENDFUNC //=================================================================== //handler to service button 0 pressed //=================================================================== FUNCTION HndlrBtn0Pr() AS INTEGER CloseConnections() ENDFUNC //==================================================================== Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 43 SCCD (CCCD and SCCD are catered for with their own dedicated messages). It comes with two parameters: ▪ The characteristic handle that was returned when the characteristic was registered using the function BleCharCommit() Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 44 //commit reports to GATT table - adRpt$ is empty rc=BleAdvRptsCommit(adRpt$,scRpt$) rc=BleAdvertStart(0,addr$,20,300000,0) rc=GpioBindEvent(1,16,1) //Channel 1, bind to low transition on GPIO pin 16 ENDSUB Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 45 "\n ::Char Handle: ";charHandle PRINT "\n ::Descriptor Index: ";hDesc PRINT "\nThe descriptor value then read using function BleCharDescRead()" Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 46 Likewise, writes which are acknowledged also do not consume these buffers. //Example :: EvNotifyBuf.sb (See in RM1xxCodeSnippets.zip) hMyChar,rc,at$,conHndl,ntfyEnabled //============================================================================== // Initialise and instantiate service, characteristic, start adverts //============================================================================== Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 47 PRINT "\n--- Notifying" tx$="SomeData" rc=BleCharValueNotify(hMyChar,tx$) count=count+1 UNTIL rc!=0 PRINT "\n--- Buffer full" PRINT "\nNotified ";count;" times" Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 48 " : Notifications have been enabled by client" ntfyEnabled=1 tx$="Hello" rc=BleCharValueNotify(hMyChar,tx$) ELSE PRINT "\nNotifications have been disabled by client" ntfyEnabled=0 ENDIF ELSE Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 49: Miscellaneous Functions

    5.3 Miscellaneous Functions This section describes all BLE-related functions that are not related to advertising, connection, security manager, or GATT. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 50 "\nTx power : desired= ";dp," "," actual= "; SysInfo(2008) dp=-45 : rc = BleTxPowerSet(dp) PRINT "\nTx power : desired= ";dp," "," actual= "; SysInfo(2008) Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 51 -55) so that the highest value in the list which is less than the desired value is set. Note that if desired value is less than -55 then -55 is selected. Interactive Command Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 52 Until a future revision when the chipset vendor has fixed a hardware issue at the silicon level, this function does not function as stated and any nNewState value are interpreted as OFF. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 53: Advertising Functions

    This function causes a BLE advertisement event as per the Bluetooth Specification. An advertisement event consists of an advertising packet in each of the three advertising channels. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 54 ADV_NONCONN – Does not accept connections and/or active scans ADV_DIRECT_LOW_DUTY_CYCLE – Invites connection from addressed device using low duty cycle timing using nAdvInternal and nAdvTimeout specified Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 55 Interactive Command //Example :: BleAdvertStart.sb addr$ : addr$="" FUNCTION HndlrBlrAdvTimOut() PRINT "\nAdvert stopped via timeout" Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 56 //The advertising interval is set to 25 milliseconds. The module will stop //advertising after 60000 ms (1 minute) BleAdvertStart(0,addr$,25,60000,0)==0 THEN PRINT "\nAdverts Started" PRINT "\nIf you search for bluetooth devices on your device, you should see 'Laird RM1xx'" ELSE PRINT "\n\nAdvertisement not successful" ENDIF ONEVENT...
  • Page 57 "\n\nAdvertisement not successful" ENDIF rc = GpioSetFunc(16,1,2) rc = GpioBindEvent(0,16,1) ONEVENT EVBLE_ADV_TIMEOUT CALL HndlrBlrAdvTimOut ONEVENT EVGPIOCHAN0 CALL Btn0Press WAITEVENT Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 58 The n leftmost characters of the device name specified in the GAP service. If this value is set to 0 then the device name is not included. Interactive Command Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 59 Interactive Command //Example :: BleScanRptInit.sb (See in RM1xxCodeSnippets.zip) scnRpt$ : scnRpt$="" BleScanRptInit(scnRpt$)==0 THEN PRINT "\nScan report initialised" ENDIF Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 60 Set the value to -1 to have it ignored and then all further UUID arguments are also ignored. Interactive Command Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 61 AdvRpt AS STRING. The advert report into which the 128-bit UUID AD record is to be added. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 62 Arguments advRpt$ byRef AdvRpt AS STRING. The advert report onto which the AD record is to be appended. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 63 Most typical value – 0x0000, indicating a successful operation. Arguments advRpt$ byRef advRpt AS STRING. The most recent advert report. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 64: Scanning Functions

    The scan procedure ends when it times out (timeout parameter is supplied when scanning is initiated) or is explicitly instructed to abort or stop. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 65 For this situation, this function takes a filter parameter which enables an opaque object to be presented to the baseband which contains a whitelist Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 66 '//Scan for 20 seconds with no filtering rc = BleScanStart(20000, rc==0 THEN PRINT "\nScanning" ELSE PRINT "\nError: "; INTEGER.H'rc ENDIF Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 67 INTEGER, a result code. Returns Most typical value – 0x0000, indicating a successful operation. Arguments None Interactive Command Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 68 The value is a bit mask: Bit 0 Set if advertising is in progress (not possible with the RM1xx) Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 69 THEN PRINT "\nStop scanning. Freeing up allocated memory" rc = BleScanStop() SysInfo(2016) == 0 THEN PRINT "\nScan stopped" Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 70 The following lists the default parameters and their settings: Scan Interval 80 milliseconds Scan Window 40 milliseconds Scan Type (Active/Passive) Active Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 71 = BleScanConfig(2, //set scan type to passive rc = BleScanConfig(3, //set report cache size PRINT "\n\n--- New Parameters:" Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 72 RSSI value. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 73 "\nScan timeout" ENDFUNC '//This handler will be called when an advert is received FUNCTION HndlrAdvRpt() periphAddr$, advData$, nDiscarded, nRssi Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 74 No. Discarded Adverts: 0 RSSI: -92 --- No more adverts in cache Scan timeout BLESCANGETADVREPORT is an extension function. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 75 '//AD with length = 7 bytes, tag = 0xDA ad2$="\07\EE\AA\BB\CC\DD\EE\FF" fullAD$ = ad1$ + ad2$ PRINT "\n\n"; Strhexize$(fullAD$);"\n" rc=BleGetADbyIndex(0, fullAD$ , nADTag, ADval$ Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 76 If multiple instances of that AD tag type are suspected, then use the function BleGetADbyIndex to extract. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 77 PRINT "\nAD element with tag 0x"; INTEGER.H'nADTag ;" is ";StrHexize$(ADval$) ELSE PRINT "\nError reading AD: " ;INTEGER.H'rc ENDIF Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 78 BleConnect() if that is the desired use case. The Bluetooth specification does NOT mandate a connection. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 79 "\nrequesting a connection to this module" rc = BleScanStop() ENDFUNC ONEVENT EVBLE_SCAN_TIMEOUT CALL HndlrScanTO ONEVENT EVBLE_FAST_PAGED CALL HndlrFastPaged WAITEVENT Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 80: Whitelist Management Functions

    Do NOT destroy this object using BleWhiteListDestroy () while the object is in use by the underlying stack. This results in unpredictable behaviour. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 81 BLEWHITELISTADDADDR (handle, madAddr$) INTEGER, a result code. Returns Most typical value – 0x0000, indicating a successful operation. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 82 Do NOT destroy a whitelist object while the object is in use by the underlying stack. This results in unpredictable behaviour. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 83: Connection Functions

    The bonding has been updated with a new long term key The connection is encrypted The connection is no longer encrypted Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 84 The link supervision timeout for the connection in microseconds. Interactive Command //Example :: BleConnect.sb (See in RM1xxCodeSnippets.zip) rc, periphAddr$ '//Scan indefinitely rc=BleScanStart(0, rc==0 THEN PRINT "\nScanning" Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 85 THEN PRINT "\n--- Connected to device with MAC address "; StrHexize$(periphAddr$) PRINT "\n--- Disconnecting now" rc=BleDisconnect(nCtx) ENDIF ENDFUNC Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 86 INTEGER, a result code. Returns Most typical value – 0x0000, indicating a successful operation. Arguments None Interactive Command Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 87 "\n--- Connecting \nCancel" ELSE PRINT "\nError: "; INTEGER.H'rc ENDIF '//Cancel current connection attempt rc=BleConnectCancel() PRINT "\n--- Connection attempt cancelled" Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 88 ‘base’ value. For the purpose of this documentation and discussions with Laird, this parameter is referred to as ‘multi-link connection interval periodicity’.
  • Page 89 = BleConnectConfig(2, //set slave latency to 1 rc = BleConnectConfig(5, //set ML connection interval periodicity to 30 Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 90 Arguments nConnHandle byVal nConnHandle AS INTEGER. Specifies the handle of the connection that must be disconnected. Interactive Command Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 91 "\n\nAdvertisement not successful" ENDIF WAITEVENT Expected Output: Adverts Started New Connection 35800 Disconnected 3580 BLEDISCONNECT is an extension function. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 92 50 and slave latency of 19 means the slave is allowed to NOT acknowledge a poll for up to 19 poll messages from the central device. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 93 Latency",slat ENDIF CASE //BLE_EVBLEMSGID_CONN_PARMS_UPDATE_FAIL PRINT "\n ??? Conn Parm Negotiation FAILED" CASE ELSE PRINT "\nBle Msg",nMsgId ENDSELECT ENDFUNC Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 94 --- Disconnected : Note: First set of parameters differ depending on your central device. BLESETCURCONNPARMS is an extension function. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 95 The connection handle will be returned in this argument. Will be an invalid handle value if a connection does not exist. Interactive Command Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 96 : addr$="" rc, connHandle connHandle = 0x0001FF00 rc = BleAddrFromConnHandle (connHandle , addr$) PRINT "\Address = ";StrHexize$(addr$) Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 97: Security Manager Functions

    This is the passkey to submit to the stack. Submit a value outside the range 0 to 999999 to reject the pairing. Interactive Command //Example :: BleSecMngrPasskey.sb (See in RM1xxCodeSnippets.zip) rc, connHandle Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 98 1655 +++ Auth Key Request, type=1 Passkey 123456 was used --- Disconnected 1655 BLESECMNGRPASSKEY is an extension function. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 99 MITM (Man in the middle) security attack. The valid user I/O capabilities are as described below. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 100 Most typical value – 0x0000, indicating a successful operation. Arguments nBondReq byVal nBondReq AS INTEGER. Disable Enable Interactive Command Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 101 Interactive Command See example for BleDisconnect: Change “rc = BlePair(nCtx)” to “PRINT BlePair(nCtx)” BLEPAIR is an extension function. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 102: Gatt Server Functions

    UUID (sometimes also known as GUID) generation utility. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 103 Bluetooth SIG for custom UUIDs. Note that Laird does not warrant or guarantee that the UUID generated by this website or any other utility is unique. It is left to the judgement of the developer whether to use it or not.
  • Page 104 Characteristic is adopted or custom because from then on the firmware managing it behind the scenes in smartBASIC does not care. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 105 Save the handle that is returned as it is used to interact with the More characteristic Characteristics? More Services? Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 106 = BleHandleUuid16(0x180D) rc = BleSvcCommit(BLE_SERVICE_PRIMARY, hUuidS1,hSvc) //---Register Characteristic 1 in Service 1 mdAttr = BleAttrMetadata(BLE_ATTR_ACCESS_OPEN,BLE_ATTR_ACCESS_OPEN,10,0,rc) mdCccd = BLE_CHAR_METADATA_ATTR_NOT_PRESENT Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 107 //------------------------------------------------------------------------------ // This handler is called when there is a EVCHARVAL message FUNCTION HandlerCharVal(BYVAL hChar INTEGER) AS INTEGER Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 108 = BleCharValueIndicate(hChar12,attr$) The rest of this section details all the smartBASIC functions that help create that framework. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 109 The preferred minimum connection interval, updates the ‘Peripheral Preferred Connection Parameters’ characteristic of the GAP service. Range is between 7500 and Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 110 //Slave latency--number of conn events that can be missed rc=BleGapSvcInit(dvcNme$,nmeWrtble,apprnce,MinConnInt,MaxConnInt,ConnSupTO,sL) THEN PRINT "\nSuccess" ELSE PRINT "\nFailed 0x"; INTEGER.H'rc //Print result code as 4 hex digits ENDIF Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 111 MaxConnInt = 1000000 ConnSupTO = 4000000 sL = 0 rc = BleGapSvcInit(dvcNme$,nmeWrtble,apprnce,MinConnInt,MaxConnInt,ConnSupTO,sL) PRINT "\n --- New DevName : "; BleGetDeviceName$() Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 112 The device’s regulatory certification data list as defined in the specification. It can be set as an empty string to omit submission. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 113 THEN PRINT "\nSuccess" ELSE PRINT "\nFailed 0x"; INTEGER.H'rc ENDIF Expected Output: Success BLESVCREGDEVINFO is an extension function. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 114 "; integer.h' hUuidHRS;"(";hUuidHRS;")" ENDIF Expected Output: Handle for HRS Uuid is FE01180D (-33482739) BLEHANDLEUUID16 is an extension function. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 115 // hUuidCustom now references an object which points to // a base uuid = ced9d91366924a1287d56f2747622b2a (note 0's in byte position 2/3) Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 116 == 0 THEN PRINT "\nFailed to create a handle" ELSE PRINT "Handle for custom Uuid is ";integer.h' hUuid1;"(";hUuid1;")" Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 117 SECONDARY service. This referencing is expedited within the definition of a service using the concept of INCLUDED SERVICE which Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 118 "\nHealth Thermometer Service attribute written to GATT table" PRINT "\nUUID Handle value: ";hUuidHT PRINT "\nService Attribute Handle value: ";hHtsSvc Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 119 This function in the RM1xx is a dummy function and does not do anything. However, for portability to other Laird 4.0 compatible modules, always invoke this function after the last descriptor of the last characteristic of a service has been committed to the GATT server.
  • Page 120 This argument will contain a handle that was previously created using the function BleSvcCommit() Interactive Command //Example :: BleSvcAddIncludeSvc.sb (See in RM1xxCodeSnippets.zip) Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 121 This function allows a 32-bit integer to be created (an opaque object) which defines those properties and is then submitted along with other information to add the attribute to the GATT table. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 122 Signed with MITM protection (not available) Note: In early releases of the firmware, 4 and 5 are not available. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 123 // and Heart Rate attribute has variable length //++++ //There is always a Value attribute in a characteristic Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 124 Can be written by the client without response Can be written Can be notifiable (CCCD descriptor must be present) Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 125 // --- Can be read, not written (shown in mdVal as well) //============================================================================== BleCharNew(0x22,charUuid,mdVal,mdCccd,0)==0 THEN PRINT "\nNew Characteristic created" Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 126 : charMet = BleAttrMetaData(1,1,20,0,metaSuccess) mdUsrDsc : mdUsrDsc = BleAttrMetaData(1,1,20,0,metaSuccess) mdSccd : mdSccd = BleAttrMetadata(1,1,2,0,rc) //CCCD metadata for char Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 127 Most typical value – 0x0000, indicating a successful operation. Arguments nFormat byVal nFormat AS INTEGER Valid range 0 to 255. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 128 : charMet = BleAttrMetaData(1,1,20,0,metaSuccess) mdUsrDsc : mdUsrDsc = BleAttrMetaData(1,1,20,0,metaSuccess) mdSccd : mdSccd = BleAttrMetadata(1,1,2,0,rc) //CCCD metadata for char Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 129 Expected Output: Char created and User Description 'A description' added Presentation Format Descriptor added BLECHARDESCPRSTNFRMT is an extension function. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 130 : mdUsrDsc = charMet mdSccd : mdSccd = charMet //initialise char, write/read enabled, accept signed writes, indicatable Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 131 "\nOther descriptors added successfully" ELSE PRINT "\nFailed" ENDIF Expected Output: Other descriptors added successfully BLECHARDESCADD is an extension function. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 132 See event messages: EVCHARHVC, EVCHARVAL, EVCHARCCCD, EVCHARSCCD, EVCHARDESC. Interactive Command Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 133 ENDIF //the characteristic will now be visible in the GATT table //and is refrenced by ‘hHtsMeas’for subsequent calls Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 134 : attr$="Hi" //commit service rc=BleSvcCommit(1,BleHandleUuid16(0x18EE),hSvc) //initialise char, write/read enabled, accept signed writes Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 135 // Get the connnection handle //============================================================================== FUNCTION HndlrBleMsg(BYVAL nMsgId, BYVAL nCtn) conHndl=nCtn ENDFUNC OnStartup()==0 THEN at$ : rc = BleCharValueRead(hMyChar,at$) Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 136 BleCharCommit() was called. attr$ byRef attr$ AS STRING String variable, contains new value to write to the characteristic. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 137 : rc=UartRead(t$) BleCharValueWrite(hMyChar,t$)==0 THEN PRINT "\nNew characteristic value: ";t$ ELSE PRINT "\nFailed to write new characteristic value" ENDIF Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 138 A notification does not result in an acknowledgement from the client. BLECHARVALUENOTIFY (charHandle, attr$) INTEGER, a result code. Returns Most typical value – 0x0000, indicating a successful operation. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 139 //Add 1 service handle to scan report rc=BleAdvRptAddUuid16(scRpt$,0x18EE,-1,-1,-1,-1,-1) //commit reports to GATT table - adRpt$ is empty rc=BleAdvRptsCommit(adRpt$,scRpt$) rc=BleAdvertStart(0,addr$,50,0,0) ENDFUNC Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 140 " : Notifications have been disabled by client" ENDIF ELSE PRINT "\nThis is for some other characteristic" ENDIF ENDFUNC Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 141 GATT client. The characteristic is identified by a composite handle returned by the function BleCharCommit(). Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 142 //Add 1 service handle to scan report rc=BleAdvRptAddUuid16(scRpt$,0x18EE,-1,-1,-1,-1,-1) //commit reports to GATT table - adRpt$ is empty Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 143 "\nSuccessful indication of new value" EXITFUNC ENDIF ELSE PRINT " : Indications have been disabled by client" ENDIF Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 144 "\nThe RM1xx will then indicate a new characteristic value\n" ELSE PRINT "\nFailure OnStartup" ENDIF WAITEVENT rc=BleDisconnect(conHndl) rc=BleAdvertStop() PRINT "\nExiting..." Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 145 AS INTEGER On exit, this is updated with the applicable UUID handle of the descriptor. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 146 // Close connections so that we can run another app without problems //============================================================================== CloseConnections() rc=BleDisconnect(conHndl) rc=BleAdvertStop() ENDSUB //============================================================================== // Ble event handler - Just to get the connection handle Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 147 PRINT "\nWrite to the User Descriptor with UUID 0x2999" //wait for events and messages WAITEVENT CloseConnections() PRINT "\nExiting..." Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 148: Gatt Client Functions

    Handle Type Value Comments 0x0001 0x2800 UUID of the Service Primary Service 1 Start Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 149 Hence when a handle is known there is no ambiguity. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 150 The Bluetooth specification states that if an operation is initiated and is not completed within 30 seconds then the connection shall be dropped as no further Gatt Client transaction can be initiated. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 151 ATT Error: Reserved for Future Use range #3 begin 0x01FC ATT Error: Reserved for Future Use range #3 end Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 152 //============================================================================== // Ble event handler //============================================================================== FUNCTION HndlrBleMsg(BYVAL nMsgId, BYVAL nCtx) conHndl=nCtx nMsgID==1 THEN PRINT "\n\n- Disconnected" EXITFUNC Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 153 At the Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 154 "\nGatt Client is now open" ENDIF //open the client with default notify/indicate ring buffer size - again rc = BleGattcOpen(128,1) Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 155 "\nGatt Client is now closed" BleGattcClose() PRINT "\nGatt Client is closed - was safe to call when already closed" Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 156 Register a handler for the EVDISCPRIMSVC event message On EVDISCPRIMSVC event message If Start/End Handle == 0 then scan is complete Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 157 //Example :: BleDiscServiceFirst.Next.sb (See in RM1xxCodeSnippets.zip) //Remote server has 5 prim services with 16 bit uuid and 3 with 128 bit uuids Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 158 ENDSUB //============================================================================== // Ble event handler //============================================================================== FUNCTION HndlrBleMsg(BYVAL nMsgId, BYVAL nCtx) conHndl=nCtx nMsgID==1 THEN PRINT "\n\n- Disconnected" Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 159 ENDIF ENDFUNC //============================================================================== // EVDISCPRIMSVC event handler //============================================================================== FUNCTION HandlerPrimSvc(cHndl,svcUuid,sHndl,eHndl) AS INTEGER PRINT "\nEVDISCPRIMSVC :" PRINT " cHndl=";cHndl Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 160 = StrDehexize$(uuid$) uHndl = BleHandleUuid128(uuid$) OnStartup()==0 THEN PRINT "\nAdvertising, and Gatt Client is open\n" ELSE PRINT "\nFailure OnStartup" Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 161 EVDISCPRIMSVC : cHndl=2804 svcUuid=00000000 sHndl=0 eHndl=0 Scan complete - Disconnected Exiting... BLEDISCSERVICEFIRST and BLEDISCSERVICENEXT are both extension functions. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 162 Set if NOTIFY is enabled Bit 5 Set if INDICATE is enabled Bit 6 Set if AUTHENTICATED_SIGNED_WRITE is enabled Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 163 This is the end attribute handle for the scan and will have been acquired by doing a primary services scan, which returns the start and end handles of services. Interactive Command Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 164 //open the gatt client with default notify/indicate ring buffer size rc==0 THEN : rc = BleGattcOpen(0,0) ENDIF ENDFUNC //============================================================================== Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 165 = BleHandleUuid128(uu$) rc = BleDiscCharFirst(conHndl,uHndl,sAttr,eAttr) rc==0 THEN //HandlerCharDisc() will exit with 0 when operation is complete WAITEVENT Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 166 ENDIF endfunc '//============================================================================== // EVDISCCHAR event handler '//============================================================================== function HandlerCharDisc(cHndl,cUuid,cProp,hVal,isUuid) as integer print "\nEVDISCCHAR :" print " cHndl=";cHndl Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 167 BleHandleUuid128(uuid$) OnStartup()==0 THEN PRINT "\nAdvertising, and Gatt Client is open\n" ELSE PRINT "\nFailure OnStartup" ENDIF WAITEVENT PRINT "\nExiting..." Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 168 EVDISCCHAR : cHndl=3549 chUuid=00000000 Props=0 valHndl=0 ISvcUuid=0 Characteristic Scan complete - Disconnected Exiting... BLEDISCCHARFIRST and BLEDISCCHARNEXT are both extension functions. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 169 On EVDISCDESC event message If Descriptor Handle == 0 then scan is complete Else Process information then call BleDiscDescNext() Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 170 // 5 uuids are 16 bit and 3 are 128 bit // 3 of the 16 bit uuid are the same value 0xDEAD and Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 171 //wait for start and end handles for first primary service WAITEVENT PRINT "\n\nScan for descritors with uuid = 0xDEAD" Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 172 = eHndl rc = BleDiscCharFirst(conHndl,0,sAttr,eAttr) rc != 0 THEN PRINT "\nScan characteristics failed" EXITFUNC ENDIF ENDIF endfunc '//============================================================================== Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 173 EXITFUNC ELSE rc = BleDiscDescNext(cHndl) rc != 0 THEN PRINT "\nDescriptor scan abort" EXITFUNC ENDIF ENDIF endfunc //============================================================================== Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 174 BleHandleUuid128(uuid$) OnStartup()==0 THEN PRINT "\nAdvertising, and Gatt Client is open\n" ELSE PRINT "\nFailure OnStartup" ENDIF WAITEVENT PRINT "\nExiting..." Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 175 EVDISCDESC cHndl=3790 dscUuid=FC033344 dscHndl=8 EVDISCDESC cHndl=3790 dscUuid=00000000 dscHndl=0 Descriptor Scan complete - Disconnected Exiting... BLEDISCDESCFIRST and BLEDISCDESCNEXT are both extension functions. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 176 GATT server for later read/write operations. ‘Included Service Uuid Handle’ is for future use and is always 0. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 177 // 2 of the 128 bit uuids are also the same 112233445566778899AABBCCDDEEFF // Server created using BleGattcTblFindChar.sub invoked in _OpenMcp.scr Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 178 "\n- Connected, so scan remote Gatt Table for an instance of char" uHndS = BleHandleUuid16(0xDEAD) uu$ = "112233445566778899AABBCCDDEEFF00" uu$ = StrDehexize$(uu$) uHndC = BleHandleUuid128(uu$) Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 179 "\nFound the characteristic at handle ";hVal PRINT "\nSvc Idx=";sIdx;" Char Idx=";cIdx ENDIF endfunc //============================================================================== // Main() equivalent //============================================================================== ONEVENT EVBLEMSG CALL HndlrBleMsg Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 180 EVFINDCHAR cHndl=866 Props=0 valHndl=0 ISvcUuid=0 Did NOT find the characteristic - Disconnected Exiting... BLEGATTCFINDCHAR is an extension function. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 181 If Descriptor Handle == 0 then Descriptor not found Else Descriptor has been found Call BleGattcFindDesc() If BleGattcFindDesc() ok then Wait for EVFINDDESC Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 182 // 2 of the 128 bit uuids are also the same 112233445566778899AABBCCDDEEFF // Server created using BleGattcTblFindDesc.sub invoked in _OpenMcp.scr // using Nordic Usb Dongle PC10000 rc,at$,conHndl,uHndl,uuid$,sIdx,cIdx,dIdx //============================================================================== Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 183 StrDehexize$(uu$) uHndD = BleHandleUuid128(uu$) sIdx = 2 cIdx = 1 dIdx = 1 // handle will be 37 Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 184 //Register base uuids with the underlying stack, otherwise the services with the //128bit uuid's will be delivered with a uuid handle == FF000000 == UNKNOWN uuid$ = "112233445566778899AABBCCDDEEFF00" Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 185 Given that the success or failure of this read operation is returned in an event message, a handler must be registered for the EVATTRREAD event. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 186 ATT Error: Reserved for Future Use range #1 end 0x0180 ATT Error: Application range begin 0x019F ATT Error: Application range end Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 187 GATT status code. INTEGER, a result code. Returns Most typical value – 0x0000, indicating a successful read. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 188 //open the gatt client with default notify/indicate ring buffer size rc==0 THEN : rc = BleGattcOpen(0,0) ENDIF ENDFUNC //============================================================================== Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 189 "\nread attibute handle 300 which does not exist" atHndl = 300 nOff = 0 rc=BleGattcRead(conHndl,atHndl,nOff) rc==0 THEN WAITEVENT ENDIF CloseConnections() ENDIF ENDFUNC '//============================================================================== '//============================================================================== Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 190 HandlerAttrRead OnStartup()==0 THEN PRINT "\nAdvertising, and Gatt Client is open\n" ELSE PRINT "\nFailure OnStartup" ENDIF WAITEVENT PRINT "\nExiting..." Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 191 On EVATTWRITE event message If Gatt_Status == 0 then Attribute was written successfully Else Attribute could not be written Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 192 //open the gatt client with default notify/indicate ring buffer size rc==0 THEN : rc = BleGattcOpen(0,0) ENDIF ENDFUNC Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 193 "\nwrite to attibute handle 300 which does not exist" atHndl = 300 rc=BleGattcWrite(conHndl,atHndl,at$) rc==0 THEN WAITEVENT ENDIF CloseConnections() ENDIF ENDFUNC '//============================================================================== '//============================================================================== Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 194 HandlerAttrWrite OnStartup()==0 THEN PRINT "\nAdvertising, and Gatt Client is open\n" ELSE PRINT "\nFailure OnStartup" ENDIF WAITEVENT PRINT "\nExiting..." Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 195 5.10.11.1 EVNOTIFYBUF event This event message is thrown if BleGattcWriteCmd() returned a success. The message contains no parameters. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 196 // Initialise and instantiate service, characteristic, start adverts //============================================================================== FUNCTION OnStartup() rc, adRpt$, addr$, scRpt$ rc=BleAdvRptInit(adRpt$, 2, 0, Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 197 THEN WAITEVENT ENDIF PRINT "\n- write again to attribute handle 3" atHndl = 3 at$="\05\06\07\08" rc=BleGattcWriteCmd(conHndl,atHndl,at$) rc==0 THEN Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 198 OnEvent EVNOTIFYBUF call HandlerNotifyBuf OnStartup()==0 THEN PRINT "\nAdvertising, and Gatt Client is open\n" ELSE PRINT "\nFailure OnStartup" ENDIF Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 199 BleGattNotifyRead() is called to extract data from the ring buffer to create space and it triggers a delayed acknowledgement. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 200 If non-zero values are encountered, it is recommended that the ring buffer size be increased by using BleGattcClose() when the GATT client is opened using BleGattcOpen(). Interactive Command Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 201 // Close connections so that we can run another app without problems //============================================================================== CloseConnections() rc=BleDisconnect(conHndl) rc=BleAdvertStop() ENDSUB //============================================================================== // Ble event handler //============================================================================== FUNCTION HndlrBleMsg(BYVAL nMsgId, BYVAL nCtx) Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 202 == 0 then print "\nAttribute write OK" else print "\nFailed to write attribute" endif endfunc Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 203 HandlerAttrNotify OnStartup()==0 THEN PRINT "\nAdvertising, and Gatt Client is open\n" ELSE PRINT "\nFailure OnStartup" ENDIF WAITEVENT PRINT "\nExiting..." Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 204: Attribute Encoding Functions

    This is reflected in smartBASIC applications so that INTEGER variables are used to manipulate those values instead of STRINGS. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 205 //write 'C' to index 2 -- '111' will be ignored rc=BleEncode8(attr$,0x11143,2) //write 'A' to index 0 rc=BleEncode8(attr$,0x41,0) //write 'B' to index 1 Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 206 If the extended length exceeds the maximum allowable length of an attribute (see SYSINFO(2013)), this function fails. Interactive Command //Example :: BleEncode16.sb (See in RM1xxCodeSnippets.zip) Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 207 If the extended length exceeds the maximum allowable length of an attribute (see SYSINFO(2013)), this function fails. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 208 This argument is the string that is written to an attribute nData byVal nData AS INTEGER The four bytes of this integer is saved. The rest is ignored. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 209 Most typical value – 0x0000, indicating a successful operation. Arguments attr$ byRef attr$ AS STRING This argument is the string that is written to an attribute. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 210 //because the mantissa is too large, it has to be < 8388600 BleEncodeFLOAT(attr$,10000000,0,2)!=0 THEN PRINT "\nFailed to encode to FLOAT" ENDIF Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 211 //Example :: BleEncodeSFloatEx.sb (See in RM1xxCodeSnippets.zip) rc, mantissa, exp attr$ : attr$="" //write 2,147,483,647 as SFLOAT to index 0 rc=BleEncodeSFloatEX(attr$,2147483647,0) Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 212 If the new length exceeds the maximum allowable length of an attribute (see SYSINFO(2013)), this function fails. Interactive Command Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 213 When the attr$ string variable is updated, the two-byte year field is converted into a 16-bit integer. Hence \14\0D gets converted to \DD\07 Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 214 The maximum length of an attribute as implemented can be obtained using the function SYSINFO(n) where n is 2013. The Bluetooth specification allows a length between 1 and 512. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 215 If the nIndex is such that the new string length exceeds the maximum attribute length, this function fails. The maximum length of an attribute as implemented can be obtained using the function SYSINFO(n) Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 216: Attribute Decoding Functions

    This section describes decoding functions that allow attribute strings to be read from smaller bytewise subfields more efficiently than the generic STRXXXX functions that are made available in smartBASIC. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 217 //create char and commit as part of service commited above rc=BleCharNew(0x07,BleHandleUuid16(0x2A1C),mdVal,0,0) rc=BleCharCommit(svcHandle,attr$,chrHandle) rc=BleCharValueRead(chrHandle,attr$) //read signed byte from index 2 Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 218 Interactive Command //Example :: BleDecodeU8.sb (See in RM1xxCodeSnippets.zip) Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 219 Decimal = 2 data in Hex = 0x00000086 data in Decimal = 134 BLEDECODEU8 is an extension function. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 220 "\ndata in Hex = 0x"; INTEGER.H'v1 PRINT "\ndata in Decimal = "; v1;"\n" //read 2 signed bytes from index 6 Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 221 //Example :: BleDecodeU16.sb (See in RM1xxCodeSnippets.zip) chrHandle,v1,svcHandle,rc mdVal : mdVal = BleAttrMetadata(1,1,50,0,rc) attr$ : attr$="\00\01\02\03\04\85\86\87\88\89" uuid : uuid = 0x1853 Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 222 AS INTEGER This references an integer to be updated with the 3-byte data from attr$, with sign extension. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 223 Decimal = 262914 data in Hex = 0xFF888786 data in Decimal = -7829626 BLEDECODES24 is an extension function. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 224 "\ndata in Hex = 0x"; INTEGER.H'v1 PRINT "\ndata in Decimal = "; v1;"\n" //read 3 unsigned bytes from index 6 Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 225 //Example :: BleDecode32.sb (See in RM1xxCodeSnippets.zip) chrHandle,v1,svcHandle,rc mdVal : mdVal = BleAttrMetadata(1,1,50,0,rc) attr$ : attr$="\00\01\02\03\04\85\86\87\88\89" uuid : uuid = 0x1853 rc=BleSvcCommit(1, BleHandleUuid16(uuid),svcHandle) Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 226 Arguments attr$ byRef attr$ AS STRING This references the attribute string from which the function reads. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 227 //read 4 bytes FLOAT from index 6 in the string rc=BleDecodeFloat(attr$,mantissa,exp,6) PRINT "\nThe number read is ";mantissa;"x 10^";exp Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 228 //Example :: BleDecodeSFloat.sb (See in RM1xxCodeSnippets.zip) chrHandle,v1,svcHandle,rc, mantissa, exp mdVal : mdVal = BleAttrMetadata(1,1,50,0,rc) attr$ : attr$="\00\01\02\03\04\85\86\87\88\89" uuid : uuid = 0x1853 Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 229 On exit this is an exact 7-byte string as described above. For example, 5 May 2013 10:31:24 is stored as \14\0D\05\05\0A\1F\18. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 230 INTEGER, the number of bytes extracted from the attribute string. Can be less than the size Returns expected if the nIndex parameter is positioned towards the end of the string. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 231 //read max 4 bytes from index 14 in the string - nothing at index 14 rc=BleDecodeSTRING(attr$,14,decStr$,4) PRINT "\nd$=";decStr$ Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 232 Interactive Command //Example :: BleDecodeBits.sb (See in RM1xxCodeSnippets.zip) chrHandle,v1,svcHandle,rc, ts$,decStr$ ba : ba=0 mdVal : mdVal = BleAttrMetadata(1,1,50,0,rc) Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 233: Pairing/Bonding Functions

    AT I 2012 or at runtime SYSINFO(2012) returns the maximum number of devices that can be saved in the database Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 234 ‘youngest’ in the age list. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 235 Bluetooth connection. That mode of pairing is currently not exposed. Laird have provided an additional mechanism for bonding using the standard inbuilt simple secure pairing which is called Whisper Mode pairing. In this mode, when a pairing is detected to be in progress, the transmit power is automatically reduced so that the ‘bubble’...
  • Page 236 This function deletes the entire trusted device database. Other values of the parameter are reserved for future use. Note: In Interactive Mode, the command AT+BTD* can also be used to delete the database. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 237 This is the address of the device for which the bonding information is to be marked as persistent Interactive Command //Example rc, addr$ addr$=”\00\00\16\A4\12\34\56” rc = BleBondingPersistKey(addr$) BLEBONDINGPERISTKEY is an extension function. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 238 Interactive Command //Example rc, addr$ addr$=”\00\00\16\A4\12\34\56” rc = BleBondingPersistKey(addr$) BLEBONDINGISTRUSTED is an extension function. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 239 //Extract info of device at index 1 rc==0 THEN PRINT "\nMAC address: ";addr$ PRINT "\nInfo: ";exInfo ELSEIF rc==BLE_INV_INDEX THEN PRINT "\nInvalid index" ENDIF Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 240: Other Extension Built-In Routines

    //Example :: SystemStateSet.sb (See in RM1xxCodeSnippets.zip) //Put the module into deep sleep PRINT "\n"; SystemStateSet(0) SYSTEMSTATESET is an extension function. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 241: Miscellaneous Routines

    The BLE_EVMSG event is thrown to the engine if the supply voltage drops below this value. Valid values are 2100, 2300, 2500 and 2700. Interactive Command Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 242 ReadPwrSupplyMv();"mV\n" mv=2700 rc=SetPwrSupplyThreshMv(mv) PRINT "\nWaiting for power supply to fall below ";mv;"mV" //wait for events and messages WAITEVENT Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 243: Events And Messages

    To read current values of these objects use the command AT+CFG, described here. Predefined configuration objects are as listed under details of the AT+CFG command. Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 244: Miscellaneous

    BLE_HCI_REMOTE_DEV_TERMINATION_DUE_TO_LOW_RESOURCES 0x14 BLE_HCI_REMOTE_DEV_TERMINATION_DUE_TO_POWER_OFF 0x15 BLE_HCI_LOCAL_HOST_TERMINATED_CONNECTION 0x16 BLE_HCI_REPEATED_ATTEMPTS 0x17 BLE_HCI_PAIRING_NOTALLOWED 0x18 BLE_HCI_LMP_PDU 0x19 BLE_HCI_UNSUPPORTED_REMOTE_FEATURE 0x1A BLE_HCI_SCO_OFFSET_REJECTED 0x1B BLE_HCI_SCO_INTERVAL_REJECTED 0x1C Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 245 BLE_HCI_EXTENDED_INQUIRY_RESP_TOO_LARGE 0x36 BLE_HCI_SSP_NOT_SUPPORTED_BY_HOST 0x37 BLE_HCI_HOST_BUSY_PAIRING 0x38 BLE_HCI_CONN_REJ_DUETO_NO_SUITABLE_CHN_FOUND 0x39 BLE_HCI_CONTROLLER_BUSY 0x3A BLE_HCI_CONN_INTERVAL_UNACCEPTABLE 0x3B BLE_HCI_DIRECTED_ADVERTISER_TIMEOUT 0x3C BLE_HCI_CONN_TERMINATED_DUE_TO_MIC_FAILURE 0x3D BLE_HCI_CONN_FAILED_TO_BE_ESTABLISHED 0x3E Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 246: Acknowledgements

    The following are required acknowledgements to address our use of open source code on the RM1xx to implement AES encryption. Laird’s implementation includes the following files: aes.c and aes.h. Copyright (c) 1998-2008, Brian Gladman, Worcester, UK. All rights reserved. 10.1 License Terms...
  • Page 247: Index Of Smartbasic Commands

    BLEWHITELISTCREATE ..........82 BleEncode24 ............208 Bluetooth Result Codes ......... 245 BleEncode32 ............209 Decoding Functions ..........217 Americas: +1-800-492-2320 Connectivity Solutions Support Center: Europe: +44-1628-858-940 http://ews-support.lairdtech.com Hong Kong: +852 2923 0610 www.lairdtech.com/ramp © Copyright 2016 Laird. All Rights Reserved...
  • Page 248 All specifications are subject to change without notice. Responsibility for the use and application of Laird materials or products rests with the end user since Laird and its agents cannot be aware of all potential uses. Laird makes no warranties as to non-infringement nor as to the fitness, merchantability, or sustainability of any Laird materials or products for any specific or general uses.

Table of Contents