Current location - Loan Platform Complete Network - Big data management - Hybrid APP low power bluetooth project parsing data may be used in some small way --- ble
Hybrid APP low power bluetooth project parsing data may be used in some small way --- ble

Can be used to interact with third-party Bluetooth devices, must support Bluetooth 4.0.

On iOS: Hardware at least iphone4s, system at least iOS6.

On android: System version at least android4.3.

Bluetooth 4.0 is known for its low-power consumption, and is generally also called BLE ( BluetoothLowEnergy). Currently, there are more cases of application: bad sports hand, embedded devices, smart home

In Bluetooth communication, there are two main parts, Central and Peripheral, a little similar to the Client Server, Peripheral as a peripheral device is a server, and Central as a central device is a client. All available Bluetooth devices can be either Peripheral or Central, but not both Peripheral and Central at the same time.

Generally, the phone is the client, and the device (e.g., the bracelet) is the server, because it is the phone that connects to the bracelet as the server. The Peripheral is the device that generates or stores the data, and the Central is the device that uses the data. You can think of the Peripheral as a device that broadcasts data to the outside world that it has data here and also describes the services it can provide. On the other side, Central starts scanning the neighborhood for services, and if Central finds a service it wants, then Central requests a connection to the perimeter, and once the connection is established, the two devices start exchanging and transferring data.

In addition to the center and the perimeter, we have to consider the structure of the data that they exchange. This data is structured in services, each of which consists of different Characteristics, which are types of attributes that contain a single logical value.

Characteristics were mentioned above, so here is a brief explanation of what they are.

Characteristics are the smallest unit of interaction with the outside world. A Bluetooth 4.0 device describes itself in terms of Services, Characteristics, and Descriptors. The same device may contain one or more Services, with several Characteristics under each Service, and several Descriptors under each Characteristic. For example, a Bluetooth 4.0 device uses feature A to describe device information, feature B and descriptor b to send and receive data. Each service, feature, and descriptor is distinguished and identified by a UUID.

source ==> string

count ==> number of bits to cut

Converting incoming ios data

Initializing Bluetooth 4.0 Manager =>. initManager

Search for Bluetooth 4.0 devices, the module will constantly scan and update the information of nearby Bluetooth 4.0 devices internally => scan

Note: Parameters: single Type: boolean true for singleton mode, false for non-singleton mode. false for non-single mode; default is false; Description: (optional) then scan for all nearby devices that support Bluetooth 4.0 Type: parmas: boolean true for single mode, false for non-single mode; default is false; non-single mode is only effective for connections on this page, single mode is effective globally for the entire app after a successful connection

Get information about a Bluetooth 4.0 device.

Get information about all currently scanned peripherals => getPeripheral

Connect to the specified peripheral. iOS doesn't have a timeout, android has a 30 second timeout by default => connect

Get all the services of a given peripheral based on its UUID => discoverService

Get all the Characteristic of a given peripheral based on its UUID and its service UUID. => discoverCharacteristics

Listen for data callbacks based on the specified peripheral UUID and its service UUID and Characteristic UUID => setNotify

Listen for data callbacks based on the specified Write data based on the specified peripheral UUID and its service UUID and Characteristic UUID => writeValueForCharacteristic

Remaining methods to be used on demand

This development needs to pass bytes as well as ASCII codes.