Utilizing BleuIO as a BLE Simulator for Testing, Debugging, and Creating BLE Applications

In the realm of Bluetooth Low Energy (BLE) development, having a reliable tool for testing, debugging, and creating BLE applications is crucial. BLE simulators serve as virtual environments that mimic real-world BLE devices, enabling developers to streamline the development process. BleuIO, a Bluetooth Low Energy USB dongle, offers a versatile and user-friendly solution for harnessing the power of BLE simulation. In this article, we will explore the significance of BLE simulators, discuss why they are needed, and delve into the various ways BleuIO can assist developers in building robust BLE applications.

Why Do We Need a BLE Simulator?
Testing and debugging BLE applications can be a complex and time-consuming process. Deploying real BLE devices for every development iteration is not only impractical but also resource-intensive. BLE simulators provide an efficient way to replicate various scenarios, allowing developers to validate their applications without relying on physical hardware. By emulating multiple BLE devices and their interactions, developers can thoroughly assess the reliability, compatibility, and functionality of their applications in a controlled environment. This not only reduces costs but also accelerates the development cycle.

How BleuIO Can Be Helpful
BleuIO offers a range of features and functionalities that make it an invaluable tool for BLE application development:

  • BLE Simulation Capabilities: BleuIO acts as a powerful BLE simulator, allowing developers to create and control multiple virtual BLE devices within a single environment. This flexibility enables comprehensive testing of various use cases, such as connecting to multiple peripherals, exploring different communication scenarios, and validating application behavior under different signal strengths and environmental conditions.
  • User-Friendly : BleuIO helps to simplify the process of setting up and managing simulated BLE devices. Developers can easily configure device attributes, services, characteristics, and descriptors, all through AT commands. These commands provide developers with a means to interact with the device programmatically. This ease of use significantly reduces the learning curve and enhances productivity.
  • Real-Time Data Monitoring: With BleuIO, developers can monitor real-time data exchanged between virtual BLE devices and their applications. This feature is particularly useful for debugging purposes, as it allows developers to inspect data packets, analyze communication output, and identify potential issues or inconsistencies. By closely monitoring data flow, developers can refine their applications for optimal performance.
  • Cross-Platform Compatibility: BleuIO supports various operating systems, making it compatible with a wide range of development environments. Whether you are working on Windows, macOS, or Linux, BleuIO seamlessly integrates into your preferred development workflow, ensuring versatility and accessibility.

Basic Functions of BleuIO

BleuIO offers several fundamental functions that aid in BLE application development:

Device Configuration: Developers can easily configure the properties and behavior of virtual BLE devices using BleuIO. This includes setting device names, MAC addresses, advertising intervals, supported services, and characteristics. This flexibility enables developers to simulate diverse scenarios and test application behavior under different configurations.

Advertising and Scanning BleuIO enables the simulation of advertising and scanning functionalities, allowing developers to emulate device discovery and connection processes. This feature is crucial for testing application behavior when interacting with various devices and ensuring seamless connectivity.

GATT Server and Client: BleuIO supports both GATT server and client roles, enabling developers to simulate and test both peripheral and central devices. This versatility allows for comprehensive testing of the application’s functionality in different roles and scenarios.

BleuIO can be served as a powerful BLE simulator that streamlines the testing, debugging, and creation of Bluetooth Low Energy applications. By providing an intuitive AT commands, comprehensive simulation capabilities, real-time data monitoring, and cross-platform compatibility, BleuIO empowers developers to build robust and reliable BLE applications efficiently. With its flexibility and ease of use, BleuIO significantly reduces development time, accelerates the testing process, and enhances the overall quality of Bluetooth Low Energy applications.

Share this post on :

BleuIO Firmware update v2.2.2: Enhanced MTU Control and Advanced Scan Filtering

The BleuIO team is excited to announce the release of their latest firmware version, v2.2.2, packed with new features and improvements for Bluetooth Low Energy (BLE) developers. This firmware update aims to provide an enhanced development experience and empower developers with more control over their BLE applications.

What’s new in this firmware :

One of the notable additions in this release is the inclusion of a new command that allows developers to set or query the maximum MTU (Maximum Transmission Unit) size used in MTU negotiation upon connecting to a device. This feature provides flexibility in adjusting the MTU size, enabling better optimization and efficiency in data transmission between devices.

Additionally, the BleuIO firmware v2.2.2 introduces a powerful filtering mechanism for scan results. A new command has been added to apply filters on the outcomes from AT+FINDSCANDATA and AT+GAPSCAN commands. This feature allows filtering based on three different parameters: Local Name, Service UUID, and Manufacturer Specific ID.

