Quick C# application to connect with a Bluetooth LE device

  Переглядів 29,270

Cornel Human

Cornel Human

День тому

Quickly create a C# application to read values from a Bluetooth Low Energy device. This application is a Dot.Net 4.7.2 console application that uses the Universal Windows Platform libraries to interact with Bluetooth LE. The specific device is a Wahoo Tickr heart rate monitor. Learn the basics of discovering devices, pairing a device and subscribing for notifications.
Bluetooth LE on UWP
docs.microsoft.com/en-us/wind...
Project references for Windows.winmd and System.Runtime.WindowsRuntime.dll
C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.19041.0\Windows.winmd
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Runtime.WindowsRuntime.dll
Bluetooth Assigned Number
www.bluetooth.com/specificati...
Data Formats for Bluetooth devices
This is a pdf and you should be able to find your device in specific measurement inside this document
www.bluetooth.org/DocMan/hand...
Bluetooth Heart Rate Sensor Data Format Document
www.silabs.com/documents/publ...
Project Git Repo
github.com/cornelhuman/QuickB...
Related UKposts content from AngelSix
• Discovering Bluetooth ...
0:00 Start
0:42 Create C# console application Dot.Net 4.7.2
1:41 Detect nearby devices
2:20 Add project references to be able to work with Bluetooth LE
3:02 Update using statements and implement event handlers
3:53 Handle DeviceWatcher_Added event
4:40 Create a while loop to wait for application input
6:53 Keep a reference to desired device
8:24 Pair with Bluetooth LE device
12:22 Get list of GATT services for paired device
14:34 Proceed with Heart Rate Monitor Service with partial Uuid 0000180d
20:59 Check if GATT service match 180D service for heart rate data
26:37 Subscribing for notifications
31:38 Deal with actual data that is received from Bluetooth LE device (16 bits) first byte is flags, second byte is heart rate value
34:48 Display correct values

