当前位置:网站首页>Quick realization of Bluetooth ibeacn function

Quick realization of Bluetooth ibeacn function

2022-06-27 06:24:00 shine_ blink

One 、iBeacon brief introduction

iBeacon It's apple 2013 year 9 Mobile devices released in January use OS(iOS7) New features on . The way it works is , Equipped with Low power Bluetooth (BLE) Communication function of the device use BLE Technology sends its own unique ID, Receive the ID Your application software will be based on this ID Take some action . such as , Set up... In the store iBeacon Communication module , Can let iPhone and iPad Run an information notification server on , Or the server sends discount coupons and store entry points to customers . Besides , It can also be used when the home appliance breaks down or stops working iBeacon Send information to the application .

Two 、iBeacon Format

iBeacon It uses BLE technology , To be specific , Use of is BLE Middle name is “ Announcement frame ”(Advertising) The broadcast frame of . An announcement frame is a frame sent periodically , As long as it's support BLE Your device can receive .iBeacon This is achieved by embedding data in Apple's own format in the payload part of this announcement frame .
 Insert picture description here
AD Field Length: Advertisement Data The length of , Indicates the length of useful broadcast information
Type: The radio type
Company ID: The data field is a two byte company ID Code start .SIG Will these ID Code issued to the company , among 0x004C It stands for Apple id( Only this ID, The device will call iBeacon)
iBeacon Type: byte 0x02 This device is Beacon
iBeacon Length: The length of the remaining fields
UUID: It is stipulated that ISO/IEC11578:1996 The standard 128 Bit identifier
Major、Minor: from iBeacon The publisher sets it himself , All are 16 Bit identifier . such as , Chain stores can be in Major Write area information , Can be found in Minor For individual stores ID etc. . in addition , Embed... In appliances iBeacon When the function , It can be used Major Indicates the product model , use Minor Indicates the error code , It is used to notify the outside of the fault
TX Power: APP adopt iBeacon The transmitted signal strength is estimated at 1 When it's rice RSSI Strength

About iBeacon Please refer to Apple's official documentation for details of :
https://developer.apple.com/ibeacon/Getting-Started-with-iBeacon.pdf

3、 ... and 、 Complete code

Realization function : Customize iBeacon The specific content of the broadcast , And update every half a second iBeacon In the broadcast content Major and Minor Value of field .

-- Here for experimental purposes , Arbitrarily defined 16 Data is as uuid
uuid = {
    0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF}
-- initialization iBeacon Specific content of broadcast information , And open iBeacon Bluetooth radio , Be careful : This function can only be called once 
--CompanyID=0x004C, Major=0x1234, Minor=0x5678, rssi_1m=0xC3(-59db),  Broadcast interval =100ms
LIB_NrfBleIbeaconConfig(0x004C,0x1234,0x5678,0x3C,100,uuid)
major = 0
minor = 10000
-- Start the big cycle 
while(GC(1) == true)
do
    -- every other 500ms(0.5 second ) Updated once iBeacon In Bluetooth broadcast Major and Minor Value 
    LIB_DelayMs(500) 
    major = major + 1
    minor = minor - 1
    LIB_NrfBleIbeaconUpdate(major,minor)
end

Four 、 demonstration

After the above code runs , We install... On Android phones nRF Connect App Bluetooth debugging software , And pass Scan Scanned iBeacon The information is as follows :
 Insert picture description here
Not only can you see iBeacon Node UUID Information , Colleagues can also see in real time Major The value of is constantly increasing ,Minor The value of is constantly decreasing .
For more details, please refer to shineblink.com The website links

原网站

版权声明
本文为[shine_ blink]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/178/202206270617053461.html