It enables the flexibility to activate one filter, two filters in combination, or all three filters simultaneously. Results will only be displayed if the selected filter value is present in the advertising or scan response data. For example, a filter can be set to exclusively show data packets from devices with the Local Name “BleuIO” (either Complete or Shortened) by executing the command AT+SCANFILTER=NAME=BleuIO.

By leveraging these filtering capabilities, developers can easily focus on specific devices or data packets that meet their criteria, streamlining the development and testing process.

To explore the full range of features and improvements introduced in BleuIO firmware v2.2.2, developers are encouraged to visit the official BleuIO documentation at https://www.bleuio.com/getting_started/docs/firmware/. The comprehensive documentation provides detailed information on firmware updates and guides on how to leverage these new features effectively.

The BleuIO team is committed to continuously enhancing the BLE development experience and providing tools needed to build robust and innovative applications. With each firmware release, BleuIO demonstrates its dedication to empowering developers and enabling seamless Bluetooth Low Energy development.

Stay tuned for future updates from the BleuIO team, as they continue to introduce new features and improvements to meet the evolving needs of the BLE developer community.

Share this post on :

BleuIO Node.js Library available on NPM

BleuIO, a leading provider of Bluetooth Low Energy (BLE) solutions, has recently released a new Node.js library for developers. This library is available on NPM, making it easy for developers to access and use it for their projects. With this library, developers can create BLE applications quickly and easily.

The BleuIO Node.js library provides a simple and straightforward way for developers to communicate with BLE devices. It supports a range of BLE protocols. This library is designed to work seamlessly with Node.js, making it easy to integrate into existing projects.

One of the primary advantages of using the BleuIO Node.js library is its ease of use. Developers do not need to have extensive knowledge of Bluetooth technology to use this library. The library provides a high-level API that simplifies the communication process, allowing developers to focus on their application’s functionality rather than the underlying BLE protocols.

Another advantage of the BleuIO Node.js library is its flexibility. The library can be used to create a range of BLE applications, from simple IoT devices to complex mobile applications. This flexibility is made possible by the library’s support for a range of BLE devices and protocols.

The BleuIO Node.js library is also highly customizable. Developers can configure the library to meet their specific requirements, such as setting up a custom scan interval or configuring the advertising payload. This flexibility allows developers to create applications that are tailored to their specific needs.

To use the BleuIO Node.js library, developers must have a BleuIO device or module. BleuIO devices are small, low-cost modules that can be integrated into a range of applications, from simple IoT devices to complex mobile applications. These devices provide a reliable and secure way to communicate with BLE devices.

Installation and how to use this library can be found on BleuIO’s getting started guide.

https://www.bleuio.com/getting_started/docs/nodejsLibScan/

Share this post on :

Create a real-time desktop CO2 widget using Javascript and Bluetooth

Creating a small real-time desktop CO2 widget using JavaScript and Bluetooth is a fun and engaging project that can help you understand how to work with Bluetooth communication and sensor data processing.

In this project we will use BleuIO to communicate with air quality monitoring sensor to read CO2 data. BleuIO is a bluetooth low energy usb dongle that helps to create BLE application easily. The AT command available on this device makes the development faster and easier.

There are many air quality sensor available but one popular choice is the HibouAir.

We will use electron js and node serial to connect with BleuIO. After that we will use AT commands to scan for nearby Bluetooth device that is advertising with a given board ID which is the air quality monitoring sensor.

Requirments :

  1. BleuIO
  2. HibouAir – air quality monitoring sensor

Note: both BleuIO and HibouAir are available at digikey.

Here are the steps you can follow to create your own widget:

Hardware setup :

Connect BleuIO to the computer and wait for the device to recognize it. This usually takes 10 seconds. Connect the air quality monitoring sensor HibouAir to a power cable. Make sure the device is within 50 meters.

Write the code :

Clone this repository from Github using

git clone https://github.com/smart-sensor-devices-ab/bluetooth-co2-desktop-widget.git

After that go inside the directory and write

npm install 

on terminal. This will install necessary libraries.

Inside this folder we will find three .js files and one html file. The index.html file is the frontend where we will see the real-time CO2 values.

The main.js file initialize the application and creates an window of 200px X 200px

render.js is the file which has all the logic go connect to BleuIO via serial port , gets real-time air quality data, decode it and finally print it on the screen.

Code explanation :

On render.js file, at first we make a list of devices connected to serial port. Then we filter out only the BleuIO devices by filtering with vendorID which is 2dcf. After that we pick the first item of the list.

Once we know the path of the BleuIO device , we connect to it.

