Bilingual application for BBMagic BUTTON and Raspberry Pi


You can download all project files as ‘bbmagic_button_sketch.tar.gz’ archive from Download section.

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:
BBMagic BUTTON app running

If here is the very first time you see BBMagic application I suggest to watch below links first for better understanding.
Writing BBMagic FLOOD application for RPi or Writing C app for Raspberry Pi and BBMagic MAGNETO

Application files

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’

Building application

As always we start from checking library version and then BBMagic bluetooth communication opening.
BBMagic BUTTON app code
After that if data arrives (data_length > 0) it is in ‘bbm_buf’ buffer.
BBMagic BUTTON app code
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.
BBMagic BUTTON app code
Then we check which BUTTON function needs to be realized.
BBMagic BUTTON app code
If there is received data from other BBMagic module we show its address and type.
BBMagic BUTTON app code
Here is the simple code for duplicate checking.
BBMagic BUTTON app code
And its done !!

You can download all project files as ‘bbmagic_button_sketch.tar.gz’ archive from Download section.
Tagged , , , , . Bookmark the permalink.

Comments are closed.