GithubHelp home page GithubHelp logo

willee / bluestsdk_ios Goto Github PK

View Code? Open in Web Editor NEW

This project forked from stmicroelectronics/bluestsdk_ios

0.0 2.0 0.0 1.81 MB

Bluetooth low energy Sensors Technology Software Development Kit (iOSversion)

License: BSD 3-Clause "New" or "Revised" License

Objective-C 100.00%

bluestsdk_ios's Introduction

#BlueST SDK

BlueST is a multi-platform library (Android and iOS supported) that permits easy access to the data exported by a Bluetooth Low Energy (BLE) device that implements the BlueST protocol.

##BlueST Protocol

###Advertise The library will show only the device that has a vendor-specific field formatted in the following way:

Length 1 1 1 1 4 6
Name Length Field Type Protocol Version Device Id Feature Mask Device MAC (optional)
Value 0x07/0xD 0xFF 0x01 0xXX 0xXXXXXXXX 0xXXXXXXXXXXXX
  • The Field Length must be 7 or 13 bytes long.

  • The Device Id is a number that identifies the type of device. It is used to select different types of feature mask and can manage more than 32 features. Currently used values are:

    • 0x00 for a generic device
    • 0x01 is reserved for the STEVAL-WESU1 board
    • 0x80 for a generic Nucleo board
    • 0x81 for a Nucleo board exporting remote feature

You should use a value between 0x02 and 0x7F for your custom board, as values between 0x80 and 0xFF are reserved for ST Nucleo boards.

  • The feature mask is a bit field that provides information regarding what characteristics/features are exported by the board. Currently, bits are mapped in the following way:

    Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
    Feature RFU ADPCM Audio sync Switch Direction of arrival ADPCM Audio MicLevel Proximity Lux Acc Gyro Mag Pressure Humidity Temperature Battery Second Temperature
    Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
    Feature RFU RFU RFU RFU RFU AccEvent FreeFall Sensor Fusion Compact Sensor Fusion RFU RFU Activity Carry Position ProximityGesture MemsGesture Pedometer

You can use one of the RFU bits or define a new device and decide how to map the feature. To see how the data is exported by pre-defined features, consult the export method Feature.ExtractResult Feature.extractData(long,byte[],int). within the feature class definition.

  • The device MAC address is optional and useful only for obtaining the device MAC address on an iOS device.

Characteristics/Features

The characteristics managed by the SDK must have a UUID such as: XXXXXXXX-0001-11e1-ac36-0002a5d5c51b. The SDK will scan all the services, searching for characteristics that match that pattern.

The first part of the UUID will have the bit set to 1 for each feature exported by the characteristics.

In case of multiple features mapped in a single characteristic, the data must be in the same order as the bit mask.

The characteristic data format must be:

Length 2 >1 >1
Name Timestamp First Feature Data Second Feature Data .....

The first 2 bytes are used to communicate a time stamp. This is especially useful for recognizing any data loss.

Since the BLE packet max length is 20 bytes, the max size for a feature data field is 18 bytes.

Remote Feature

This type of Feature are created for handle the case when the node collect information from other boards the user want to know also how produced the data.

For this type of feature a node ID is attach at the beginning of a standard feature update message.

For this type of feature the characteristic data format must be:

Length 2 2 >1
Name NodeID Remote timestamp Feature Data .....

###Special Services ####Debug If available, the debug service must have the UUID 0000000-0000E-11e1-9ab4-0002a5d5c51b and will contains 2 characteristics:

  • 00000001-000E-11e1-ac36-0002a5d5c51b (Notify/Write) is used to send string commands to the board and to notify the user of the result.
  • 00000002-000E-11e1-ac36-0002a5d5c51b (Notify) is used by the board to notify the user of an error message.

