The method with Bluetooth communication compatibility between flash memory IoT equipment and Android device of solution
Technical field
The present invention relates to Bluetooth communication fields, more particularly to a kind of IoT for having flash (flash memory, generally as external memory)
(Internet of Things, Internet of Things) Bluetooth communication compatibility solution between equipment and Android device.
Background technique
With the development of IoT technology, the industry using IoT technology is more and more, including manufactures industry, consumer electronics
Industry, medical treatment & health industry etc..The development of IoT develops our life towards more automation, intelligentized direction, gives life band
Carry out bigger convenience, it is following to become a part indispensable in our lives.The network that IoT is connected as object object, nothing
Line communication technology is particularly significant, bluetooth with its inexpensive, it is low in energy consumption the features such as become a kind of nothing that IoT equipment more welcomes
Line communication protocol.However, there are some compatibility issues also to hinder its development to a certain degree for bluetooth, and such as: connection cannot
The problems such as establishing, disconnecting often, these problems become one of the emphasis of Bluetooth domain research.
There is bluetooth module in IoT equipment, bluetooth module can be attached with Android device by bluetooth, at Android device end
IoT equipment is managed, is supervised, data analysis etc..General IoT equipment is used as from equipment, and Android device is as main equipment, example
Such as: wearable smartwatch is managed wrist-watch by Android mobile phone.But at present with flash IoT equipment be used as from
When carrying out Bluetooth communication between equipment and Android device, need to carry out flash erasable operation and serious compatibility is caused to be asked
Topic, bluetooth compatibility issue is more significant especially in software development process.The compatibility issue of Bluetooth communication refers to, has
The IoT equipment of flash can only carry out stable Bluetooth communication with the Android device of certain particular vendor specific models, for some
Android device, even with the operating system of identical version, under identical environment, the IoT equipment with flash with these
When Android device carries out Bluetooth communication, it may appear that the phenomenon that bluetooth connection is unstable, frequently cuts off.Lead to the problem of this main original
Because being: when IoT equipment and Android device carry out Bluetooth communication, main equipment is usually used as by Android device, IoT equipment as from
Equipment, Bluetooth connection parameter are determined by main equipment (Android device), can only passively receive these connection ginsengs from equipment (IoT equipment)
Number.Meanwhile when IoT equipment to flash carry out erasable operation when, due to erasable needs of the IoT equipment to flash it is certain when
Between, cause IoT equipment to require the Connecting quantity of bluetooth connection event, if IoT equipment is to the erasable time BELAND of flash
The connection interval (Connection Interval) of tooth connection event is long, may cause bluetooth connection event and is skipped, it is also possible to
The access to flash is caused to be postponed.The Connecting quantity defined in Bluetooth protocol haves a wide reach, and each Android manufacturer is realizing indigo plant
The Connecting quantity disunity defined when tooth function, therefore IoT equipment carries out the connection used when bluetooth connection from different Android devices
Parameter disunity, the Connecting quantity for not being able to satisfy erasable operation of the IoT equipment to flash will cause bluetooth connection time-out or blue
Tooth connection disconnects and causes compatibility issue.Lance between overcoming bluetooth connection interval and flash to store access it would therefore be desirable to have one kind
The method of shield, thus solve bluetooth mutual communication exception between IoT equipment and different vendor's Android device with flash and generate
Compatibility issue.The solution of relevant issues is not yet found from the data published at present.
One bluetooth connection event refers to the process of main equipment and from mutually sending data packet between equipment, main equipment and from
Equipment is established after connection, and all data communications are carried out in connection event (Connection Events).Bluetooth
A variety of connection events are defined in agreement, including event is established in connection, Connecting quantity updates request event, Connecting quantity updates
Event and some user's customized events etc..Although being defined in Bluetooth protocol a variety of different to realize different functions
Event, but in the realization of bluetooth applications, some functions are not essential functions, i.e., are not that each connection event can all be answered
With, such as Connecting quantity updates request event, this event is not all applied in most of bluetooth equipments, so that Connecting quantity only exists
It is determined when establishing connection by main equipment.
Connecting quantity update event is the connection event initiated by main equipment, and Connecting quantity is determined by main equipment, from equipment
It can only receive and use these Connecting quantities, or disconnect.If the Connecting quantity current from equipment desired modifications, can
To initiate the connection parameter updating request event to main equipment.Connecting quantity updates request event and is only used for sending out from equipment to main equipment
It send, if the event is sent by main equipment, a mistake can be regarded as from equipment.Ginseng can be sent at any time from equipment
Number updates request event, if the main equipment for receiving the connection event agrees to modification Connecting quantity, will return to Connecting quantity more
New response events, carrying result parameter is " receiving ".Then, main equipment starts Connecting quantity update event.If main equipment is not
Agree to update from the Connecting quantity of equipment and request, then sends the Connecting quantity that result parameter is " refusal " and update response events to refuse
Request absolutely.From equipment, there are two selections at this time: receiving Connecting quantity currently in use or terminates connection.Currently, Android device
When as main equipment, it can all receive to update from the Connecting quantity of equipment and request, to make to set with master from equipment (IoT equipment)
The standby negotiation for being attached parameter main equipment and can be used full after initiating the connection parameter updating request from equipment from equipment
Foot carries out Bluetooth communication from the Connecting quantity of equipment requirement.
Summary of the invention
The technical problem to be solved by the present invention is providing a kind of IoT equipment and different vendor's Android solved with flash
The compatible method of equipment room Bluetooth communication guarantees that IoT equipment when carrying out bluetooth connection with different vendor's Android device, can have
Effect supports the operation stored to IoT equipment to flash, and bluetooth is kept to be in connection status.
The technical scheme is that
For the exploitation of IoT equipment, design the flash memory compatible modules used by IoT equipment (i.e. from equipment), make from
Equipment can be attached the negotiation of parameter with main equipment, to solve rushing between bluetooth connection interval and flash storage access
Prominent problem.
Specific step is as follows:
The first step designs a flash memory compatible modules, is connected with the bluetooth module in IoT equipment, carries out in IoT equipment
When connection event processing, negotiates Connecting quantity by flash memory compatible modules and Android device, meet Connecting quantity in IoT equipment
The requirement of flash storage access.Flash memory compatible modules update processing mould by initialization module, parameter updating request module and parameter
Block composition.
Initialization module updates processing module with parameter updating request module and parameter and is connected, and function is asked for parameter update
Modulus block provides Connecting quantity, updates processing module for parameter and provides Connecting quantity and connection mode mark.
Connecting quantity includes connection interval (wishing that main equipment allows to send the frequency of data packet from equipment from equipment), from setting
Standby retardation coefficient (can ignore that the maximum value of the connection event number of main equipment from equipment) and supervision time-out time are (from equipment
The maximum time for keeping connecting there is no communication with main equipment).
There are three types of connection mode marks, i.e. unknown pattern mark, fast connection mode mark and connection mode mark at a slow speed,
Respectively correspond unknown pattern, at a slow speed connection mode and fast connection mode.Unknown pattern mark refers to from the not no company of initiation of equipment
The connection mode mark used when connecing parameter updating request;Fast connection mode mark is quickly connected from equipment to main equipment initiation
The connection mode mark used after parameter updating request is connect, the connection interval of connection event is shorter at this time (only meets master-slave equipment
Between normal communication Smallest connection interval) or it is smaller (being traditionally arranged to be 0) from equipment retardation coefficient, need to handle in bluetooth module
When mass data, the treatment effeciency to connection event can be improved using fast connection mode between master-slave equipment;Connect at a slow speed
Connecing mode flags is to initiate Connecting quantity at a slow speed to main equipment from equipment to update the connection mode mark used after request, Zhu Congshe
When between standby using connection mode at a slow speed, Connecting quantity of the Connecting quantity relative to fast connection mode, between the connection of connection event
Every it is longer or from equipment retardation coefficient it is larger, this mode can reduce from equipment processing bluetooth event frequency, thus reduce from
The power consumption of equipment.As from the IoT equipment of equipment be generally battery power supply or charging it is more difficult, energy conservation it is very heavy to IoT equipment
It wants, when bluetooth module does not have data to need to handle or have low volume data to need to handle, connection mode can reduce bluetooth at a slow speed
The energy consumption of module.
Parameter updating request module is connected with initialization module and bluetooth module;Parameter updating request module is from bluetooth module
It receives connection and establishes event or big data event (the customized connection event for needing to handle mass data of user), if received
It is that event is established in connection, is that connection mode mark will if received is big data event at a slow speed by connection mode traffic sign placement
Connection mode traffic sign placement is fast connection mode mark, and connection mode mark is sent to initialization module;Meanwhile parameter
It updates request module and obtains Connecting quantity from initialization module, Connecting quantity is stored in after bluetooth module and sends company to bluetooth module
Parameter updating request is connect, Connecting quantity is sent to main equipment from bluetooth module and updates request event, carry Connecting quantity.
Parameter updates processing module and is connected with initialization module and bluetooth module, and function is the company judged in initialization module
It connects whether parameter is updated successfully, if success, keeps connection with new Connecting quantity, if unsuccessful, sent to bluetooth module
Order is disconnected, disconnects bluetooth module with main equipment.Parameter updates processing module and obtains connection from initialization module
Parameter and connection mode mark return to the Connecting quantity obtained from initialization module with the main equipment obtained from bluetooth module
Connecting quantity is compared, if the connection that main equipment returns is spaced Smallest connection interval and most Dalian not in initialization module
It connects in the range of being spaced and (is less than the Smallest connection interval in initialization module or is greater than maximum connection and be spaced), then to bluetooth mould
Block transmission disconnects order, disconnects bluetooth module with main equipment, if the connection that main equipment returns is spaced in initialization
Smallest connection interval in module (is more than or equal between the Smallest connection in initialization module in the range of connecting interval with maximum
Every and less than or equal to maximum connection interval), then it is not processed, bluetooth module continues and main equipment keeps connecting.
Second step, initialization module initialization Connecting quantity and connection mode mark, connection mode mark are initialized as not
Know mode, Connecting quantity is arranged by developer, and method is: connection interval can be the arbitrary value in 7.5ms~4s, but necessary
For the integral multiple of 1.25ms;It can be 0~499 from equipment retardation coefficient range;Supervising time-out time range is 100ms~32s.
Connection interval meets following formula from equipment delay and supervision this three of time-out time:
Supervise time-out time > (1+ from equipment retardation coefficient) × (connection interval) (formula one)
In view of the operation to flash, the time for wiping 4096 bytes (minimum erasure unit) is about 22ms, that is, is wiped
Time is the integral multiple of 22ms, and the time for writing 256 bytes is about 13ms, when supervision time-out time is greater than 6 times of connection interval
And connection is spaced when being greater than 60ms, it is relatively high to operate successful probability to flash storage as the IOT equipment from equipment.It is setting
It must guarantee that IoT equipment has time enough to carry out erasable operation to flash in a bluetooth event when setting Connecting quantity, that is, connect
It connects interval and is greater than the time operated to flash.
In order to have biggish probability to be received by main equipment in the parameter updating request initiated from equipment, one need to be arranged
The value range at interval is connected, i.e. connection interval can be the arbitrary value in Smallest connection interval and maximum connection interval.Generally,
IoT equipment bluetooth reception caching (a part in IoT device memory) is bigger, and Smallest connection interval is spaced with maximum connection will
It is bigger, because receiving caching represents the ability that IoT equipment receives data volume in a bluetooth event, if a connection thing
Data volume in part, which is equal to, receives caching, then by the time of these data write-in flash are as follows: bluetooth receives cache size (unit
For byte) ÷ 256 × 13, unit is that millisecond (such as receives caching when be 1KB, writes the time of flash as 52ms), these are counted
According to the time of erasing are as follows:Unit is millisecond;It indicates to reality
It is rounded on number x.(such as receive caching be 1KB when, wipe flash time be 22ms).So receiving company when caching is 1KB
It connects interval and is greater than 22+52=74ms.
The IOT equipment that caching is n KB is received for bluetooth, parameter setting preferred method is when connection mode at a slow speed: most
Small connection interval is greater than (÷ of n × 1,024 256 × 13)+(n ÷ 4+1) × 22 (ms) and meets the integral multiple of 1.25ms;Most Dalian
Smallest connection interval+20ms is divided between connecing;It is greater than 1 from the value of equipment retardation coefficient;Time-out time is supervised to meet in supervision time-out
At least to 6 chances listened to are reserved from equipment in time, i.e., (from equipment retardation coefficient+1) × 6 × connection interval < it supervises super
When the time.Parameter setting preferred method is when fast connection mode: from equipment retardation coefficient be 0, other Connecting quantities at a slow speed
Connection mode is identical.
For example, the IoT equipment used bluetooth receive caching for 1K when, at a slow speed when connection mode parameter setting can such as table 1,
Parameter setting can be such as table 2 when fast connection mode.
The connection mode at a slow speed of table 1
Smallest connection interval |
Maximum connection interval |
From equipment retardation coefficient |
Supervise time-out time |
80ms |
100ms |
2 |
4s |
2 fast connection mode of table
Smallest connection interval |
Maximum connection interval |
From equipment retardation coefficient |
Supervise time-out time |
80ms |
100ms |
0 |
4s |
Third step receives the connection that main equipment is sent from the bluetooth module of equipment and establishes event or big data event, will even
It connects the event of foundation or big data event is sent to parameter updating request module.
4th step, connection event is that event or big data thing are established in connection to parameter updating request module based on the received
Part sends Connecting quantity to bluetooth module and updates request, and method is:
4.1 parameter updating request modules judge according to the connection status carried from the received connection event of bluetooth module from setting
Whether standby bluetooth state is in connection mode.If connection status is invalid, updates and request without Connecting quantity, turn third
Step;If connection status is effective, turn 4.2;
4.2 parameter updating request modules judge that the connection event received from bluetooth module is that event or big is established in connection
Connection mode traffic sign placement is then connection mode mark at a slow speed, and will connect at a slow speed if event is established in connection by data event
Mode flags are sent to initialization module;It is then fast connection mode mark by connection mode traffic sign placement if big data event
Will, and fast connection mode mark is sent to initialization module;
4.3 parameter updating request modules read Connecting quantity from initialization module, and Connecting quantity is sent to bluetooth mould
Block, method are: if parameter updating request module received from bluetooth module be connection establish event, from initialization module read
It takes the Connecting quantity of connection mode at a slow speed and is sent to bluetooth module;If parameter updating request module is received from bluetooth module
It is big data event, then reads the Connecting quantity of fast connection mode from initialization module and be sent to bluetooth module;
4.4 parameter updating request modules send Connecting quantity to bluetooth module and update request, Connecting quantity are carried, if parameter
What update request module was received from bluetooth module is that event is established in connection, then carries the Connecting quantity of connection mode at a slow speed;If
What parameter updating request module was received from bluetooth module is big data event, then carries the Connecting quantity of fast connection mode.
The Connecting quantity received is updated request from equipment bluetooth module and is sent to main equipment by the 5th step.
6th step, main equipment receive after the Connecting quantity update request event that equipment bluetooth module is sent, Xiang Congshe
Preparation send Connecting quantity to update response events, carries result parameter " receiving " or " refusal ".
7th step receives the Connecting quantity that main equipment is sent from equipment bluetooth module and updates response events, judging result
Parameter is " receiving " or " refusal ".If result parameter is " receiving ", the Connecting quantity for waiting main equipment to send updates thing
Part turns the 8th step;If result parameter is " refusal ", bluetooth module uses before initiating the connection parameter updating request from equipment
Old Connecting quantity be sent to parameter update processing module, turn the 9th step.
8th step receives the Connecting quantity update event that main equipment is sent from the bluetooth module of equipment, more by Connecting quantity
New events are sent to parameter and update processing module, carry main equipment and determine the new Connecting quantity used.New Connecting quantity is that master sets
It is standby to update what the Connecting quantity carried in request determined according to from the Connecting quantity of equipment transmission, i.e., the connection of new Connecting quantity
Interval is more than or equal to the Smallest connection interval carried in parameter updating request and is less than or equal to maximum connection interval, postpones from equipment
Coefficient and supervision time-out time are identical as in parameter updating request.
9th step, parameter update processing module and handle parameter update result.Method is:
9.1 parameters update processing module according in initialization module connection mode mark judgement be fast connection mode also
It is connection mode at a slow speed, if fast connection mode, turns 9.2, if connection mode at a slow speed, then turn 9.3;
9.2 parameters update processing module and obtain the Connecting quantity of fast connection mode from initialization module, and judge parameter
The connection Smallest connection interval that whether is arranged in fast connection mode of interval in the Connecting quantity that update event carries and most
Within big connection interval, if not turning 9.4 within Smallest connection interval and maximum connection interval;If most
Within small connection interval and maximum connection interval, turn 9.5;
9.3 parameters update processing module and obtain the Connecting quantity of connection mode at a slow speed from initialization module, and judge parameter
The connection Smallest connection interval that whether is arranged in connection mode at a slow speed of interval in the Connecting quantity that update event carries and most
Within big connection interval, if not turning 9.4 within Smallest connection interval and maximum connection interval;If most
Within small connection interval and maximum connection interval, turn 9.5;
9.4 parameters update processing module and send Connecting quantity update request to bluetooth module, according in initialization module
Connection mode mark carries the Connecting quantity under corresponding modes, turns the 5th step.
9.5 parameters update processing module and the Connecting quantity that parameter update event carries are saved in bluetooth module, by bluetooth
Module keeps the bluetooth connection with main equipment.
Following technical effect can achieve using the present invention: using the invention enables can send to connect to main equipment from equipment
Parameter updating request is connect, thus make the negotiation that can be attached parameter with main equipment (Android device) from equipment (IoT equipment),
After initiating the connection parameter updating request from equipment, the company for meeting and requiring from equipment flash can be used from equipment and main equipment
It connects parameter and carries out Bluetooth communication, so that the IoT equipment with flash is not in when carrying out Bluetooth communication with Android device
Because Connecting quantity is improper, make IoT equipment to flash operation no the phenomenon that having handled and bluetooth is caused to frequently cut off, completely
Solves Bluetooth communication compatibility issue between IoT equipment and Android device.
Detailed description of the invention
Fig. 1 is overview flow chart of the present invention;
Fig. 2 is the flash memory compatible modules structure chart of first step design of the present invention.
Specific embodiment
Fig. 1 is overview flow chart of the present invention.The present invention the following steps are included:
The first step designs flash memory compatible modules as shown in Figure 2, is connected with the bluetooth module in IoT equipment, in IoT
When equipment is attached event handling, negotiates Connecting quantity by flash memory compatible modules and Android device, Connecting quantity is made to meet IoT
The requirement of flash storage access in equipment.Flash memory compatible modules are updated by initialization module, parameter updating request module and parameter
Processing module composition.
Initialization module updates processing module with parameter updating request module and parameter and is connected, and function is asked for parameter update
Modulus block provides Connecting quantity, updates processing module for parameter and provides Connecting quantity and connection mode mark.
Parameter updating request module is connected with initialization module and bluetooth module;Parameter updating request module is from bluetooth module
Connection event or big data event are received, is connection mode at a slow speed by connection mode traffic sign placement if received is connection event
Connection mode traffic sign placement is fast connection mode mark, and by connection mode if received is big data event by mark
Mark is sent to initialization module;Meanwhile parameter updating request module obtains Connecting quantity from initialization module, by Connecting quantity
It is stored in after bluetooth module and sends Connecting quantity update request to bluetooth module, send Connecting quantity more from bluetooth module to main equipment
New request event carries Connecting quantity.
Parameter updates processing module and is connected with initialization module and bluetooth module, and function is the company judged in initialization module
It connects whether parameter is updated successfully, if success, keeps connection with new Connecting quantity, if unsuccessful, sent to bluetooth module
Order is disconnected, disconnects bluetooth module with main equipment.Parameter updates processing module and obtains connection from initialization module
Parameter and connection mode mark return to the Connecting quantity obtained from initialization module with the main equipment obtained from bluetooth module
Connecting quantity is compared, if the connection that main equipment returns is spaced Smallest connection interval and most Dalian not in initialization module
In the range of connecing interval, then order is disconnected to bluetooth module transmission, disconnect bluetooth module with main equipment, if master sets
In the range of the Smallest connection interval that the standby connection returned is spaced in initialization module connect interval with maximum, does not then do and locate
Reason, bluetooth module continue to keep connecting with main equipment.
Second step, initialization module initialization Connecting quantity and connection mode mark, connection mode mark are initialized as not
Know mode, Connecting quantity is arranged by developer.
Third step receives the connection that main equipment is sent from the bluetooth module of equipment and establishes event or big data event, will even
It connects the event of foundation or big data event is sent to parameter updating request module.
4th step, connection event is that event or big data thing are established in connection to parameter updating request module based on the received
Part sends Connecting quantity to bluetooth module and updates request, and method is:
4.1 parameter updating request modules judge according to the connection status carried from the received connection event of bluetooth module from setting
Whether standby bluetooth state is in connection mode.If connection status is invalid, updates and request without Connecting quantity, turn third
Step;If connection status is effective, turn 4.2;
4.2 parameter updating request modules judge that the connection event received from bluetooth module is that event or big is established in connection
Connection mode traffic sign placement is then connection mode mark at a slow speed, and will connect at a slow speed if event is established in connection by data event
Mode flags are sent to initialization module;It is then fast connection mode mark by connection mode traffic sign placement if big data event
Will, and fast connection mode mark is sent to initialization module;
4.3 parameter updating request modules read Connecting quantity from initialization module, and Connecting quantity is sent to bluetooth mould
Block, method are: if parameter updating request module received from bluetooth module be connection establish event, from initialization module read
It takes the Connecting quantity of connection mode at a slow speed and is sent to bluetooth module;If parameter updating request module is received from bluetooth module
It is big data event, then reads the Connecting quantity of fast connection mode from initialization module and be sent to bluetooth module;
4.4 parameter updating request modules send Connecting quantity to bluetooth module and update request, Connecting quantity are carried, if parameter
What update request module was received from bluetooth module is that event is established in connection, then carries the Connecting quantity of connection mode at a slow speed;If
What parameter updating request module was received from bluetooth module is big data event, then carries the Connecting quantity of fast connection mode.
The Connecting quantity received is updated request from equipment bluetooth module and is sent to main equipment by the 5th step.
6th step, main equipment receive after the Connecting quantity update request event that equipment bluetooth module is sent, Xiang Congshe
Preparation send Connecting quantity to update response events, carries result parameter " receiving " or " refusal ".
7th step receives the Connecting quantity that main equipment is sent from equipment bluetooth module and updates response events, judging result
Parameter is " receiving " or " refusal ".If result parameter is " receiving ", the Connecting quantity for waiting main equipment to send updates thing
Part turns the 8th step;If result parameter is " refusal ", bluetooth module uses before initiating the connection parameter updating request from equipment
Old Connecting quantity be sent to parameter update processing module, turn the 9th step.
8th step receives the Connecting quantity update event that main equipment is sent from the bluetooth module of equipment, more by Connecting quantity
New events are sent to parameter and update processing module, carry main equipment and determine the new Connecting quantity used.New Connecting quantity is that master sets
It is standby to update what the Connecting quantity carried in request determined according to from the Connecting quantity of equipment transmission, i.e., the connection of new Connecting quantity
Interval is more than or equal to the Smallest connection interval carried in parameter updating request and is less than or equal to maximum connection interval, postpones from equipment
Coefficient and supervision time-out time are identical as in parameter updating request.
9th step, parameter update processing module and handle parameter update result.Method is:
9.1 parameters update processing module according in initialization module connection mode mark judgement be fast connection mode also
It is connection mode at a slow speed, if fast connection mode, turns 9.2, if connection mode at a slow speed, then turn 9.3;
9.2 parameters update processing module and obtain the Connecting quantity of fast connection mode from initialization module, and judge parameter
The connection Smallest connection interval that whether is arranged in fast connection mode of interval in the Connecting quantity that update event carries and most
Within big connection interval, if not turning 9.4 within Smallest connection interval and maximum connection interval;If most
Within small connection interval and maximum connection interval, turn 9.5;
9.3 parameters update processing module and obtain the Connecting quantity of connection mode at a slow speed from initialization module, and judge parameter
The connection Smallest connection interval that whether is arranged in connection mode at a slow speed of interval in the Connecting quantity that update event carries and most
Within big connection interval, if not turning 9.4 within Smallest connection interval and maximum connection interval;If most
Within small connection interval and maximum connection interval, turn 9.5;
9.4 parameters update processing module and send Connecting quantity update request to bluetooth module, according in initialization module
Connection mode mark carries the Connecting quantity under corresponding modes, turns the 5th step.
9.5 parameters update processing module and the Connecting quantity that parameter update event carries are saved in bluetooth module, by bluetooth
Module keeps the bluetooth connection with main equipment.