{"id":119,"date":"2021-12-03T14:29:43","date_gmt":"2021-12-03T14:29:43","guid":{"rendered":"https:\/\/www.bleuio.com\/blog\/?p=119"},"modified":"2022-07-01T10:37:11","modified_gmt":"2022-07-01T10:37:11","slug":"how-to-make-a-ble-enabled-smart-bulb-with-stm32-and-bleuio","status":"publish","type":"post","link":"https:\/\/www.bleuio.com\/blog\/how-to-make-a-ble-enabled-smart-bulb-with-stm32-and-bleuio\/","title":{"rendered":"How To Make a BLE enabled Smart Bulb with STM32"},"content":{"rendered":"\n<p>Home automation involves automating household environment equipment. To achieve that, we have created a smart bulb that is easy to install, and the attached equipment can be controlled over a web browser or smartphone app. The aim of this project is to control different home appliances using a web browser or smartphone.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. Introduction<\/h2>\n\n\n\n<p>The project is showcasing a simple way of using the the BleuIO Dongle to turn on and off a light bulb that is connected to the STM32 Nucleo-144 via a 5V Relay.<\/p>\n\n\n\n<p>You will need two dongles, one connected to the Nucleo board and one connected to a computer, running the web script.<br>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.<\/p>\n\n\n\n<p>It will also accept 3 different inputs from the UART:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>input<\/th><th>result<\/th><\/tr><\/thead><tbody><tr><td>0<\/td><td>Send ATI (Request device information) command to BlueIO Dongle.<\/td><\/tr><tr><td>1<\/td><td>Manually turn the light bulb on<\/td><\/tr><tr><td>2<\/td><td>Manually turn the light bulb off<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>We have used a STM32 Nucleo-144 development board with STM32H743ZI MCU (STM32H743ZI micro mbed-Enabled Development Nucleo-144 series ARM\u00ae Cortex\u00ae-M7 MCU 32-Bit Embedded Evaluation Board) for this example.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong>WARNING \u2013 THIS PROJECT INVOLVES HIGH VOLTAGES THAT CAN CAUSE SERIOUS INJURY OR DEATH. PLEASE TAKE ALL NECESSARY PRECAUTIONS, AND TURN OFF ALL POWER TO A CIRCUIT BEFORE WORKING ON IT.<\/strong><\/p><\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\">2. Connecting the relay<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Beware:<\/h3>\n\n\n\n<p><strong>Always be very careful when experimenting with AC, electrical shock can result in serious injuries!<\/strong>&nbsp;NOTICE OF RISK; DISCLAIMER OF LIABILITY<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.bleuio.com\/getting_started\/img\/smart_bulb\/warning_sign.jpg\" alt=\"alt text\"\/><\/figure>\n\n\n\n<p><strong>Pinout and Connection to STM32<\/strong>&nbsp;For the DC part of the Relay circuit connect S (signal) to pin PE4 on the STM32 NUCLEO board, also connect the Power supply (+) and ground (-) to +5V and GND respectively.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"708\" height=\"448\" src=\"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/03\/stm32-smart-light-project.jpg\" alt=\"\" class=\"wp-image-193\" srcset=\"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/03\/stm32-smart-light-project.jpg 708w, https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/03\/stm32-smart-light-project-300x190.jpg 300w\" sizes=\"auto, (max-width: 708px) 100vw, 708px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.bleuio.com\/getting_started\/img\/smart_bulb\/final_setup.jpg\" alt=\"alt text\" title=\"Lightbulb.\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">3. About the Code<\/h2>\n\n\n\n<p>You can get project&nbsp;<strong><a href=\"https:\/\/github.com\/smart-sensor-devices-ab\/stm32_bleuio_lightbulb_example\">HERE<\/a><\/strong><br><a href=\"https:\/\/github.com\/smart-sensor-devices-ab\/stm32_bleuio_lightbulb_example\">https:\/\/github.com\/smart-sensor-devices-ab\/stm32_bleuio_lightbulb_example<\/a><\/p>\n\n\n\n<p>This project based on our previous STM32 project (<a href=\"https:\/\/github.com\/smart-sensor-devices-ab\/stm32_bleuio_example\">https:\/\/github.com\/smart-sensor-devices-ab\/stm32_bleuio_example<\/a>) with these changes in the .ioc file:<\/p>\n\n\n\n<p>In the pinout view we set the GPIO PE4 to OUTPUT and labeled it to \u2018lightbulb\u2019.<img decoding=\"async\" src=\"https:\/\/www.bleuio.com\/getting_started\/img\/smart_bulb\/Pinout_view.png\" alt=\"alt text\"><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>In the USBH_CDC_ReceiveCallback function in USB_HOST\\usb_host.c we copy the CDC_RX_Buffer into a external variable called dongle_response that is accessable from the main.c file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void USBH_CDC_ReceiveCallback(USBH_HandleTypeDef *phost)\n{\n    if(phost == &amp;hUsbHostFS)\n    {\n        \/\/ Handles the data recived from the USB CDC host, here just printing it out to UART\n        rx_size = USBH_CDC_GetLastReceivedDataSize(phost);\n        HAL_UART_Transmit(&amp;huart3, CDC_RX_Buffer, rx_size, HAL_MAX_DELAY);\n\n        \/\/ Copy buffer to external dongle_response buffer\n        strcpy((char *)dongle_response, (char *)CDC_RX_Buffer);\n\n        memset(CDC_RX_Buffer,0,RX_BUFF_SIZE);\n        USBH_CDC_Receive(phost, CDC_RX_Buffer, RX_BUFF_SIZE);\n    }\n\n    return;\n}<\/code><\/pre>\n\n\n\n<p><br>In main.c we create a simple intepreter so we can react to the data we are recieving from the dongle.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/**\n  * @brief Simple dongle interpreter\n  * @retval None\n  *\/\nvoid dongle_interpreter(uint8_t * input)\n{\n\n    if(strlen((char *)input) != 0)\n    {\n        if(strstr((char *)input, \"\\r\\nADVERTISING...\") != NULL)\n        {\n            isAdvertising = true;\n        }\n        if(strstr((char *)input, \"\\r\\nADVERTISING STOPPED.\") != NULL)\n        {\n            isAdvertising = false;\n        }\n        if(strstr((char *)input, \"\\r\\nCONNECTED\") != NULL)\n        {\n            isConnected = true;\n            HAL_GPIO_WritePin(GPIOE, GPIO_PIN_1, GPIO_PIN_SET);\n        }\n        if(strstr((char *)input, \"\\r\\nDISCONNECTED\") != NULL)\n        {\n            isConnected = false;\n            HAL_GPIO_WritePin(GPIOE, GPIO_PIN_1, GPIO_PIN_RESET);\n        }\n        if(strstr((char *)input, \"L=0\") != NULL)\n        {\n            isLightBulbOn = false;\n            HAL_GPIO_WritePin(Lightbulb_GPIO_Port, Lightbulb_Pin, GPIO_PIN_RESET);\n\n            writeToDongle((uint8_t*)DONGLE_SEND_LIGHT_OFF);\n\n            uart_buf_len = sprintf(uart_tx_buf, \"\\r\\nLight bulb is %s\\r\\n\", isLightBulbOn ? \"on\":\"off\");\n            HAL_UART_Transmit(&amp;huart3, (uint8_t *)uart_tx_buf, uart_buf_len, HAL_MAX_DELAY);\n        }\n        if(strstr((char *)input, \"L=1\") != NULL)\n        {\n            isLightBulbOn = true;\n            HAL_GPIO_WritePin(Lightbulb_GPIO_Port, Lightbulb_Pin, GPIO_PIN_SET);\n\n            writeToDongle((uint8_t*)DONGLE_SEND_LIGHT_ON);\n\n            uart_buf_len = sprintf(uart_tx_buf, \"\\r\\nLight bulb is %s\\r\\n\", isLightBulbOn ? \"on\":\"off\");\n            HAL_UART_Transmit(&amp;huart3, (uint8_t *)uart_tx_buf, uart_buf_len, HAL_MAX_DELAY);\n        }\n    }\n    memset(&amp;dongle_response, 0, RSP_SIZE);\n}<\/code><\/pre>\n\n\n\n<p><br>We also update the handleUartInput function so we can have manual control over the light bulb via the UART.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/**\n  * @brief Simple uart input handler\n  * @retval None\n  *\/\nvoid handleUartInput(UARTCommandTypeDef cmd)\n{\n    switch(cmd)\n    {\n        case UART_RX_0:\n        {\n            \/\/ 0\n            uart_buf_len = sprintf(uart_tx_buf, \"\\r\\n(0 pressed)\\r\\n\");\n            HAL_UART_Transmit(&amp;huart3, (uint8_t *)uart_tx_buf, uart_buf_len, HAL_MAX_DELAY);\n            if(isBleuIOReady)\n            {\n                writeToDongle((uint8_t*)DONGLE_CMD_ATI);\n            } else\n            {\n                uart_buf_len = sprintf(uart_tx_buf, BLEUIO_NOT_READY_MSG);\n                HAL_UART_Transmit(&amp;huart3, (uint8_t *)uart_tx_buf, uart_buf_len, HAL_MAX_DELAY);\n            }\n            uartStatus = UART_RX_NONE;\n            break;\n        }\n        case UART_RX_1:\n        {\n            \/\/ 1\n            uart_buf_len = sprintf(uart_tx_buf, \"\\r\\n(1 pressed light bulb on!)\\r\\n\");\n            HAL_UART_Transmit(&amp;huart3, (uint8_t *)uart_tx_buf, uart_buf_len, HAL_MAX_DELAY);\n            HAL_GPIO_WritePin(Lightbulb_GPIO_Port, Lightbulb_Pin, GPIO_PIN_SET);\n            uartStatus = UART_RX_NONE;\n            break;\n        }\n        case UART_RX_2:\n        {\n            \/\/ 2\n            uart_buf_len = sprintf(uart_tx_buf, \"\\r\\n(2 pressed light bulb off!)\\r\\n\");\n            HAL_UART_Transmit(&amp;huart3, (uint8_t *)uart_tx_buf, uart_buf_len, HAL_MAX_DELAY);\n            HAL_GPIO_WritePin(Lightbulb_GPIO_Port, Lightbulb_Pin, GPIO_PIN_RESET);\n\n            uartStatus = UART_RX_NONE;\n            break;\n        }\n        case UART_RX_NONE:\n        {\n            break;\n        }\n        default:\n        {\n            uartStatus = UART_RX_NONE;\n            break;\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<p>We put the intepreter function inside the main loop.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/* Infinite loop *\/\n  \/* USER CODE BEGIN WHILE *\/\n  while (1)\n  {\n    \/* USER CODE END WHILE *\/\n    MX_USB_HOST_Process();\n\n    \/* USER CODE BEGIN 3 *\/\n    \/\/ Simple handler for uart input\n    handleUartInput(uartStatus);\n    \/\/ Inteprets the dongle data\n    dongle_interpreter(dongle_response);\n\n    \/\/ Starts advertising as soon as the Dongle is ready.\n    if(!isAdvertising &amp;&amp; !isConnected &amp;&amp; isBleuIOReady)\n    {\n        HAL_Delay(200);\n        writeToDongle((uint8_t*)DONGLE_CMD_AT_ADVSTART);\n        isAdvertising = true;\n    }\n  }\n  \/* USER CODE END 3 *\/<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">4. Using the example project<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">4.1 What you will need<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>Two BleuIO dongles (<a href=\"https:\/\/www.bleuio.com\/\">https:\/\/www.bleuio.com\/<\/a>)<\/li><li>The script for the dongle (available on the source code inside web script folder)<\/li><li>A board with a STM32 Microcontroller with a USB port. (A Nucleo-144 development board: NUCLEO-H743ZI2, was used developing this example. (<a href=\"https:\/\/www.st.com\/en\/evaluation-tools\/nucleo-h743zi.html\">https:\/\/www.st.com\/en\/evaluation-tools\/nucleo-h743zi.html<\/a>)<br>To connect the dongle to the Nucleo board a \u201cUSB A to Micro USB B\u201d-cable with a USB A female-to-female adapter can be used.)<br><br><img decoding=\"async\" src=\"https:\/\/www.bleuio.com\/getting_started\/img\/smart_bulb\/adapter.jpg\" alt=\"alt text\"><\/li><li>STM32CubeIDE (<a href=\"https:\/\/www.st.com\/en\/development-tools\/stm32cubeide.html\">https:\/\/www.st.com\/en\/development-tools\/stm32cubeide.html<\/a>)<\/li><li>A 5V Relay<\/li><li>A light bulb<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">5. How to setup project<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">5.1 Downloading the project from GitHub<\/h3>\n\n\n\n<p><strong>Get project&nbsp;<a href=\"https:\/\/github.com\/smart-sensor-devices-ab\/stm32_bleuio_lightbulb_example\">HERE<\/a><\/strong><br><a href=\"https:\/\/github.com\/smart-sensor-devices-ab\/stm32_bleuio_lightbulb_example\">https:\/\/github.com\/smart-sensor-devices-ab\/stm32_bleuio_lightbulb_example<\/a><br><br>Either clone the project, or download it as a zip file and unzip it, into your STM32CubeIDE workspace.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">5.2 Importing as an Existing Project<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>From STM32CubeIDE choose File&gt;Import\u2026<br><img decoding=\"async\" src=\"https:\/\/www.bleuio.com\/getting_started\/img\/smart_bulb\/import.png\" alt=\"alt text\"><\/li><li>Then choose General&gt;Existing Projects into Workspace then click \u2018Next &gt;\u2019<br><img decoding=\"async\" src=\"https:\/\/www.bleuio.com\/getting_started\/img\/smart_bulb\/existing_projects.png\" alt=\"alt text\"><\/li><li>Make sure you\u2019ve choosen your workspace in \u2018Select root directory:\u2019<\/li><li>You should see the project \u201cstm32_bleuio_example\u201d, check it and click \u2018Finish\u2019.<br><img decoding=\"async\" src=\"https:\/\/www.bleuio.com\/getting_started\/img\/smart_bulb\/import_projects.png\" alt=\"alt text\"><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">6. Running the example<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>In STMCubeIDE click the hammer icon to build the project.<\/li><li>Open up the \u2018STMicroelectronics STLink Viritual COM Port\u2019 with a serial terminal emulation program like TeraTerm, Putty or CoolTerm.Serial port Setup:<br>Baudrate: 115200<br>Data Bits: 8<br>Parity: None<br>Stop Bits: 1<br>Flow Control: None<\/li><li>Connect the BleuIO Dongle before running the example .<\/li><li>In STMCubeIDE click the green play button to flash and run it on your board. The first time you click it the \u2018Run Configuration\u2019 window will appear. You can just leave it as is and click run.<\/li><li>You should be greeted by this welcome message:<img decoding=\"async\" src=\"https:\/\/www.bleuio.com\/getting_started\/img\/smart_bulb\/Welcome.png\" alt=\"Welcome!\"><\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li>Wait until the message: \u201c[BleuIO Dongle Ready]\u201d is shown.<br><br><img decoding=\"async\" src=\"https:\/\/www.bleuio.com\/getting_started\/img\/smart_bulb\/Ready_adv.png\" alt=\"Welcome!\"><\/li><li>You can now connect with the other dongle using the script.<\/li><\/ul>\n\n\n\n<p>You can also use the uart commands (0, 1 or 2):<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Press 0 to get device information.<br><br>1 to turn on lightbulb.<br><br>2 to turn off lightbulb.<br><br><br>Dongle response will be printed to UART.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">7. Controlling the light from a web browser<\/h2>\n\n\n\n<p>We wrote a simple script that connects to the dongle and sends signals to toggle the light from the web browser.<\/p>\n\n\n\n<p>For this script to work, we need<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/www.bleuio.com\/\">BleuIO USB dongle<\/a>&nbsp;connected to the computer.<\/li><li><a href=\"https:\/\/www.npmjs.com\/package\/bleuio\">BleuIO javascript library<\/a><\/li><li>Chrome 78 or later, and you need to enable the&nbsp;<strong>#enable-experimental-web-platform-features<\/strong>&nbsp;flag in&nbsp;<a href=\"chrome:\/\/flags\/\">chrome:\/\/flags<\/a><\/li><li>A web bundler \u2013 (<a href=\"https:\/\/parceljs.org\/\">parcel js<\/a>)<\/li><\/ul>\n\n\n\n<p><strong>Steps<\/strong><\/p>\n\n\n\n<p>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 signal to the remote dongle, which is connected to stm32.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html&gt;\n&lt;html lang=\"en\"&gt;\n  &lt;head&gt;\n    &lt;meta charset=\"UTF-8\" \/&gt;\n    &lt;meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" \/&gt;\n    &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" \/&gt;\n    &lt;link\n      href=\"https:\/\/cdn.jsdelivr.net\/npm\/bootstrap@5.1.3\/dist\/css\/bootstrap.min.css\"\n      rel=\"stylesheet\"\n      integrity=\"sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3\"\n      crossorigin=\"anonymous\"\n    \/&gt;\n    &lt;title&gt;Control Light using Bleutooth Low Energy&lt;\/title&gt;\n  &lt;\/head&gt;\n  &lt;body class=\"mt-5\"&gt;\n    &lt;div class=\"container mt-5\"&gt;\n      &lt;h1 class=\"mb-5\"&gt;Control Light using Bleutooth Low Energy&lt;\/h1&gt;\n      &lt;button class=\"btn btn-success\" id=\"connect\"&gt;Connect&lt;\/button&gt;\n      &lt;button class=\"btn btn-warning\" id=\"lightOn\" disabled&gt;Turn On&lt;\/button&gt;\n      &lt;button class=\"btn btn-danger\" id=\"lightOf\" disabled&gt;Turn Off&lt;\/button&gt;\n    &lt;\/div&gt;\n    &lt;div class=\"container mt-5\"&gt;\n      &lt;img id=\"light\" src=\"light_off.png\" alt=\"\" \/&gt;\n    &lt;\/div&gt;\n\n    &lt;script src=\"script.js\"&gt;&lt;\/script&gt;\n  &lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n\n\n\n<p>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.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import * as my_dongle from \"bleuio\";\nconst dongleToConnect = \"&#91;0]40:48:FD:E5:35:A5\";\nimport lightOnImg from \".\/light_on.png\";\nimport lightOfImg from \".\/light_off.png\";\ndocument.getElementById(\"connect\").addEventListener(\"click\", function () {\n  my_dongle.at_connect();\n  document.getElementById(\"lightOn\").disabled = false;\n  document.getElementById(\"lightOf\").disabled = false;\n  document.getElementById(\"connect\").disabled = true;\n});\n\ndocument.getElementById(\"lightOn\").addEventListener(\"click\", function () {\n  my_dongle\n    .ati()\n    .then((data) =&gt; {\n      \/\/make central if not\n      if (JSON.stringify(data).includes(\"Peripheral\")) {\n        console.log(\"peripheral\");\n        my_dongle.at_central().then((x) =&gt; {\n          console.log(\"central now\");\n        });\n      }\n    })\n    .then(() =&gt; {\n      \/\/ connect to dongle\n      my_dongle\n        .at_getconn()\n        .then((y) =&gt; {\n          if (JSON.stringify(y).includes(dongleToConnect)) {\n            console.log(\"already connected\");\n          } else {\n            my_dongle.at_gapconnect(dongleToConnect).then(() =&gt; {\n              console.log(\"connected successfully\");\n            });\n          }\n        })\n        .then(() =&gt; {\n          \/\/ send command to control light\n          my_dongle.at_spssend(\"L=1\").then(() =&gt; {\n            console.log(\"Turned on\");\n            document.getElementById(\"light\").src = lightOnImg;\n          });\n        });\n    });\n});\n\ndocument.getElementById(\"lightOf\").addEventListener(\"click\", function () {\n  my_dongle\n    .ati()\n    .then((data) =&gt; {\n      \/\/make central if not\n      if (JSON.stringify(data).includes(\"Peripheral\")) {\n        console.log(\"peripheral\");\n        my_dongle.at_central().then((x) =&gt; {\n          console.log(\"central now\");\n        });\n      }\n    })\n    .then(() =&gt; {\n      \/\/ connect to dongle\n      my_dongle\n        .at_getconn()\n        .then((y) =&gt; {\n          if (JSON.stringify(y).includes(dongleToConnect)) {\n            console.log(\"already connected\");\n          } else {\n            my_dongle.at_gapconnect(dongleToConnect).then(() =&gt; {\n              console.log(\"connected successfully\");\n            });\n          }\n        })\n        .then(() =&gt; {\n          \/\/ send command to control light\n          my_dongle.at_spssend(\"L=0\").then(() =&gt; {\n            console.log(\"Turned off\");\n            document.getElementById(\"light\").src = lightOfImg;\n          });\n        });\n    });\n});<\/code><\/pre>\n\n\n\n<p>The script js file has three button actions; connect and control light.<\/p>\n\n\n\n<p>Now we need to know the ID of the other dongle connected to STM32 so that we can connect to it. You can use this web terminal to get the dongle ID.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>- Open this site https:\/\/bleuio.com\/web_terminal.html and click connect to dongle.\n- Select the appropriate port to connect.\n- Once it says connected, type **\"ATI\"**. This will show dongle information and current status.\n- If the dongle is on peripheral role, set it to central by typing **\"AT+CENTRAL\"**\n- Now do a gap scan by typing **\"AT+GAPSCAN\"**\n- Once you see your dongle on the list ,stop the scan by pressing control+c\n- Copy the ID and paste it into the script (script.js) line #2<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.bleuio.com\/getting_started\/img\/smart_bulb\/scan_deviceid.gif\" alt=\"alt text\" title=\"Lightbulb.\"\/><\/figure>\n\n\n\n<p>You will need a web bundler. You can use&nbsp;<a href=\"https:\/\/parceljs.org\/\">parcel.js<\/a><\/p>\n\n\n\n<p>Once parcel js installed, go to the root directory and type&nbsp;<strong>\u201cparcel index.html\u201d<\/strong>. This will start your development environment.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.bleuio.com\/getting_started\/img\/smart_bulb\/parcel_on.jpg\" alt=\"alt text\" title=\"Lightbulb.\"\/><\/figure>\n\n\n\n<p>Open the script on a browser using parcel js.<\/p>\n\n\n\n<p>You can easily connect to the dongle and turn on-off light from there.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.bleuio.com\/getting_started\/img\/smart_bulb\/light_page.jpg\" alt=\"alt text\" title=\"Lightbulb.\"\/><\/figure>\n\n\n\n<p>You can also access the script athttps:\/\/smart-sensor-devices-ab.github.io\/stm32_bleuio_lightbulb_example\/web%20script\/dist\/index.html<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Home automation involves automating household environment equipment. To achieve that, we have created a smart bulb that is easy to install, and the attached equipment can be controlled over a web browser or smartphone app. The aim of this project is to control different home appliances using a web browser or smartphone. 1. Introduction The [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":120,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,2],"tags":[],"class_list":["post-119","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bleuio","category-bleuio-tutorial"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How To Make a BLE enabled Smart Bulb with STM32 - BleuIO - Create Bluetooth Low Energy application<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.bleuio.com\/blog\/how-to-make-a-ble-enabled-smart-bulb-with-stm32-and-bleuio\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How To Make a BLE enabled Smart Bulb with STM32 - BleuIO - Create Bluetooth Low Energy application\" \/>\n<meta property=\"og:description\" content=\"Home automation involves automating household environment equipment. To achieve that, we have created a smart bulb that is easy to install, and the attached equipment can be controlled over a web browser or smartphone app. The aim of this project is to control different home appliances using a web browser or smartphone. 1. Introduction The [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.bleuio.com\/blog\/how-to-make-a-ble-enabled-smart-bulb-with-stm32-and-bleuio\/\" \/>\n<meta property=\"og:site_name\" content=\"BleuIO - Create Bluetooth Low Energy application\" \/>\n<meta property=\"article:published_time\" content=\"2021-12-03T14:29:43+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-07-01T10:37:11+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/01\/smart_bulb_bluetooth_low_energy.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"600\" \/>\n\t<meta property=\"og:image:height\" content=\"399\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"BleuIO\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/how-to-make-a-ble-enabled-smart-bulb-with-stm32-and-bleuio\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/how-to-make-a-ble-enabled-smart-bulb-with-stm32-and-bleuio\\\/\"},\"author\":{\"name\":\"BleuIO\",\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/#\\\/schema\\\/person\\\/89bc581382d5964043f96efc54b75b80\"},\"headline\":\"How To Make a BLE enabled Smart Bulb with STM32\",\"datePublished\":\"2021-12-03T14:29:43+00:00\",\"dateModified\":\"2022-07-01T10:37:11+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/how-to-make-a-ble-enabled-smart-bulb-with-stm32-and-bleuio\\\/\"},\"wordCount\":1070,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/how-to-make-a-ble-enabled-smart-bulb-with-stm32-and-bleuio\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/01\\\/smart_bulb_bluetooth_low_energy.jpg\",\"articleSection\":[\"BleuIO\",\"BleuIO tutorial\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/how-to-make-a-ble-enabled-smart-bulb-with-stm32-and-bleuio\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/how-to-make-a-ble-enabled-smart-bulb-with-stm32-and-bleuio\\\/\",\"url\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/how-to-make-a-ble-enabled-smart-bulb-with-stm32-and-bleuio\\\/\",\"name\":\"How To Make a BLE enabled Smart Bulb with STM32 - BleuIO - Create Bluetooth Low Energy application\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/how-to-make-a-ble-enabled-smart-bulb-with-stm32-and-bleuio\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/how-to-make-a-ble-enabled-smart-bulb-with-stm32-and-bleuio\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/01\\\/smart_bulb_bluetooth_low_energy.jpg\",\"datePublished\":\"2021-12-03T14:29:43+00:00\",\"dateModified\":\"2022-07-01T10:37:11+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/#\\\/schema\\\/person\\\/89bc581382d5964043f96efc54b75b80\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/how-to-make-a-ble-enabled-smart-bulb-with-stm32-and-bleuio\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/how-to-make-a-ble-enabled-smart-bulb-with-stm32-and-bleuio\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/how-to-make-a-ble-enabled-smart-bulb-with-stm32-and-bleuio\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/01\\\/smart_bulb_bluetooth_low_energy.jpg\",\"contentUrl\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/01\\\/smart_bulb_bluetooth_low_energy.jpg\",\"width\":600,\"height\":399,\"caption\":\"Make a BLE enabled Smart Bulb with STM32\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/how-to-make-a-ble-enabled-smart-bulb-with-stm32-and-bleuio\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How To Make a BLE enabled Smart Bulb with STM32\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/\",\"name\":\"BleuIO - Create Bluetooth Low Energy application\",\"description\":\"Learn Bluetooth Low Energy programming and build Bluetooth Low Energy Application\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/#\\\/schema\\\/person\\\/89bc581382d5964043f96efc54b75b80\",\"name\":\"BleuIO\",\"sameAs\":[\"https:\\\/\\\/www.bleuio.com\\\/blog\"],\"url\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/author\\\/biadmin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How To Make a BLE enabled Smart Bulb with STM32 - BleuIO - Create Bluetooth Low Energy application","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.bleuio.com\/blog\/how-to-make-a-ble-enabled-smart-bulb-with-stm32-and-bleuio\/","og_locale":"en_US","og_type":"article","og_title":"How To Make a BLE enabled Smart Bulb with STM32 - BleuIO - Create Bluetooth Low Energy application","og_description":"Home automation involves automating household environment equipment. To achieve that, we have created a smart bulb that is easy to install, and the attached equipment can be controlled over a web browser or smartphone app. The aim of this project is to control different home appliances using a web browser or smartphone. 1. Introduction The [&hellip;]","og_url":"https:\/\/www.bleuio.com\/blog\/how-to-make-a-ble-enabled-smart-bulb-with-stm32-and-bleuio\/","og_site_name":"BleuIO - Create Bluetooth Low Energy application","article_published_time":"2021-12-03T14:29:43+00:00","article_modified_time":"2022-07-01T10:37:11+00:00","og_image":[{"width":600,"height":399,"url":"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/01\/smart_bulb_bluetooth_low_energy.jpg","type":"image\/jpeg"}],"author":"BleuIO","twitter_card":"summary_large_image","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.bleuio.com\/blog\/how-to-make-a-ble-enabled-smart-bulb-with-stm32-and-bleuio\/#article","isPartOf":{"@id":"https:\/\/www.bleuio.com\/blog\/how-to-make-a-ble-enabled-smart-bulb-with-stm32-and-bleuio\/"},"author":{"name":"BleuIO","@id":"https:\/\/www.bleuio.com\/blog\/#\/schema\/person\/89bc581382d5964043f96efc54b75b80"},"headline":"How To Make a BLE enabled Smart Bulb with STM32","datePublished":"2021-12-03T14:29:43+00:00","dateModified":"2022-07-01T10:37:11+00:00","mainEntityOfPage":{"@id":"https:\/\/www.bleuio.com\/blog\/how-to-make-a-ble-enabled-smart-bulb-with-stm32-and-bleuio\/"},"wordCount":1070,"commentCount":0,"image":{"@id":"https:\/\/www.bleuio.com\/blog\/how-to-make-a-ble-enabled-smart-bulb-with-stm32-and-bleuio\/#primaryimage"},"thumbnailUrl":"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/01\/smart_bulb_bluetooth_low_energy.jpg","articleSection":["BleuIO","BleuIO tutorial"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.bleuio.com\/blog\/how-to-make-a-ble-enabled-smart-bulb-with-stm32-and-bleuio\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.bleuio.com\/blog\/how-to-make-a-ble-enabled-smart-bulb-with-stm32-and-bleuio\/","url":"https:\/\/www.bleuio.com\/blog\/how-to-make-a-ble-enabled-smart-bulb-with-stm32-and-bleuio\/","name":"How To Make a BLE enabled Smart Bulb with STM32 - BleuIO - Create Bluetooth Low Energy application","isPartOf":{"@id":"https:\/\/www.bleuio.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.bleuio.com\/blog\/how-to-make-a-ble-enabled-smart-bulb-with-stm32-and-bleuio\/#primaryimage"},"image":{"@id":"https:\/\/www.bleuio.com\/blog\/how-to-make-a-ble-enabled-smart-bulb-with-stm32-and-bleuio\/#primaryimage"},"thumbnailUrl":"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/01\/smart_bulb_bluetooth_low_energy.jpg","datePublished":"2021-12-03T14:29:43+00:00","dateModified":"2022-07-01T10:37:11+00:00","author":{"@id":"https:\/\/www.bleuio.com\/blog\/#\/schema\/person\/89bc581382d5964043f96efc54b75b80"},"breadcrumb":{"@id":"https:\/\/www.bleuio.com\/blog\/how-to-make-a-ble-enabled-smart-bulb-with-stm32-and-bleuio\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.bleuio.com\/blog\/how-to-make-a-ble-enabled-smart-bulb-with-stm32-and-bleuio\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.bleuio.com\/blog\/how-to-make-a-ble-enabled-smart-bulb-with-stm32-and-bleuio\/#primaryimage","url":"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/01\/smart_bulb_bluetooth_low_energy.jpg","contentUrl":"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/01\/smart_bulb_bluetooth_low_energy.jpg","width":600,"height":399,"caption":"Make a BLE enabled Smart Bulb with STM32"},{"@type":"BreadcrumbList","@id":"https:\/\/www.bleuio.com\/blog\/how-to-make-a-ble-enabled-smart-bulb-with-stm32-and-bleuio\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.bleuio.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How To Make a BLE enabled Smart Bulb with STM32"}]},{"@type":"WebSite","@id":"https:\/\/www.bleuio.com\/blog\/#website","url":"https:\/\/www.bleuio.com\/blog\/","name":"BleuIO - Create Bluetooth Low Energy application","description":"Learn Bluetooth Low Energy programming and build Bluetooth Low Energy Application","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.bleuio.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.bleuio.com\/blog\/#\/schema\/person\/89bc581382d5964043f96efc54b75b80","name":"BleuIO","sameAs":["https:\/\/www.bleuio.com\/blog"],"url":"https:\/\/www.bleuio.com\/blog\/author\/biadmin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.bleuio.com\/blog\/wp-json\/wp\/v2\/posts\/119","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bleuio.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bleuio.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bleuio.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bleuio.com\/blog\/wp-json\/wp\/v2\/comments?post=119"}],"version-history":[{"count":3,"href":"https:\/\/www.bleuio.com\/blog\/wp-json\/wp\/v2\/posts\/119\/revisions"}],"predecessor-version":[{"id":269,"href":"https:\/\/www.bleuio.com\/blog\/wp-json\/wp\/v2\/posts\/119\/revisions\/269"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bleuio.com\/blog\/wp-json\/wp\/v2\/media\/120"}],"wp:attachment":[{"href":"https:\/\/www.bleuio.com\/blog\/wp-json\/wp\/v2\/media?parent=119"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bleuio.com\/blog\/wp-json\/wp\/v2\/categories?post=119"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bleuio.com\/blog\/wp-json\/wp\/v2\/tags?post=119"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}