WOWConnect
In the rapidly evolving landscape of technology, the integration of wireless communication has become increasingly prevalent, unlocking new possibilities for seamless connectivity. One such breakthrough is the introduction of the WOWConnect library, designed specifically for the WOWCube device, to facilitate efficient data transfer over Bluetooth Low Energy (BLE).
At its core, WOWConnect serves as a robust conduit between applications and WOWCube devices, ensuring a fluid and efficient exchange of data. WOWCube, with its unique cubic design and individual screens on each face, demands a sophisticated communication mechanism, and WOWConnect rises to the occasion.
Key Features of WOWConnect
- Bluetooth Low Energy (BLE) Integration:
Harnessing the prowess of BLE, WOWConnect establishes a low-power wireless connection between applications and WOWCube devices. This strategic implementation ensures minimal power consumption, a critical consideration for the energy-efficient operation of WOWCube.
- Efficient Data Transfer:
WOWConnect has been optimized to facilitate swift and efficient data transfer. By streamlining the exchange of data packets, the library guarantees a seamless and responsive communication channel between applications and the WOWCube.
- Device Discovery and Connection:
The library simplifies the process of discovering nearby WOWCube devices and establishing connections. WOWConnect streamlines the pairing procedure, enhancing user-friendliness for both developers and end-users.
- Cross-Platform Compatibility:
A noteworthy aspect of WOWConnect is its cross-platform compatibility. Developers can seamlessly integrate WOWConnect into applications developed in C++, C#, Swift and Kotlin, providing a unified interface across various platforms.
Implementation Guidelines for WOWConnect
Embarking on the integration of WOWConnect into your application involves a structured approach:
- Library Installation:
Begin by integrating the WOWConnect library into your development environment. Comprehensive installation instructions are available below.
- Initialization and Configuration
Initialize WOWConnect within your application and configure the library according to specific requirements. This includes setting connection parameters and defining preferences related to data handling.
- Data Transfer Implementation:
Implement functions for data transfer, utilizing WOWConnect's streamlined API. This empowers developers to seamlessly send and receive data packets, fostering a harmonious interaction between applications and the WOWCube.
- Testing and Optimization:
Rigorously test the integration of your application with WOWConnect to ensure a smooth and responsive user experience. Optimize the code as necessary to enhance performance.
WOWConnect and Emulation Mode
In addition to its primary functions, WOWConnect introduces a noteworthy feature – compatibility with the WOWCube Emulator that comes with WOWCube Development Kit. This feature allows developers to test and debug their applications in a simulated environment, providing a valuable tool for refining the user experience before deploying to physical WOWCube devices.
Writing your first WOW-connected cubeapp
So, let’s begin. The first thing to note is the following: unlike conventional WOWCube applications that hold all program logic in a single file installed on WOWCube, the use of the WOWConnect library requires the presence of two applications – one to be installed on the device, the other – an application launched on the “host” system, used to transmit and receive data via BLE. That is, there are always two applications.
Writing an application that supports WOWConnect is practically no different from creating a regular application for WOWCube. Support for receiving and transmitting data via BLE is a standard feature provided by WOWCube SDK version 6.0 or higher, supplied as a part of the WOWCube Development Kit. The only difference, in fact, is the need to implement a data handler, which will be used from the callback called when the device receives data via BLE. Working with data transmitted via BLE is no fundamentally different from working with network data: when receiving data, a dedicated callback function is called, and if you need to send data back to the “host” application, a special send function is used.
On the “host” side of the application, everything is also simple, although there are some nuances.
First of all, in order to send something via BLE to WOWCube, you need to find out the address of the device in order to know where to send the data. The WOWConnect library provides an interface for automatic searching for available WOWCube devices, both physical and virtual. However, the “host” application must be responsible for processing the list of detected devices, selecting and storing the address of the current device. In other words, the library allows you to find a device, but the “host” application decides what to do with it next.
Secondly, the WOWConnect library provides interfaces for different programming languages depending on the target operating system. The following programming languages are currently supported:
- Microsoft Windows 10 (version 21H2 or higher)
- Microsoft Windows 11
- C# (.Net Framework 4.8)
- C++
- MacOS 11 (Big Sur)
- MacOS 12 (Monterey)
- MacOS 13 (Ventura)
- MacOS 14 (Sonoma)
- iOS/iPadOS 14 or higher
- Swift 5 (XCode 14.3 or higher)
- Android (version 26 or higher)
- Kotlin
And finally, depending on the type of operating system, it may be necessary to supply some special files along with your project.
The process of creation of a WOW-connected application begins, as for any other WOWCube application, with generation of an empty project in Visual Studio Code.
It should be noted that at this stage only projects written in C++ are supported.
Upon completion of generating a new project, the following files will be created:
MyNewConnectedApp.h
MyNewConnectedApp.cpp
Please note two important points here:
-
Starting from WOWCube SDK 6.0, each new application gets automatically assigned with a unique identifier (UUID), which is used by the WOWConnect library to address data. In other words, so that the library “knows” which application on the cube it is sending data to. The values of UUID identifier can be found at the top of both files and used as a parameter for SetApplication function.
-
A new callback function
on_ExternalMessagehas been added to the interface of theCubios::Applicationclass. It is the callback function that is called by the CubiOS operating system at the moment of registration of the arrival of BLE data to the device.
Let’s look at this callback function in more detail:
As you can see, the funciton takes two input parameters – a pointer to the data packet (pkt) and the size of the received data (size). This means that in order to receive data from the “host” application, you just need to copy the received number of bytes from the incoming buffer, and that’s it!
The library does not impose any special restrictions on what happens to the data after copying; a cubeapp may process the data as desired. However, as with network data processing, it is generally not recommended to perform complex calculations that require significant CPU time inside a given callback function.
Let’s consider a very simple example.
Say we have a “host” application that periodically sends 10 bytes of data to our cubeapp. Then, our handler code may look like this:
Transferring data from the cube to the “host” application is also not a big problem.
For that,
function is used.
But unlike the data callback function, this one has three input parameters: a pointer to the data to send (data), a size of the data to send (size) and a type of the data being sent. This parameter allows you to “tag” your data so that the receiving party (the “host” application) could distinguish between same size data packets which are coming from WOWCube.
As an elementary example, consider a situation where we want to send a packet of 10 random bytes to the “host” application every time someone taps the cube.
The code may look like this:
Writing your “host” application for Windows
Ok, now when we’ve our cubeapp created let’s make an app that sends some data to it. Let’s see how an application that uses WOWConnect library is created for Windows operating system.
First, create a new C# project of Windows Application type with Microsoft Visual Studio. The version of your IDE may vary; however you should make sure .NET Framework 4.8 is supported.
Then set up application references. Add WOWConnect library to the list of referenced frameworks and make sure the following files are copied to your application’s executable folder:
- WOWConnect.dll
- Windows.winmd
- System.Runtime.WindowsRuntime.dll
And finally, add
at the beginning of your application to get access to the interfaces of WOWConnect library. Now everything is set, and we can start coding!
The life cycle of the WOWConnect library within a host application consists of four stages:
- Initialization and configuration
- Search for devices
- Transmission and reception of data
- De-initialization and cleanup
Let’s take a closer look at each stage.
Initialization
Since most of the library’s functionality operates asynchronously, communication with the user’s application occurs through delegates. For correct initialization, the library requires three delegates:
this delegate is called when the list of detected devices is changed, i.e. new device is detected or previously detected device disappears
this delegate is called when the host application receives data via BLE
and this delegate is used to redirect the library log output.
A sample code for WOWCube library initialization is shown below:
Search for devices
When searching for available devices, everything is very simple: the WOWConnect library starts searching for WOWCube devices automatically upon successful initialization. In other words, you will start receiving DetectedDevicesListChangedDelegate callbacks right after calling Bluetooth.Open function.
Sending the data
In order to send the data to a cubeapp application that is running on WOWCube device, three simple steps are required:
-
You have to find the device you want to send your data to by its name:
info
In case if requested device is available, you will get a device descriptor object.
-
Then, you should try to open the device providing a UUID of the cubeapp application to communicate with as a parameter:
info -
And finally, you can send your data to a successfully opened device using
info
When the device is no longer in use, you should use
function to terminate BLE connection to the device and clean up the memory.
Оf course, the above is a simplification to some extent, in a real application additional checks on function return codes will be required. However, in essence, these three functions are necessary and sufficient for solving the task of data transfer over BLE to WOWCube device.
Cleaning up
Before closing the host application, we would want to disconnect from all currently connected BLE or virtual devices and free compter resources used by the library. To do that, simply call
Writing your “host” application for Mac and iOS
The method of using the WOWConnect library to create “host” applications for Mac and iOS is no different from that described above for Windows.
First, create a new App project in XCode. Please make sure you are using XCode version 14.3.1 or higher.
Then set up application references. Add WOWConnectCore.framework library to the list of referenced frameworks in the Frameworks, Libraries and Embedded Content section of General settings of your project.
Then navigate to Signing & Capabilites tab and select the following items from App Sandbox section:
- Incoming Connections (Server)
- Incoming Connections (Client)
- Bluetooth
and the next item from Hardened Runtime section:
- Disable Library Validation
Then switch to Info tab and add two new Key/Value pairs to the Custom macOS Application Target Properties list:
- Privacy - Local Network Usage Description
- Privacy - Bluetooth Always Usage Description
And finally, add
at the beginning of your application's view controller code to get access to the interfaces of WOWConnect library.
And this would be it, your project's setup is done.
The life cycle of the WOWConnect library within a host application consists of four stages:
- Initialization and configuration
- Search for devices
- Transmission and reception of data
- De-initialization and cleanup
Let’s take a closer look at each stage.
Initialization
Since most of the library’s functionality operates asynchronously, communication with the user’s application occurs through delegates. For correct initialization, the library requires three delegates:
this delegate is called when the list of detected devices is changed, i.e. new device is detected or previously detected device disappears
this delegate is called when the host application receives data via BLE
and this delegate is used to redirect the library log output.
A sample code for WOWCube library initialization is shown below:
Search for devices
When searching for available devices, everything is very simple: the WOWConnect library starts searching for WOWCube devices automatically upon successful initialization. In other words, you will start receiving DetectedDevicesListChangedDelegate callbacks right after calling Bluetooth.Open function.
Sending the data
In order to send the data to a cubeapp application that is running on WOWCube device, three simple steps are required:
-
You have to find the device you want to send your data to by its name:
info
In case if requested device is available, you will get a device descriptor object.
-
Then, you should try to open the device providing a UUID of the cubeapp application to communicate with as a parameter:
info -
And finally, you can send your data to a successfully opened device using
info
When the device is no longer in use, you should use
function to terminate BLE connection to the device and clean up the memory.
Оf course, the above is a simplification to some extent, in a real application additional checks on function return codes will be required. However, in essence, these three functions are necessary and sufficient for solving the task of data transfer over BLE to WOWCube device.
Cleaning up
Before closing the host application, we would want to disconnect from all currently connected BLE or virtual devices and free compter resources used by the library. To do that, simply call