КОМЕНТАРІ: 63
@wayahedia9989
@wayahedia9989 2 роки тому
Excellent. It's more informative watching someone work it out than it is when they've already worked it out before producing the video. Well done.
@numberjuan6332
@numberjuan6332 Рік тому
you're a legend! Showing the process was extremely helpful; like showing the process and then showing the documentation because this is my first time making anything with c#. Thanks for the video!
@ottomaier7127
@ottomaier7127 11 місяців тому
The first C# bluetooth video that really works... Thank you!
@EliasIoannou
@EliasIoannou Рік тому
You are an absolute BEAST. Thank you so much for this tutorial!
@ivanonwan3524
@ivanonwan3524 4 місяці тому
Awesome, thank you very much for your tutorial. Very enlightening. I missed a part with the "writing" capabilities of this.
@briant44
@briant44 5 місяців тому
Great video Cornel. Planning to use my new found knowledge to read a bluetooth temperature module. Thanks a lot. I have liked and subscribed.
@poulchristensen7142
@poulchristensen7142 Місяць тому
Thanks for this very cool video. This was just what I needed to get started 😊
@alibek3006
@alibek3006 Рік тому
Thank you for tutorial. Helped a lot!
@Krobel1706
@Krobel1706 2 роки тому
Thanks! Very good video in every aspect.
@dhakshayinikoppad1411
@dhakshayinikoppad1411 Рік тому
Hello Cornel, The 2 references you added, Wndows.WinMD and system.runtime.windowsruntime. I dont have those in my paths you have mentioned. Can you explain on how to get them?
@user-if7kr4hb3b
@user-if7kr4hb3b 10 місяців тому
search the name directly. I think they may store differently
@pats22fos
@pats22fos 26 днів тому
I had this problem. I needed to go the the VS installer and download the relevant modules. I think it was the "Data Storage and processing" workload, in particular the Windows 10 and 11 SDKS: 10.0. -22000.0, -20348.0, -19041.0, -18362.0
@user-yx4tb1sm7m
@user-yx4tb1sm7m 9 місяців тому
thanks! i added some write function in your code so i was able to test BLE module byte by byte in handler I was a bit confused when I first referenced it, but it seems to work fine in the end. I simply checked the received value of 1 byte sent, but now I think I can operate it continuously.
@eugenejayachandra5122
@eugenejayachandra5122 Рік тому
Thank you. This healped
@eliudgarciadiaz8646
@eliudgarciadiaz8646 2 роки тому
Good information. But I have a question, in a scenario where you have 2 different devices and each one has a barcode with serial number which contains part of the information that appears in the name of the device you want to find, once you pass the 2 devices, and a negative test is done to scan the 1st device but only turns on the 2nd, this routine keeps stored all scanned devices, as if there were a system variable, and still detects the first device as if it were on. . . . . how to make this not happen?
@sonus89
@sonus89 2 роки тому
Excellent video!!! ( The volume is a bit low )
@Tzuyu-fg4qy
@Tzuyu-fg4qy 2 роки тому
excellent!but, a personal question...how can my pc connect to wahoo tickr😢 I have write the same code in visual studio, but "Console.WriteLine(args.Name) " as 6'23 in the video didn't appear my tickr name.
@aleksander5784
@aleksander5784 7 місяців тому
Thanks
@pauldavis5635
@pauldavis5635 Рік тому
I can't really read the code you are working with. Do you share it for download??
@White_Rose19
@White_Rose19 3 місяці тому
Can you please tell how to migrate this code from console .Net framework to WPF.
@chiyouyu6469
@chiyouyu6469 2 роки тому
How to find my TICKR? THANKS
@abhishekmor6929
@abhishekmor6929 Рік тому
Very informative. Thanks for the video. I am using your code to connect with our Nonin 3230 oximeter but its not reading, condition for GattCharacteristicProperties.Notify never met true. Can you please help us on this. 🙏
@steevebreton2736
@steevebreton2736 2 роки тому
Thanks for this exemple. It works well. 🙂 Where did you find the information about the references you need to add to get Windows.Devices.Enumeration?
@cornelhuman1940
@cornelhuman1940 2 роки тому
This documents describes where to find the references - blogs.windows.com/windowsdeveloper/2017/01/25/calling-windows-10-apis-desktop-application/
@adriellenazar
@adriellenazar 2 роки тому
I would also like to know this. I cannot see your reply above.
@wervisMM
@wervisMM Рік тому
Instead of all the references you could also add the Microsoft.Windows.SDK.Contracts Nuget package.
@eliaspantzier6872
@eliaspantzier6872 Рік тому
THX! that helped me a lot!
@LangrennsPortalen
@LangrennsPortalen Рік тому
Will this work/be as easy for Mac? Have a master task on the university and I have to connect the wahoo kickr core to my Mac (programming in python)
@cornelhuman1940
@cornelhuman1940 Рік тому
Hi Eirik, I have not attempted to do Bluetooth Low Energy on a mac. I suspect you will need to look at objective c libraries. I unfortunately cant help on the mac or python front.
@Allyourneedsmet
@Allyourneedsmet 4 місяці тому
what are the prerequisites to know before diving in?, Is this systems programming, hardware or network programming?, I would like to know how to fish
@zorannajdovski2820
@zorannajdovski2820 Рік тому
Great Video Cornel. Thanks for sharing. Any idea how to maintain a connection with a device that has dropped out or turned off/on again? Cheers
@wervisMM
@wervisMM Рік тому
I experience the issue. Did you solve this issue?
@masterpc-9845x
@masterpc-9845x 2 роки тому
Thanks bro, really helped me for the most part here. I have a different device here, that reads in data of someone's skin from a sensor (it's a skincare device btw). And I'm also trying to get the program to display the device info, and I am stuck at this point.
@cornelhuman1940
@cornelhuman1940 2 роки тому
@Master PC, I suspects you don't know the data format for your device? There is a lot of information in a pdf on the Bluetooth.com website www.bluetooth.com/specifications/assigned-numbers/ Have a look at GATT Specification Supplement it has all the data specifications. Hopefully you can find what you looking for there.
@dotnetdevni
@dotnetdevni 2 роки тому
Surley it should ask for paring code thru csharp aint that the whole point of bluetooh security in theory anyone could listen in on ur hr monitor
@cornelhuman1940
@cornelhuman1940 2 роки тому
@@dotnetdevni it depends on the device so for my specific devices it does not require a code. docs.microsoft.com/en-us/windows/uwp/devices-sensors/bluetooth-dev-faq#do-i-have-to-pair-bluetooth-devices-before-using-them-
@1stfanofsonic
@1stfanofsonic 2 роки тому
Thank you so much for your video, can you also make a video for GATT server application?
@cornelhuman1940
@cornelhuman1940 2 роки тому
Hi Bora, a GATT Server would be implemented on the actual Bluetooth device. This would be a fun project, but would involve a fair amount of electronics and embedded development. I am somewhat time constrained so for the moment I cant help on that front.
@KishoreKumar-xt7pz
@KishoreKumar-xt7pz 2 місяці тому
Excellent. information i am getting exception line number 80 WriteClientCharacteristicConfigurationDescriptorAsync could you help on this if i use WriteClientCharacteristicConfigurationDescriptorWithResultAsync status is protocolerror 0x03
@ATMIKES123456
@ATMIKES123456 Рік тому
Thank you very much, it worked all very fine! Now I have a question: I have a self built device with 5 characteristics I can subscribe to (gyro, force, etc). After i subscribe to one of them i would like to unsubscribe from it and subscribe to another. I can remove the listener on my .net client, but i realized that my device still sends the data I subscribed in the first place. Is there a way to tell it to stop sending data? Thanks a lot!
@cornelhuman1940
@cornelhuman1940 Рік тому
I think there is a disconnect command, just make sure that you dont have multiple connection open.
@dotnetdevni
@dotnetdevni 2 роки тому
Does ifit connect in same method have a treadmil and am sick paying ifit subscriptions
@cornelhuman1940
@cornelhuman1940 2 роки тому
Hi David, You should be able to list the GATT services your treadmill expose. If it has the Fitness Machine Service, it is fairly generic between all the fitness providers. And changing resistance or power values are relatively simple.
@kondurmadhu4506
@kondurmadhu4506 2 роки тому
Hi Cornel. Firstly I would like to thank you for the video and knowledge you shared. With the same code I could not see the other windows/android mobile bluetooth enabled devices online. Will it work only for few devices? Please reply.
@cornelhuman1940
@cornelhuman1940 2 роки тому
Hi Kondur, yes, that would be expected. With Bluetooth LE, the LE is (Low Energy) devices. They are not the same as normal Bluetooth devices. So the way to connect and interact is different. The Types of devices I have connected with are Heart Rate Monitor, Cadence monitor, KICKR Core training bike and I suspect many more.
@juzijuzi3117
@juzijuzi3117 2 роки тому
How to automatically generate "();"
@nevcivanokumus2295
@nevcivanokumus2295 2 роки тому
Hello; This video is very excellent and helped me . However ı am stuck in somewhere. I want to send a value to my ESP32 module.But ı didnt this.Will you add new videos this ? or can you help me this topic.
@cornelhuman1940
@cornelhuman1940 2 роки тому
I will have a look at my Kickr Core Smart Trainer to see if I can set the power values and how to do this.
@sude3925
@sude3925 11 місяців тому
Selam nevcivan sorununu çözebildin mi acaba? Çözdüysen hangi kaynaklardan yararlandın, ne önerirsin acaba?
@hynesie11
@hynesie11 2 роки тому
God damn, it took me an hour and a half to get as far as 3:38.
@sleeplesslights795
@sleeplesslights795 2 роки тому
How did you get past this? I'm stuck in the same place.
@hynesie11
@hynesie11 2 роки тому
@@sleeplesslights795 keep watching and he explains it. You have to use NuGet to add packages to the project.
@manofsteel6923
@manofsteel6923 2 роки тому
I tried this same method to connect to huwavei fit 2. Its showing ,if (result.Status == GattCommunicationStatus.Success), showing result.Status as unreachable
@wervisMM
@wervisMM Рік тому
Have the same error message. It occures when the device is paired but not connected. Did you find a solution?
@hiltongallagher5657
@hiltongallagher5657 Рік тому
Hey @@wervisMM Did you happen to find a fix for this 😅. I'm really struggling with this issue.
@hiltongallagher5657
@hiltongallagher5657 Рік тому
Hi Man of steel, please tell me you found and answer to your question somewhere? Anywhere? 🙏
@brownhong8473
@brownhong8473 10 місяців тому
me. too. did you solved it?
Everything you need to know about Bluetooth Low Energy advertising
1:03:22
Nordic Semiconductor
Переглядів 30 тис.
Master BLE Basics in Just 10 Minutes: The Ultimate Guide!
9:15
Novel Bits
Переглядів 86 тис.
McDonald’s MCNUGGET PURSE?! #shorts
00:11
Lauren Godwin
Переглядів 23 млн
Godzilla Attacks Brawl Stars!!!
00:39
Brawl Stars
Переглядів 4,8 млн
Завтра в школу с... | Шоу-квиз «Вопросики»
00:28
Телеканал СОЛНЦЕ
Переглядів 3,2 млн
Reading Bluetooth LE Device Details C# WPF
1:12:08
AngelSix
Переглядів 22 тис.
Using Web BLE to detect and get GATT information
19:41
Sayanee Basu
Переглядів 27 тис.
Building Android Apps to Control Bluetooth LE Devices
38:51
CrossComm, Inc.
Переглядів 34 тис.
Pairing Bluetooth Devices in Windows C#
56:26
AngelSix
Переглядів 19 тис.
C# application to get Real time Bluetooth Low energy data
0:56
Smart Sensor Devices AB
Переглядів 7 тис.
План хакера 🤯 #shorts #фильмы
0:59
BruuHub
Переглядів 989 тис.
Почему сканер ставят так не удобно?
0:47
Не шарю!
Переглядів 697 тис.
Broken Flex Repair #technology #mobilerepair
0:55
ideal institute aligarh
Переглядів 15 млн
Компьютер подписчику
0:40
Miracle
Переглядів 193 тис.
Start from 0 at any point on the T1 Digital Tape Measure
0:14
REEKON Tools
Переглядів 20 млн