<Notify/Indicate Features>

We have new notify/indicate features implemented in the BIG Smart Server that will be included in the next release. In this guide we will how you how to get notifications/indications using curl commands on Cygwin. For a basic guide of how to use the BIG RESTful Smart Server please refer to the following blog.

BIG RESTful Smart Server Demo

 

In this example, we will sign up for notifications for the heart rate value on a virtual heart rate monitor device on iOS LightBlue. This was verified in SDK 3.5.2 on BCM943341WCD1. Please download the attached patch and copy the three files over to <SDK>/libraries/daemons/bt_internet_gateway/restful_smart_server.

 

<Prerequisites>

  1. Scan for devices

          a. curl -v -X GET “http://<BIG_SERVER_ADDR>/gap/nodes?passive=1

 

          b. If you add the following options to the curl command when you scan, it will skip the redundancies and only print out unique device handles.

 

          c. curl -v -X GET "http:// <BIG_SERVER_ADDR>/gap/nodes?passive=1" 2>/dev/null | grep handle | sort -u

scan_unique.png

 

   d. You might get multiple handles if you are in a busy environment. In order to narrow down the possibility of the handles that could be the device you wish to test, try running the above (c) command without your device powered up (or deactivated in LightBlue), and do another scan with the device powered up. Then you can run the command (a) and check the RSSI value associated with the possible handles. The one with the highest signal strength should be your device if it is set close to your WICED device.

 

      **NOTE: Using a LightBlue virtual peripheral device, the BD_ADDR handle can change after disconnection so be sure to scan and check the BD_ADDR handle again.

 

     2. Connect to BLE device

          a. curl -v -X PUT "http://<BIG_SERVER_ADDR>/gap/nodes/<node_handle>?connect=1"

 

     3. Perform primary service discovery

          a. curl -v -X GET “http://<BIG_SERVER_ADDR>/gatt/nodes/<node_handle>/services?primary=1”    

 

          **NOTE: Same with BD_ADDR, service handles might change after disconnection on the same LightBlue devices. The uuids will stay the same though.

 

     4. Perform characteristic discovery of the service

          c. curl -v -X GET "http://<BIG_SERVER_ADDR>/gatt/nodes/<node_handle>/services/<service_ref_handle>/characteristics"

 

          **NOTE: Same with BD_ADDR, service handles might change after disconnection on the same LightBlue devices. The uuids will stay the same though.

    **NOTE: in the service and characteristic handle, you need to use the values on the end of “self” : { “href”: …/003700360035”}, instead of the 4 digit “handle” number.

          handle.png

 

<Notify/Indicate>

Now you should have all the handles you need to sign up for the desired characteristic. You can follow the steps below to turn on notify/indicate and you will see the results streaming into your WICED device.

  1. Enable Notify or Indicate

          a.      curl -v -X GET “http://<BIG_SERVER_ADDR>/gatt/nodes/<node_handle>/characteristics/<characteristic_ref_handle>?notify=1

          b.      curl -v -X GET “http://<BIG_SERVER_ADDR>/gatt/nodes/<node_handle>/characteristics/<characteristic_ref_handle>?indicate=1

 

          **NOTE: Check if your device characteristic has the notify/indicate property. It will show as the following in LightBlue.

          LightBlue.jpg

 

    2. Subscribe to Notify or Indicate and wait for notifications / indications

          a.      curl -v -X GET “http://<BIG_SERVER_ADDR>/gatt/nodes/<node_handle>/characteristics/<characteristic_ref_handle>/value?notify=1&event=1

          b.      curl -v -X GET "http://<BIG_SERVER_ADDR>/gatt/nodes/<node_handle>/characteristics/<characteristic_ref_handle>/value?indicate=1&event=1"

 

     3. Results

     This is the reply you should be getting afterwards. You will see the notify values streaming in through your device. In the below screen I am manually changing the numbers on LightBlue. 

 

* STATE: DO => DO_DONE handle 0x600057380; line 1337 (connection #0)

* STATE: DO_DONE => WAITPERFORM handle 0x600057380; line 1464 (connection #0)

* STATE: WAITPERFORM => PERFORM handle 0x600057380; line 1474 (connection #0)

* HTTP 1.1 or later with persistent connection, pipelining supported

< HTTP/1.1 200 OK

< Content-Type: text/event-stream

< Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0

< Pragma: no-cache

< Connection: Keep-Alive

* no chunk, no close, no size. Assume close to signal end

<

data: 0050

 

data: 0064

 

data: 0064

 

data: 0064

 

data: 0078

 

data: 0078

 

data: 0078

 

data: 0078

 

data: 1111

 

data: 0078

 

data: 0078

 

data: 0078

 

data: 2222

 

data: 0078

 

data: 0078

 

data: 3333

 

...

 

<Scripts>

One thing to keep in mind is that if you are testing with LightBlue, connection will be dropped quickly so you will have to use a script to process all the commands within the time frame. From the moment you lose connection and reconnect again, the BD_ADDR or the handles for services and characteristics could change so you will have to double check them. For this reason it will be easier to maintain the connection using scripts. Make a file run_notification.bat and copy the following contents. You can run it as

>run_notification.bat <BD_ADDR>

 

and you will have to change addr, serv(service) and char(characteristic) in the file accordingly to the device and characteristic you are using.

 

addr=10.14.12.163

serv=00F40047

char=00F4004E004D

curl -v -X PUT "http://$addr/gap/nodes/$1?connect=1&enable=1"

curl -v -X GET "http://$addr/gatt/nodes/$1/services?primary=1&uuid=180D"

curl -v -X GET "http://$addr/gatt/nodes/$1/services/$serv/characteristics"

 

curl -v -X GET "http://$addr/gatt/nodes/$1/characteristics/$char?notify=1"

curl -v -X GET http://$addr/gatt/nodes/$1/characteristics/$char/value?notify=1&event=