How it works?
Our demo app is for Raspberry Pi microcomputers. It receives data from BBMagic BUTTON. When you press modules button (single click, double click or holding) it sends proper information to Raspberry Pi and then application:
Our bilingual app consists few files:
- bbmagic_lib_1.2.a – library for receiving data from BBMagic devices through Bluetooth Low Energy radio link. It’s for Raspberry Pi zero W and Raspberry Pi 3 which have Bluetooth LE chipset onboard.
- bbmagic_lib.h – header file containing definitions and constants
- libbluetooth.a – library file from libbluetooth-dev Debian package that contains development files for using the BlueZ Linux Bluetooth library.
- bbmagic_button_sketch_pl.c – application ‘C’ file in polish
- bbmagic_button_sketch_eng.c – application ‘C’ file in english
- Makefile – it contains compilation instructions for making binaries: ‘bbmagic_button_sketch_pl’ and ‘bbmagic_button_sketch_eng’
As always we start from checking library version and then BBMagic bluetooth communication opening.
After that if data arrives (data_length > 0) it is in ‘bbm_buf’ buffer.
If data is from BBMAGIC_M_BUTTON we check for message duplication.
To increase communication quality BBMagic BUTTON sends multiple messages with the same signature on bytes bbm_buf[BBM_BUTTON_SIGN_0], bbm_buf[BBM_BUTTON_SIGN_1], bbm_buf[BBM_BUTTON_SIGN_2], bbm_buf[BBM_BUTTON_SIGN_3].
check_duplicate_msg(unsigned char* bbm_buf, unsigned char *last_sig) function checks duplicate message,
If there is new data from BBMagic BUTTON lets display welcome message: ‘HELLO, Here is BBMagic BUTTON’ and then modules address and system time.
Then we check which BUTTON function needs to be realized.
If there is received data from other BBMagic module we show its address and type.
Here is the simple code for duplicate checking.
And its done !!