ports = ports.filter((x) => x.vendorId == "2dcf");
      if (ports && ports.length > 0) {
        port = new SerialPort({
          path: ports[0].path,
          baudRate: 57600,
        });
}

Now that we are connected to the BleuIO dongle, we can write AT commands to it and get the response.

At first we write AT+DUAL to the dongle to put the dongle in dual role. So that we can scan for nearby devices and advertised data.

to put the dongle in dual role we write

port.write(Buffer.from("AT+DUAL\r"), function (err) {
          if (err) {
            document.getElementById("error").textContent =
              "Error writing at dual";
          } else {
            console.log('dongle in dual role')
}

In this project I am trying to get air quality data from a HibouAir device which has a board ID of 45840D. Therefore I look for advertised data that has this specific boardID. If i write AT+FINDSCANDATA=4584OD, BleuIO will filter out only advertise data from this board ID.

After writing this , we get a response from the dongle. To read the response from serial port we use

 port.on("readable", () => {
          let data = port.read();
console.log(data)
})

We can push the response in an array and later decide what to do with it.

When we do a AT+FINDSCANDATA=45840D

the response from the dongle looks something like this

Then we take the last response by using

resp = readDataArray[readDataArray.length - 2];

After that , get the advertised data from the string by

resp.split(" ").pop();

Now we have the advertised data in a variable. We can easily get the CO2 value from this string by selecting the position. The documentation from HibouAirs says , the CO2 value is right at the end of the string. In that case the value is 023A which is 570 is decimal.

We can print this value in our screen.

We can create a function that do the scanning every 20 seconds to get latest values.

Here is the complete code to render.js file

// This file is required by the index.html file and will
// be executed in the renderer process for that window.
// All of the Node.js APIs are available in this process.
const { SerialPort } = require("serialport");
var port;
var readDataArray = [];
async function listSerialPorts() {
  await SerialPort.list().then((ports, err) => {
    if (err) {
      document.getElementById("error").textContent = err.message;
      return;
    } else {
      document.getElementById("error").textContent = "";
    }
    console.log("ports", ports);

    if (ports.length === 0) {
      document.getElementById("error").textContent = "No ports discovered";
    } else {
      ports = ports.filter((x) => x.vendorId == "2dcf");
      if (ports && ports.length > 0) {
        port = new SerialPort({
          path: ports[0].path,
          baudRate: 57600,
        });
        port.write(Buffer.from("AT+DUAL\r"), function (err) {
          if (err) {
            document.getElementById("error").textContent =
              "Error writing at dual";
          } else {
            const myWriteFunc = () => {
              port.write(Buffer.from("AT+FINDSCANDATA=5B0705=3\r")),
                function (err) {
                  if (err) {
                    document.getElementById("error").textContent =
                      "Error writing findscandata";
                  } else {
                    console.log("here");
                  }
                };
            };
            myWriteFunc();
            setInterval(() => {
              myWriteFunc();
            }, 20000);
          }
        });
        // Read serial port data
        port.on("readable", () => {
          let data = port.read();
          let enc = new TextDecoder();
          let arr = new Uint8Array(data);
          let removeRn = enc.decode(arr).replace(/\r?\n|\r/gm, "");
          if (removeRn != null) readDataArray.push(removeRn);
          if (removeRn == "SCAN COMPLETE") {
            console.log(readDataArray);
            let resp = readDataArray[readDataArray.length - 2];

            let advData = resp.split(" ").pop();
            let pos = advData.indexOf("5B0705");
            console.log("advData", advData);
            console.log("c", advData.substr(pos + 46, 4));
            let co2 = parseInt("0x" + advData.substr(pos + 46, 4));
            console.log(co2);
            document.getElementById("co2Val").innerHTML = co2;
          }
        });
      } else {
        document.getElementById("error").innerHTML =
          "No device found. Please connect a BleuIO ongle to your computer and try again.";
      }
    }
  });
}

function listPorts() {
  listSerialPorts();
  setTimeout(listPorts, 20000);
}

// Set a timeout that will check for new serialPorts every 2 seconds.
// This timeout reschedules itself.
//setTimeout(listPorts, 2000);

listSerialPorts();

To build this app we need a library called electron-builder. To install this library we write on terminal
npm i electron-builder

Once the library is build , we need to update our package json file and add build option or mac.

"build": {
    "appId": "com.co2.widget",
    "productName": "co2-widget",
    "mac": {
      "category": "airquality.app.widget"
    }
  }

We can update our script on package json like this

"scripts": {
    "start": "electron .",
    "pack": "electron-builder --dir",
    "dist": "electron-builder"
  },

Once we are done, build the app with

npm run build

We will see a dmg file in our dist folder. Once we run the app, the widget will look like this.

The value will update every 20 seconds.

Creating a small desktop CO2 widget using JavaScript and BlueIO is a great way to learn about these technologies and create a useful tool for monitoring indoor air quality.

Share this post on :

BleuIO Python library v1.2.0 includes verbose mode with easier event handling features

BleuIO Python library is updated and supports firmware version 2.2.1 .This update utilizes the new Verbose mode of the dongle and make it a lot simpler to work with Bluetooth Low Energy with Python.
Now the AT commands returns an object with 4 members

  • Command
  • Acknowledge
  • Response
  • End

Each contains a JSON object, except Response. The Response contains a list of JSON objects since a command can have several responses.

This new update of the library makes it easier to get the relevant information without building your own parser.
Status variables : Helpful status variables has been added which helps to keep track of the dongle status ; whether it is scanning, advertising or connected along with the dongle role.
Callback function : A callback function should be registered for both scan results and events. The callback functions will run every time a new event or scan result is detected.

Using the library

List of AT commands are available at https://www.bleuio.com/getting_started/docs/commands/

and how to access these AT commands using python library can be found at
https://pypi.org/project/bleuio/

Before starting to install our library, make sure you have the latest python installed on your system.

If you have never installed a library from PyPI, you must install the pip tool enabling you to download and install a PyPI package. There are several methods that are described on this page.

Now Install the library by running

pip install bleuio

pip automatically downloads and installs the most recent library on your system in the correct directory. To check that the installation went well, you can launch a Python interpreter and run the following lines:

from bleuio_lib.bleuio_funcs import BleuIO
my_dongle = BleuIO()
print(my_dongle.ati().Rsp)

Good luck on creating amazing Bluetooth Low Energy application using BleuIO and Python.

Share this post on :

BleuIO’s new firmware version 2.2.1 increased MTU size to 512 bytes

What is the maximum transmission unit (MTU)?

In networking, maximum transmission unit (MTU) is a measurement representing the largest data packet that a network-connected device will accept.

BleuIO’s new firmware version 2.2.1 increased MTU size from 247 bytes to 512 bytes, which allows more data to fit into fewer packets. This generally results in a faster and more efficient transmission of data.

A new AT command AT+GETMAC is also added to the latest firmware. This will return the MAC address of the BleuIO dongle.

Added features:

  • Increased MTU to 512 bytes.
  • Added an MTU event that shows the negotiated MTU when connected or when changed: (MTU CHANGED: xxx) (using verbose mode: {779:”0000″,”evt”:{“action”:”mtu changed”,”mtu”:xxx}})
  • Added new AT command: AT+GETMAC for getting bleuio mac address.

Bugfixes

  • Fixed format errors of some messages when using verbose mode that doesn’t comform to JSON.

To find out more about the updates of the dongles new firmware 2.2.1, please visit our Getting Started Guide.

Share this post on :

Bluetooth Low Energy based RGB LED Strip color control from a web browser and STM32

1. Introduction

This project is about Bluetooth Low Energy based RGB LED Strip Color Control from a web browser and STM 32. The LEDs light strip can also be controlled wirelessly via a BLE scanning App using IOS or Android. With the received data, we decide which color of the RGB strip to activate.

You will need two dongles, one connected to the Nucleo board and one connected to a computer to control from web browser. The web script is also available on GitHub.

When the BleuIO Dongle is connected to the Nucleo boards USB port the STM32 will recognize it and directly start advertising. This allows the other Dongle to connect to it.

It will also accept 3 different inputs from the UART:

inputresult
0Send ATI (Request device information) command to BlueIO Dongle.
1Manually turn the LED on
2Manually turn the LED off

We have used a STM32 Nucleo-144 development board with STM32H743ZI MCU (STM32H743ZI micro mbed-Enabled Development Nucleo-144 series ARM® Cortex®-M7 MCU 32-Bit Embedded Evaluation Board) and the WS2812, a intelligent control LED light source, for this example.

Connect the LED to the Nucleo Board by connecting:

4-7 VDC to 5V

GND to any GND

DIN to PE9

On the Nucleo NUCLEO-H743ZI2:

Note : If you want to use another setup you will have to make sure it support USB Host and beware that the GPIO setup might be different and may need to be reconfigured in the .ioc file.

2. Project requirments

  • Two BleuIO dongles (https://www.bleuio.com/)
  • A board with a STM32 Microcontroller with a USB port. (A Nucleo-144 development board: NUCLEO-H743ZI2, is used for this project. (https://www.st.com/en/evaluation-tools/nucleo-h743zi.html)
  • To connect the dongle to the Nucleo board a “USB A to Micro USB B”-cable with a USB A female-to-female adapter can be used.)
  • STM32CubeIDE (https://www.st.com/en/development-tools/stm32cubeide.html)
  • An WS2812 RGB LED

3. About the Code

The source code is available at
https://github.com/smart-sensor-devices-ab/stm32_bleuio_rgb_led_example

This project is based on another STM32 project (https://github.com/smart-sensor-devices-ab/stm32_bleuio_example) with the interface to the WS2812 Interface WS2812 with STM32 by Controllers Tech

The DIN pin will be connected to TIM1 which need to be enabled in to the .ioc file:

Parameter Settings:

DMA for TIM1 will also be enabled:

In main.c we will need to add a callback for TIM PWM Pulse Finished:

void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim)
{
    HAL_TIM_PWM_Stop_DMA(&htim1, TIM_CHANNEL_1);
    datasentflag=1;
}



In main.c there is also a functions for controlling the LED.

Set_LED() for changing the color of the individual LEDs.

Set_Brightness() for setting the brightness. A brightness value of 0 means the LED is turned off.

WS2812_Send() execute the changes we made to the LED.

void Set_LED (int LEDnum, int Red, int Green, int Blue)
{
    LED_Data[LEDnum][0] = LEDnum;
    LED_Data[LEDnum][1] = Green;
    LED_Data[LEDnum][2] = Red;
    LED_Data[LEDnum][3] = Blue;
}

#define PI 3.14159265

void Set_Brightness (int brightness)  // 0-45
{
#if USE_BRIGHTNESS

    if (brightness > 45) brightness = 45;
    for (int i=0; i<MAX_LED; i++)
    {
        LED_Mod[i][0] = LED_Data[i][0];
        for (int j=1; j<4; j++)
        {
            float angle = 90-brightness;  // in degrees
            angle = angle*PI / 180;  // in rad
            LED_Mod[i][j] = (LED_Data[i][j])/(tan(angle));
        }
    }

#endif

}

void WS2812_Send (void)
{
    uint32_t indx=0;
    uint32_t color;


    for (int i= 0; i<MAX_LED; i++)
    {
#if USE_BRIGHTNESS
        color = ((LED_Mod[i][1]<<16) | (LED_Mod[i][2]<<8) | (LED_Mod[i][3]));
#else
        color = ((LED_Data[i][1]<<16) | (LED_Data[i][2]<<8) | (LED_Data[i][3]));
#endif

        for (int i=23; i>=0; i--)
        {
            if (color&(1<<i))
            {
                pwmData[indx] = 60;  // 2/3 of 90
            }

            else pwmData[indx] = 30;  // 1/3 of 90

            indx++;
        }

    }

    for (int i=0; i<50; i++)
    {
        pwmData[indx] = 0;
        indx++;
    }

    HAL_TIM_PWM_Start_DMA(&htim1, TIM_CHANNEL_1, (uint32_t *)pwmData, indx);
    while (!datasentflag){};
    datasentflag = 0;
}



We also update the handleUartInput function so we can have manual control over the LED via the UART.

/**
  * @brief Simple uart input handler
  * @retval None
  */
void handleUartInput(UARTCommandTypeDef cmd)
{
    switch(cmd)
    {
        case UART_RX_0:
        {
            // 0
            uart_buf_len = sprintf(uart_tx_buf, "\r\n(0 pressed)\r\n");
            HAL_UART_Transmit(&huart3, (uint8_t *)uart_tx_buf, uart_buf_len, HAL_MAX_DELAY);
            if(isBleuIOReady)
            {
                writeToDongle((uint8_t*)DONGLE_CMD_ATI);
            } else
            {
                uart_buf_len = sprintf(uart_tx_buf, BLEUIO_NOT_READY_MSG);
                HAL_UART_Transmit(&huart3, (uint8_t *)uart_tx_buf, uart_buf_len, HAL_MAX_DELAY);
            }
            uartStatus = UART_RX_NONE;
            break;
        }
        case UART_RX_1:
        {
            // 1
            uart_buf_len = sprintf(uart_tx_buf, "\r\n(1 pressed LED on!)\r\n");
            HAL_UART_Transmit(&huart3, (uint8_t *)uart_tx_buf, uart_buf_len, HAL_MAX_DELAY);
              Set_Brightness(40);
              WS2812_Send();
            uartStatus = UART_RX_NONE;
            break;
        }
        case UART_RX_2:
        {
            // 2
            uart_buf_len = sprintf(uart_tx_buf, "\r\n(2 pressed LED off!)\r\n");
            HAL_UART_Transmit(&huart3, (uint8_t *)uart_tx_buf, uart_buf_len, HAL_MAX_DELAY);
              Set_Brightness(0);
              WS2812_Send();

            uartStatus = UART_RX_NONE;
            break;
        }
        case UART_RX_NONE:
        {
            break;
        }
        default:
        {
            uartStatus = UART_RX_NONE;
            break;
        }
    }
}

4. How to setup project

4.1 Downloading the project from GitHub

Get project HERE

https://github.com/smart-sensor-devices-ab/stm32_bleuio_rgb_led_example


Either clone the project, or download it as a zip file and unzip it, into your STM32CubeIDE workspace.

4.2 Importing as an Existing Project

  • From STM32CubeIDE choose File>Import…

  • Then choose General>Existing Projects into Workspace then click ‘Next >’

  • Make sure you’ve choosen your workspace in ‘Select root directory:’
  • You should see the project “stm32_bleuio_rgb_led_example”, check it and click ‘Finish’.

5. Running the example

  • In STMCubeIDE click the hammer icon to build the project.
  • Open up the ‘STMicroelectronics STLink Viritual COM Port’ with a serial terminal emulation program like TeraTerm, Putty or CoolTerm.

Serial port Setup:

Baudrate: 115200

Data Bits: 8

Parity: None

Stop Bits: 1

Flow Control: None

  • Connect the BleuIO Dongle before running the example
  • In STMCubeIDE click the green play button to flash and run it on your board. The first time you click it the ‘Run Configuration’ window will appear. You can just leave it as is and click run.
  • You should be greeted by this welcome message:
Welcome to STM32 BleuIO RGB LED Example!
Press 0 to run the ATI command
Press 1 to manually turn on LED
Press 2 to manually turn off LED

The LED will turn on briefly when starting up.

  • Wait until the message: “[BleuIO Dongle Ready]” is shown.

  • The LEDs should now turn off and you can now connect with the other dongle using the script.

You can also use the uart commands (0, 1 or 2):

  • Press 0 to get device information.
  • 1 to turn on LED.
  • 2 to turn off LED.

Dongle response will be printed to UART.

Control the colors from a web browser

Connect the BleuIO dongle to the computer. Run the web script to connect to the other BleuIO dongle on the STM32. The web script is available inside the source file. Now we can control the colors wirelessly.

For this script to work, we need

Create a simple Html file called index.html which will serve as the frontend of the script. This Html file contains some buttons that help connect and read advertised data from the remote dongle, which is connected to stm32.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link
      href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css"
      rel="stylesheet"
      integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3"
      crossorigin="anonymous"
    />
    <title>
      Bluetooth controlled RGB LED Strip - Control color from web browser
    </title>
  </head>
  <body class="mt-5">
    <div class="container mt-5">
      <img
        src="https://www.bleuio.com/blog/wp-content/themes/bleuio/images/logo.png"
      />
      <h1 class="mb-5">
        Bluetooth controlled RGB LED Strip - Control color from web browser
      </h1>

      <div class="row">
        <div class="col-md-4 pt-5">
          <button class="btn btn-success mb-2" id="connect">Connect</button>
          <form method="post" id="sendMsgForm" name="sendMsgForm">
            <div class="mb-3">
              <label for="msgToSend" class="form-label"
                >Select color option</label
              >
              <select
                class="form-select"
                aria-label="Default select example"
                name="msgToSend"
                id="msgToSend"
                required
              >
                <option selected>Open this select menu</option>
                <option value="L=0">LED Off</option>
                <option value="L=1">LED On</option>
                <option value="L=RED">Set LED lights red</option>
                <option value="L=GREEN">Set LED lights green</option>
                <option value="L=BLUE">Set LED lights blue</option>
                <option value="L=RAINBOW">
                  Set LEDs lights to different colors
                </option>
              </select>
            </div>

            <button type="submit" class="btn btn-primary">Submit</button>
          </form>
        </div>
        <div class="col-md-8">
          <img
            src="https://www.bleuio.com/blog/wp-content/uploads/2022/09/bluetooth-controlled-rgb-led-strip-collor-control.jpg"
          />
        </div>
      </div>
    </div>

    <script src="script.js"></script>
  </body>
</html>

Create a js file called script.js and include it at the bottom of the Html file. This js file uses the BleuIO js library to write AT commands and communicate with the other dongle.

import * as my_dongle from 'bleuio'
const dongleToConnect='[0]40:48:FD:E5:2F:17'
document.getElementById('connect').addEventListener('click', function(){
  my_dongle.at_connect()
  document.getElementById("connect").disabled=true;
  document.getElementById("sendMsgForm").hidden=false;
})

document.getElementById("sendMsgForm").addEventListener("submit", function(event){
    event.preventDefault()

    
    my_dongle.ati().then((data)=>{
        //make central if not
        if(JSON.stringify(data).includes("Peripheral")){
            console.log('peripheral')
            my_dongle.at_central().then((x)=>{
                console.log('central now')
            })
        }        
    })
    .then(()=>{
        // connect to dongle
        my_dongle.at_getconn().then((y)=>{
            if(JSON.stringify(y).includes(dongleToConnect)){
                console.log('already connected')
            }else{
                my_dongle.at_gapconnect(dongleToConnect).then(()=>{
                    console.log('connected successfully')
                })
            }
        })
        .then(()=>{
            var theVal = document.getElementById('msgToSend').value;
            console.log('Message Send  '+theVal)
            // send command to show data
            my_dongle.at_spssend(theVal).then(()=>{
                console.log('Message Send '+theVal)
            })
        })
        
    })
  });

The script has a button to connect to COM port on the computer. After connecting to the dongle , we should be able to control the colors of the LED strip.

To connect to the BleuIO dongle on the STM32, make sure the STM32 is powered up and a BleuIO dongle is connected to it.

Get the MAC address

Follow the steps to get the MAC address of the dongle that is connected to STM32

- Open this site https://bleuio.com/web_terminal.html and click connect to dongle.
- Select the appropriate port to connect.
- Once it says connected, type ATI. This will show dongle information and current status.
- If the dongle is on peripheral role, set it to central by typing AT+CENTRAL
- Now do a gap scan by typing AT+GAPSCAN
- Once you see your dongle on the list ,stop the scan by pressing control+c
- Copy the ID and paste it into the script (script.js) line #2

Run the web script

You will need a web bundler. You can use parcel.js

Once parcel js installed, go to the root directory of web script and type “parcel index.html”. This will start your development environment.

Open the script on a browser. For this example we opened http://localhost:1234

You can easily connect to the dongle and update the LED strip.

The web script looks like this

Share this post on :

Bluetooth based PIR motion detecting application using STM32 board

1. Introduction

In this project we will use a PIR sensor to detect motion. Once motion is detected, it will trigger an interrupt and the BleuIO dongle connected to the board will advertise for 25 seconds. You can expand the project based on your needs further.

A PIR (passive infrared) Sensor is an electronic device that  detects heats from human or animal body, giving a detection signal when movement happens in a given area or range of the sensor.

For this project, we will need one dongle and a PIR sensor (for example: https://www.digikey.com/short/4v12z2nw).
When the BleuIO Dongle is connected to the Nucleo boards USB port the STM32 will recognize it and set up a new device name for the dongle: BleuIO PIR Detected. This will show up when the dongle is advertising.

2. Using the example project

2.1 What we will need

2. How to setup project

2.1 Downloading the project from GitHub

Get project HERE

https://github.com/smart-sensor-devices-ab/stm32_bleuio_pir_example


Either clone the project, or download it as a zip file and unzip it, into your STM32CubeIDE workspace.

2.2 Importing as an Existing Project

  • From STM32CubeIDE choose File>Import…
  • Then choose General>Existing Projects into Workspace then click ‘Next >’
  • Make sure you’ve choosen your workspace in ‘Select root directory:’
  • You should see the project “stm32_bleuio_pir_example”, check it and click ‘Finish’.

If you download the project as a zip file you will need to rename the project folder from ‘stm32_bleuio_pir_example-master’ to ‘stm32_bleuio_pir_example’

5. Connecting the sensor

Connect the PIR Sensor Gnd to ground and Vdd to power and Output to a pin of your choice on the Nucleo board (In the example we use PA0)

If you want a different PIN you will need to go into the STM32Cube ioc file and make some edits:

  • Click on PA0 and select Reset_State in the STM32Cube ioc file.
  • Click on your desired Pin and select EXTIO
  • Then go to GPIO under System Core and make sure you setup the pin as follows:

    GPIO mode: External Interrupt Mode with Rising edge trigger detection

    GPIO Pull-up/Pull-down: Pull-down
  • Then go to NVIC under System Core and make sure EXTI line0 interrupt is enabled

6. Running the example

  • In STMCubeIDE click the hammer icon to build the project.
  • Open up the ‘STMicroelectronics STLink Viritual COM Port’ with a serial terminal emulation program like TeraTerm, Putty or CoolTerm.

Baudrate: 115200

Data Bits: 8

Parity: None

Stop Bits: 1

Flow Control: None

  • In STMCubeIDE click the green play button to flash and run it on your board. The first time you click it the ‘Run Configuration’ window will appear. You can just leave it as is and click run.
  • Connect the BleuIO Dongle.

7. Output

When the PIR sensor detects movement it will trigger an interrupt that in turn will tell the BleuIO Dongle to advertise for 25 seconds. Just so the PIR Sensor will not trigger constantly we have put a 20 second timeout before it will trigger again. If no new interrupts have been detected after the 25 second advertising timer has run out the BleuIO Dongle will stop advertising and wait for a new interrupt to happen.

The yellow LED on the STM32 board also toggles if there is a movement.

Hope you found this article informative.

Share this post on :

Benefits and use cases of Bluetooth Low Energy technology

We live in a day where wireless data transfer is a rather common phenomenon. From offering location services or audio streaming to maintaining device networks and data transfers, all is made possible due to wireless communication technologies and Bluetooth is one of them. Bluetooth is a short-range wireless technology which helps exchange data between connected devices over short radiuses. 

Bluetooth Low Energy is essential for IoT networks due to its ability to preserve battery power on devices. Major use cases of Bluetooth Low Energy technology include:

Use Cases

  • Mobile payments at retail outlets.
  • Wireless charging for multiple devices.
  • Keep track of traveller luggage at the airport by using smart tags.
  • Monitor air quality of the indoor environment by using BLE-powered sensors.
  • Remote monitoring of patient’s health conditions
  • Autonomous vehicles with intelligent seats and steering wheels, intelligent proximity reporting etc
  • Smart Home automation systems with sensors for tracking fire breakouts, water leakages, or motion in case of robbery.

Advantages of Bluetooth Low Energy technology

  • Sends an ID number via BLE advertising channels
  • The 2.4 GHz frequency controls interference in signals.
  • Determines the location of users within its range
  • Longer battery life by keeping the radio off when not required
  • Uninterrupted broadcast using Bluetooth beacon 
  • The devices are able to establish connections and faster data transfer.
  • Small size (maximum up to 255 bytes) data transfer which is helpful for IoT-based applications
  • The 128-bit AES algorithm ensures the safety of data transfer.
  • Low power consumption compared to other wireless technologies.
  • Comparatively lower cost of deployment and maintenance of chipsets and modules.

The BleuIO is Bluetooth low energy USB dongle that can be used to create Bluetooth low energy application. Just use the AT Commands available on the device for faster development.
The BleuIO is a fully integrated solution, providing MCU and Bluetooth® radio in one chip, based on Dialog Semiconductor latest Bluetooth chip DA14683. The FLASH based device permits field or boot upgradable, while application is stored on FLASH memory.
Projects and tutorials with source code can be found at https://www.bleuio.com/blog/?bleprojects

Share this post on :

Integration of Bluetooth technology within Embedded Systems

Bluetooth Low Energy (BLE) is one of the most widely applicable low-power connectivity standards. Its purpose is to connect devices over a fairly short range. BLE was developed with IoT applications in mind, which has special implications for its design.

Integration of Bluetooth technology within Embedded Systems facilitates an expansive range of Application Domains to support devices at various design levels. Engaging Bluetooth into an embedded system creates value in device capability for specific needs, via the implementation of Bluetooth Profiles that can help the data transfer between compatible devices. Recent introductions to Bluetooth LE Audio in the SMART phone market deliver revolutions in Bluetooth audio capability, enabling users to share audio from a single device to multiple wireless headsets.

Bluetooth Low Energy is used almost everywhere, which is one of its core strengths compared to other low-power networks. This is one of the reasons why everyone looking into BLE when designing their solutions. Because of the well-established name of Bluetooth Classic, BLE had an easier time gaining trust among developers. All these factors combined made it the obvious choice for many consumer IoT applications and much more.

On the other hand, Bluetooth Low Energy is constantly being developed and perfected to meet the most current demands of the market, therefore, it is one of the top choices for embedded system developers to integrate BLE in their solutions.

The BleuIO is Bluetooth low energy USB dongle that can be used in embedded system solutuions. Just use the AT Commands available on the device for faster development.
The BleuIO is a fully integrated solution, providing MCU and Bluetooth® radio in one chip, based on Dialog Semiconductor latest Bluetooth chip DA14683. The FLASH based device permits field or boot upgradable, while application is stored on FLASH memory.
Projects and tutorials with source code can be found at https://www.bleuio.com/blog/?bleprojects

Share this post on :