{"id":127,"date":"2022-01-05T14:32:58","date_gmt":"2022-01-05T14:32:58","guid":{"rendered":"https:\/\/www.bleuio.com\/blog\/?p=127"},"modified":"2022-07-01T10:36:52","modified_gmt":"2022-07-01T10:36:52","slug":"create-bleutooth-low-energy-application-with-c-and-bleuio","status":"publish","type":"post","link":"https:\/\/www.bleuio.com\/blog\/create-bleutooth-low-energy-application-with-c-and-bleuio\/","title":{"rendered":"Create Bleutooth Low Energy Application with C# and BleuIO"},"content":{"rendered":"\n<p><strong>Bluetooth Low Energy (BLE)<\/strong>&nbsp;is a low power wireless&nbsp;technology used for connecting devices with each other. It is a popular communication method especially in the era of Internet of Things. Several devices around the house have a build-in buetooth transceiver and most of them provide really useful capabilitites to automate jobs. For that reason it is really interesting to be able to create a main-device (like a PC) which will have an application that connects to the devices around the house and manage them.<\/p>\n\n\n\n<p>In this example we are going to create a simple C# console application to communicate with BleuIO using SerialPort. This script can be used to create Bluetooth Low Energy application using C# with BleuIO.<\/p>\n\n\n\n<p><strong>Let\u2019s start<\/strong><\/p>\n\n\n\n<p>As a first step lets create a new project in visual studio and select C# console application from the list.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/dev.smartsensordevices.com\/wp-content\/uploads\/2022\/01\/image-1024x172.png\" alt=\"This image has an empty alt attribute; its file name is image-1024x172.png\"\/><\/figure>\n\n\n\n<p>Choose a suitable name for your project and paste the following code to Program.cs file.<\/p>\n\n\n\n<p>The source code is available at&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/smart-sensor-devices-ab\/bluetooth_low_energy_csharp\" target=\"_blank\">github<\/a>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using System;\nusing System.IO.Ports;\nusing System.Text;\n\nnamespace SerialPortExample\n{\n    class SerialPortProgram\n    {                \n        static SerialPort _port;\n        static void Main(string&#91;] args)\n        {\n            string portName;\n            portName = SetPortName();\n            _port = new SerialPort(portName,57600, Parity.None, 8, StopBits.One);\n            \/\/ Instatiate this class\n            SerialPortProgram serialPortProgram = new SerialPortProgram();\n        }\n\n        private SerialPortProgram()\n        {\n            _port.DataReceived += new\n              SerialDataReceivedEventHandler(port_DataReceived);\n            OpenMyPort();\n            Console.WriteLine(\"Type q to exit.\");\n            bool continueLoop = true;\n            string inputCmd;\n\n            while (continueLoop)\n            {\n                inputCmd = Console.ReadLine();\n\n                if (inputCmd == \"q\")\n                {\n                    continueLoop = false;\n                    break;\n                }\n                else\n                {\n                    byte&#91;] bytes = Encoding.UTF8.GetBytes(inputCmd);\n                    var inputByte = new byte&#91;] { 13 };\n                    bytes = bytes.Concat(inputByte).ToArray();\n                    _port.Write(bytes, 0, bytes.Length);\n                }\n            }\n        }\n\n        private void port_DataReceived(object sender,\n          SerialDataReceivedEventArgs e)\n        {           \n            \/\/ Show all the incoming data in the port's buffer\n            Console.WriteLine(_port.ReadExisting());\n        }\n\n        \/\/Open selected COM port\n        private static void OpenMyPort()\n        {\n            try\n            {\n                _port.Open();\n            }\n            catch (Exception ex)\n            {\n                Console.WriteLine(\"Error opening my port: {0}\", ex.Message);\n                Environment.Exit(0);\n            }\n        }\n\n        \/\/ Display Port values and prompt user to enter a port.\n        public static string SetPortName()\n        {\n            string portName;\n\n            Console.WriteLine(\"Available Ports:\");\n            foreach (string s in SerialPort.GetPortNames())\n            {\n                Console.WriteLine(\"   {0}\", s);\n            }\n\n            Console.Write(\"Enter COM port value (ex: COM18): \");\n            portName = Console.ReadLine();\n            return portName;\n        }\n\n    }\n}<\/code><\/pre>\n\n\n\n<p>For this script a BleuIO dongle connected to the computer.<\/p>\n\n\n\n<p>When we run the application, it suggests all the available ports on the computer and asks to write the com port number where the BleuIO is connected.<\/p>\n\n\n\n<p>Once we write the correct port number, it starts communicating with BleuIO via SerialPort.<\/p>\n\n\n\n<p>The response of AT commands from the BleuIO will be shown on the screen.<\/p>\n\n\n\n<p>Find the list of available AT commands at&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/www.bleuio.com\/getting_started\/docs\/commands\/\" target=\"_blank\">BleuIO getting started guide.<\/a><\/p>\n\n\n\n<p>The application will terminate with control+c or type \u2018q\u2019.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Bluetooth Low Energy (BLE)&nbsp;is a low power wireless&nbsp;technology used for connecting devices with each other. It is a popular communication method especially in the era of Internet of Things. Several devices around the house have a build-in buetooth transceiver and most of them provide really useful capabilitites to automate jobs. For that reason it is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":128,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,2],"tags":[],"class_list":["post-127","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.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Create Bleutooth Low Energy Application with C# and BleuIO - 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\/create-bleutooth-low-energy-application-with-c-and-bleuio\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Create Bleutooth Low Energy Application with C# and BleuIO - BleuIO - Create Bluetooth Low Energy application\" \/>\n<meta property=\"og:description\" content=\"Bluetooth Low Energy (BLE)&nbsp;is a low power wireless&nbsp;technology used for connecting devices with each other. It is a popular communication method especially in the era of Internet of Things. Several devices around the house have a build-in buetooth transceiver and most of them provide really useful capabilitites to automate jobs. For that reason it is [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.bleuio.com\/blog\/create-bleutooth-low-energy-application-with-c-and-bleuio\/\" \/>\n<meta property=\"og:site_name\" content=\"BleuIO - Create Bluetooth Low Energy application\" \/>\n<meta property=\"article:published_time\" content=\"2022-01-05T14:32:58+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-07-01T10:36:52+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/01\/c-ble.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"662\" \/>\n\t<meta property=\"og:image:height\" content=\"324\" \/>\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\\\/create-bleutooth-low-energy-application-with-c-and-bleuio\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/create-bleutooth-low-energy-application-with-c-and-bleuio\\\/\"},\"author\":{\"name\":\"BleuIO\",\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/#\\\/schema\\\/person\\\/89bc581382d5964043f96efc54b75b80\"},\"headline\":\"Create Bleutooth Low Energy Application with C# and BleuIO\",\"datePublished\":\"2022-01-05T14:32:58+00:00\",\"dateModified\":\"2022-07-01T10:36:52+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/create-bleutooth-low-energy-application-with-c-and-bleuio\\\/\"},\"wordCount\":265,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/create-bleutooth-low-energy-application-with-c-and-bleuio\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/01\\\/c-ble.jpg\",\"articleSection\":[\"BleuIO\",\"BleuIO tutorial\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/create-bleutooth-low-energy-application-with-c-and-bleuio\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/create-bleutooth-low-energy-application-with-c-and-bleuio\\\/\",\"url\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/create-bleutooth-low-energy-application-with-c-and-bleuio\\\/\",\"name\":\"Create Bleutooth Low Energy Application with C# and BleuIO - BleuIO - Create Bluetooth Low Energy application\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/create-bleutooth-low-energy-application-with-c-and-bleuio\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/create-bleutooth-low-energy-application-with-c-and-bleuio\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/01\\\/c-ble.jpg\",\"datePublished\":\"2022-01-05T14:32:58+00:00\",\"dateModified\":\"2022-07-01T10:36:52+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/#\\\/schema\\\/person\\\/89bc581382d5964043f96efc54b75b80\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/create-bleutooth-low-energy-application-with-c-and-bleuio\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/create-bleutooth-low-energy-application-with-c-and-bleuio\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/create-bleutooth-low-energy-application-with-c-and-bleuio\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/01\\\/c-ble.jpg\",\"contentUrl\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/01\\\/c-ble.jpg\",\"width\":662,\"height\":324,\"caption\":\"Create Bleutooth Low Energy Application with C#\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/create-bleutooth-low-energy-application-with-c-and-bleuio\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.bleuio.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Create Bleutooth Low Energy Application with C# and BleuIO\"}]},{\"@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":"Create Bleutooth Low Energy Application with C# and BleuIO - 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\/create-bleutooth-low-energy-application-with-c-and-bleuio\/","og_locale":"en_US","og_type":"article","og_title":"Create Bleutooth Low Energy Application with C# and BleuIO - BleuIO - Create Bluetooth Low Energy application","og_description":"Bluetooth Low Energy (BLE)&nbsp;is a low power wireless&nbsp;technology used for connecting devices with each other. It is a popular communication method especially in the era of Internet of Things. Several devices around the house have a build-in buetooth transceiver and most of them provide really useful capabilitites to automate jobs. For that reason it is [&hellip;]","og_url":"https:\/\/www.bleuio.com\/blog\/create-bleutooth-low-energy-application-with-c-and-bleuio\/","og_site_name":"BleuIO - Create Bluetooth Low Energy application","article_published_time":"2022-01-05T14:32:58+00:00","article_modified_time":"2022-07-01T10:36:52+00:00","og_image":[{"width":662,"height":324,"url":"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/01\/c-ble.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\/create-bleutooth-low-energy-application-with-c-and-bleuio\/#article","isPartOf":{"@id":"https:\/\/www.bleuio.com\/blog\/create-bleutooth-low-energy-application-with-c-and-bleuio\/"},"author":{"name":"BleuIO","@id":"https:\/\/www.bleuio.com\/blog\/#\/schema\/person\/89bc581382d5964043f96efc54b75b80"},"headline":"Create Bleutooth Low Energy Application with C# and BleuIO","datePublished":"2022-01-05T14:32:58+00:00","dateModified":"2022-07-01T10:36:52+00:00","mainEntityOfPage":{"@id":"https:\/\/www.bleuio.com\/blog\/create-bleutooth-low-energy-application-with-c-and-bleuio\/"},"wordCount":265,"commentCount":0,"image":{"@id":"https:\/\/www.bleuio.com\/blog\/create-bleutooth-low-energy-application-with-c-and-bleuio\/#primaryimage"},"thumbnailUrl":"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/01\/c-ble.jpg","articleSection":["BleuIO","BleuIO tutorial"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.bleuio.com\/blog\/create-bleutooth-low-energy-application-with-c-and-bleuio\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.bleuio.com\/blog\/create-bleutooth-low-energy-application-with-c-and-bleuio\/","url":"https:\/\/www.bleuio.com\/blog\/create-bleutooth-low-energy-application-with-c-and-bleuio\/","name":"Create Bleutooth Low Energy Application with C# and BleuIO - BleuIO - Create Bluetooth Low Energy application","isPartOf":{"@id":"https:\/\/www.bleuio.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.bleuio.com\/blog\/create-bleutooth-low-energy-application-with-c-and-bleuio\/#primaryimage"},"image":{"@id":"https:\/\/www.bleuio.com\/blog\/create-bleutooth-low-energy-application-with-c-and-bleuio\/#primaryimage"},"thumbnailUrl":"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/01\/c-ble.jpg","datePublished":"2022-01-05T14:32:58+00:00","dateModified":"2022-07-01T10:36:52+00:00","author":{"@id":"https:\/\/www.bleuio.com\/blog\/#\/schema\/person\/89bc581382d5964043f96efc54b75b80"},"breadcrumb":{"@id":"https:\/\/www.bleuio.com\/blog\/create-bleutooth-low-energy-application-with-c-and-bleuio\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.bleuio.com\/blog\/create-bleutooth-low-energy-application-with-c-and-bleuio\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.bleuio.com\/blog\/create-bleutooth-low-energy-application-with-c-and-bleuio\/#primaryimage","url":"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/01\/c-ble.jpg","contentUrl":"https:\/\/www.bleuio.com\/blog\/wp-content\/uploads\/2022\/01\/c-ble.jpg","width":662,"height":324,"caption":"Create Bleutooth Low Energy Application with C#"},{"@type":"BreadcrumbList","@id":"https:\/\/www.bleuio.com\/blog\/create-bleutooth-low-energy-application-with-c-and-bleuio\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.bleuio.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Create Bleutooth Low Energy Application with C# and BleuIO"}]},{"@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\/127","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=127"}],"version-history":[{"count":1,"href":"https:\/\/www.bleuio.com\/blog\/wp-json\/wp\/v2\/posts\/127\/revisions"}],"predecessor-version":[{"id":129,"href":"https:\/\/www.bleuio.com\/blog\/wp-json\/wp\/v2\/posts\/127\/revisions\/129"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bleuio.com\/blog\/wp-json\/wp\/v2\/media\/128"}],"wp:attachment":[{"href":"https:\/\/www.bleuio.com\/blog\/wp-json\/wp\/v2\/media?parent=127"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bleuio.com\/blog\/wp-json\/wp\/v2\/categories?post=127"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bleuio.com\/blog\/wp-json\/wp\/v2\/tags?post=127"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}