RN4020: Eddystone Bluetooth beacon
To use the RN4020 as an Eddystone beacon one must use the custom advertisement features, which are available only in version 1.33.4 BEC. If I choose to broadcast only the URL frame that I can use the scripting features of the RN2040 and I can use this little BLE module in standalone mode, without a microcontroller to drive it.
To program the script I will use the same connection as in the firmware update tutorial, with an USB-UART click providing RX, TX lines and power, and SWAKE pin connected to Vcc. I will use TerraTerm to run the following commands:
+ WC WW @PW_ON # Clear previous Eddystone frame NZ # Add Eddystone service to a new frame NB,03AAFE # Add URL information to the frame NB,16AAFE10F2036269742E6C792F6D7962636E # Start advertising A # End with ESC (works fine with ESC key in TerraTerm)
Then I configure the script to run at power on:
SR,01001000 // Run script after power on R,1 // Reboot
Some explanations:
The + command turn on echo, so I can see on the terminal the command I have sent.
WC clears any previous script.
WW allows for a script to be entered.
The script is set to start at power on (@PW_ON event). It first performs a NZ command, which clears any previous advertising payload. Then I start building a new advertising frame by using NB to append information. In my case I fist append 03AAFE which is the Eddystone service, then I append the frame content, respectively 16AAFE10F2036269742E6C792F6D7962636E. The A command starts advertising in default mode, at 100ms intervals. Pressing ESC key on the PC exits the scripting mode.
If you wish you can run LW command to verify the content of the script. The script can be manually startedd with WR, and can be stopped with WP.
SR,01001000 sets the script to be run at startup, with serial output enabled. R,1 reboots and save the settings. At this moment the USB-UART is not needed anymore, and the beacon can run by itself on battery power.
And here are some screen captures from Android and iOS devices:
Given the default advertising period of 100ms, with the above connections the current consumption of this particular BLE2 click module is approximately 3.4mA with the blue WAKE LED on, and 2.4mA with the WAKE LED removed.
With SWAKE pin set to low the current consumption is 41μA, but in this mode UART is limited to 2400 baud. Thus, I can run on a pair of AA alkaline batteries for more than 5 years, or on a CR2032 battery for about six months (estimated using http://oregonembedded.com/batterycalc.htm).
13 Comments
So I have a question on this. you show the encoded value is
0303AAFE1216AAFE10F2036269742E6C792F6D7962636E
but you entered in
03AAFE and
16AAFE10F2036269742E6C792F6D7962636E
so the first 03H and the 12H (payload size) are missing.
I agree this works, because I copied and got it to work. Just dont understand why those two bytes were left out.
The first 03H is the length of the first packet. Also 12H is the length of payload (18 bytes). Both values are automatically computed and added to the encoded value by the software within RN4020.
Thanks for the info, I suspected that but was not sure.
I don’t follow the encoding of the NB messages NB,03AAFE and NB,16AAFE10F2036269742E6C792F6D7962636E.
The RN4020 firmware release note for 1.33BEC says that the NB command format is based on altbeacon and the first parameter is the AD Type (03 = Complete list 16-bit UUIDs, 16 = service data) it doesn’t seem to match the Eddystone format that you’re using.
Am I missing something ?
Please advise,
Thanks
Hi Chris!
Please refer to RN4020 Firmware v1.33BEC Release Notes.
On page 4 the description of ND command sais: NB,
This command is used to customize non-connectable advertisement payload.
On page 5 you have the different types of AD
AD Type HEX Description
01 – Flags
02 – Incomplete list of 16-bit UUIDs
03 – Complete list of 16-bit UUIDs
04 – Incomplete list of 32-bit UUIDs
05 – Complete list of 32-bit UUIDs
06 – Incomplete list of 128-bit UUIDs
07 – Complete list of 128-bit UUIDs
08 – Shortened local name
09 – Complete local name
0A – TX power level
0D – Class of device
0E – Simple pairing hash
0F – Simple pairing randomizer
10 – TK value
11 – Security OOB flag
12 – Slave connection interval range
14 – List of 16-bit service UUIDs
15 – List of 128-bit service UUIDs
16 – Service data
FF – Manufacture Specific Data
With this information, you can build any broadcasting packet (including AltBEacon, Eddystone, and Ibeacon).
Please note that the RN4020 performs some internal processing of NB information entered, and adds extra information to that (such as packet length).
So, in my case of Eddystone beacon, the protocol is (according to https://github.com/google/eddystone/blob/master/protocol-specification.md):
Every Eddystone frame type must contain the following PDU data types:
– The Complete List of 16-bit Service UUIDs as defined in The Bluetooth Core Specification Supplement (CSS) v5, Part A, § 1.1. The Complete List of 16-bit Service UUIDs must contain the Eddystone Service UUID of 0xFEAA. This is included to allow background scanning on iOS devices.
– The Service Data data type, Ibid., § 1.11. The Service Data – 16 bit UUID data type must be the Eddystone Service UUID of 0xFEAA
Thus, two NB commands are needed to build one single Eddystone frame. One for the “Complete List of 16-bit Service UUIDs”, the other to define the “Service data”.
In the case of other beacon standards such as AltBeacon or Ibeacon, the syntax might differ. There’s an example for AltBeacon in the release notes. So, if you wish to broadcast in that format you can use that file as reference.
I haven’t explored the possibility to send Ibeacon frames yet.
What type of beacon are you trying to make? Is it Eddystone, or something else? I could do more to help you if you can tell me exactly what you are trying to do…
Regards,
Teodor
Hello,
Is there a way to send data using the Rx I/O while in Beacon mode ?
Hi,
As I understand, you have to stop the beacon service before doing any serial communication. You can resume the beacon operation after the serial communication is completed.
Note that in beacon mode the RN4020 is only broadcasting packets. It will not listen on Bluetooth communication either.
Hi,
I mean to other issue: i want to send data via the serial port but only to broadcast it like a beacon.
Hi,
You can build almost any type of packet to be broadcasted, just like I did with the Eddystone frame in my example. You can, for example, follow my procedure to build one Eddystone frame then broadcast it. Then you can stop the broadcast, set up a new frame (let’s say iBeacon), then start broadcasting it. And so on.
Just remember that you have to stop the broadcast during the activity on the serial port, and you have to re-enable broadcast once you are done.
The question is, what do you want to broadcast? In the situation of Eddystone and other well-defined beacon formats, the receiver knows what to do with the broadcasted data. You can define your own beacon format but you have to write also the software that receives the broadcasted information. Also, mind the current (Bluetooth) communication standards, you don’t want to interfere with other services running on Bluetooth.
Hi
I can manage the App side so i can manage the data received.
I would like to clarify my question : lets say i want to broadcast data (by feeding the serial port), but without “real” ble connection, i.e only broadcast. and the App side is just a listener. how can i do it ?
Any packet you build using the NB command will be broadcasted to whoever is listening. This is the main advantage of a beacon. No connection is made between the beacon and the receiver.
You can read the “Non-Connectable Advertisement Payload” section of http://ww1.microchip.com/downloads/en/DeviceDoc/RN4020%20Firmware%201.33BEC%20Release%20Note-May2016.pdf for more information. You’ll also find a good example for AltBeacon there – that’s just another (simpler) beacon.
Probably you’ll have to do something like NB, XXYYYYYY, where XX is the ad type from Annex 1 of the above file, and YYYYYY is your data to be broadcasted.
Hi,
Great, do you familiar with free ‘listener’ App ?
https://play.google.com/store/apps/details?id=com.radiusnetworks.locate
https://play.google.com/store/apps/details?id=com.fair.ashok.rssireader
https://play.google.com/store/apps/details?id=com.beaconinside.android
https://play.google.com/store/apps/details?id=de.flurp.beaconscanner.app
Most apps I use are for beacons, but some listen to everything on Bluetooth.