####Configuration If available, the configuration service must have the UUID 00000000-000F-11e1-9ab4-0002a5d5c51b and will contain 2 characteristics:

  • 00000002-000F-11e1-ac36-0002a5d5c51b (Notify/Write): it can be used to send command/data to a specific feature.

    The request message must have the following format:

    Length 4 1 0-15
    Name Destination Feature Mask Command Id Command Data

    Where the first 4 bytes will select the recipient of the command/data package.

    The optional command answer must have the following format:

    Length 2 4 1 0-13
    Name Timestamp Sender Feature Mask Command Id Answer Data

    From the SDK point of view the messages are sent using the method BlueSTSDKFeature::sendCommand:data: and the answer is notified with a callback passed through the method BlueSTSDKFeature::parseCommandResponseWithTimestamp:commandType::data:.

    If this characteristic does not exist, but the characteristics that export the feature is in write mode, the command id and the command data are sending directly to the feature characteristics. In this case is not possible answer to the command.

  • 00000001-000F-11e1-ac36-0002a5d5c51b (Read/Write/Notify): if available it is used to access the board configuration register that can be modified using the BlueSTSDKConfigControl class.

###Example The ST Bluemicrosystem1 and ST Bluemicrosystem3 firmware implements this protocol, you can find the project source here: Bluemicrosystem

##How to install the library ###As an external library

  1. Clone the repository or add it as submodule:
$ git submodule add https://github.com/STMicroelectronics-CentralLabs/BlueSTSDK_iOS.git BlueSTSDK
  1. In the application project, in the general tab, file open the BlueSTSDK project file as "Linked external frameworks or library"
  2. Add the BlueSTSDK framework as enbeded library

##Main library actors

###Manager This is a singleton class that starts/stops the discovery process and stores the retrieved nodes. Before starting the scanning process, it is also possible to define a new deviceId and to register/add new features to already-defined devices

The Manager will notify a node discovery through the BlueSTSDKManagerDelegate delegate. Note that each callback is performed asynchronously by a background thread.

###Node This class represents a remote device.

From this class you can recover what features are exported by a node and read/write data from/to the device. The node will export all the features that are set to 1 in the advertise message. Once the device is connected, scanning and enabling of available characteristics are performed. At this point it is possible to request/send data related to the discovered features.

A node notifies its RSSI (signal strength) through the BlueSTSDKNodeBleConnectionParamDelegate delegate. A node notifies any change of its state through the BlueSTSDKNodeStateDelegate delegate.

A node can be in one of following states:

  • Idle: the node is waiting for a connection and sending an advertise message
  • Connecting: a connection with the node was triggered, the node is performing the discovery of device services/characteristics
  • Connected: connection with the node was successful. Note: this status can be fired twice if a secure connection with BLE pairing was performed
  • Disconnecting: ongoing disconnection, once disconnected the node goes back to the idle state
  • Lost: the device sent an advertise, however currently it is not reachable
  • Unreachable: we were connected with the node, however we lost the connection

Note that each callback is performed asynchronously by a background thread.

###Feature This class represent data exported by the node.

Each Feature has an array of BlueSTSDKFeatureField that describes the data exported.

Data are received from a BLE characteristic and contained in a class BlueSTSDKFeatureSample. The user is notified of data using a listener pattern.

The data exported by the Sample can be extracted using the static utility methods of the class.

Note that each callback is performed asynchronously by a background thread.

####How to add a new Feature

  1. Extend the class Feature:

    1. Implement the getFieldDesc that usually return an static array of BlueSTSDKFeatureField that that will describe the data exported by the new feature
    2. Create a constructor that accepts only the node as parameter. From this constructor call the super constructor, passing the feature name.
    3. Implement the method BlueSTSDKFeature::extractData:data:dataOffset.
    4. Create a utility static method that extracts the data from the BlueSTSDKFeatureSample class
  2. Before start the scanning register the new feature

    // add the feature to the Nucleo device
    uint8_t deviceId = 0x80;
    // the feature will be mapped in the characteristic 
    // 0x10000000-0001-11e1-ac36-0002a5d5c51b
    NSDictionary * temp = @{
        @0x10000000: [MyNewFeature class]
    };
    
    BlueSTSDKManager *manager = [BlueSTSDKManager sharedInstance];
    [manager addFeatureForBoard:deviceId features:temp];
    

    Otherwise you can register the characteristics before call the connect method:

    BlueSTSDKNode *node = ...;
    NSDictionary *map = [BlueSTSDKStdCharToFeatureMap getManageStdCharacteristics];
    [node addExternalCharacteristics: map];

##Docs You can find the documentation at this link: Documentation

##License COPYRIGHT(c) 2015 STMicroelectronics

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of STMicroelectronics nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

bluestsdk_ios's People

Contributors

araucea avatar giovannivisentinist avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.