{"id":13808166,"url":"https://github.com/EngstromJimmy/Blazm.Bluetooth","last_synced_at":"2025-05-14T02:31:19.844Z","repository":{"id":37767736,"uuid":"263089111","full_name":"EngstromJimmy/Blazm.Bluetooth","owner":"EngstromJimmy","description":null,"archived":false,"fork":false,"pushed_at":"2022-12-08T14:58:36.000Z","size":879,"stargazers_count":80,"open_issues_count":5,"forks_count":13,"subscribers_count":7,"default_branch":"main","last_synced_at":"2024-08-04T01:09:23.305Z","etag":null,"topics":["blazor","bluetooth"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/EngstromJimmy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"EngstromJimmy"}},"created_at":"2020-05-11T15:54:31.000Z","updated_at":"2024-06-18T22:46:08.000Z","dependencies_parsed_at":"2023-01-25T13:46:12.628Z","dependency_job_id":null,"html_url":"https://github.com/EngstromJimmy/Blazm.Bluetooth","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EngstromJimmy%2FBlazm.Bluetooth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EngstromJimmy%2FBlazm.Bluetooth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EngstromJimmy%2FBlazm.Bluetooth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EngstromJimmy%2FBlazm.Bluetooth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EngstromJimmy","download_url":"https://codeload.github.com/EngstromJimmy/Blazm.Bluetooth/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225273220,"owners_count":17448071,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blazor","bluetooth"],"created_at":"2024-08-04T01:01:36.515Z","updated_at":"2024-11-19T00:30:35.712Z","avatar_url":"https://github.com/EngstromJimmy.png","language":"C#","funding_links":["https://github.com/sponsors/EngstromJimmy"],"categories":["Libraries \u0026 Extensions"],"sub_categories":["Tools \u0026 Utilities"],"readme":"# How to use Blazm.Bluetooth\n\nBlazm.Bluetooth makes it easy to connect Blazor to your Bluetooth devices using Web Bluetooth.\n\nWorks both Client-side and Server-side.\n\n## Sponsors\nThanks you to much to my sponsors!  \n![](https://raw.githubusercontent.com/EngstromJimmy/Blazm.Components/master/Display%20Ads%20Horizontal%20Leaderboard%20728x90%20TOP_RITM0148003.png)\n\n\nTelerik UI for Blazor – Increase productivity and cut cost in half! Use the Telerik truly native Blazor UI components and high-performing grid to cover any app scenario. [Give it a try for free.](https://www.telerik.com/blazor-ui?utm_source=jimmyengstrom\u0026utm_medium=cpm\u0026utm_campaign=blazor-trial-github-blazmcomp-sponsored-message )\n\n\n## Getting Started\n\n1. Add Nuget package Blazm.Bluetooth\n2. In Program.cs add ```builder.Services.AddBlazmBluetooth();```\n3. In the component you want to connect to a device add the Blazm.Bluetooth Namespace\n```@using Blazm.Bluetooth```\n4. Inject the IBluetoothNavigator (the instance that will communicate with your device)\n```@inject IBluetoothNavigator navigator```\n\nNow you are all setup now it is time to connect to a device.\n\n## Connecting to a device\n\nYou need to create a query or a filter to filter devices, you could also specify ```AcceptAllDevices``` but that is only recommended while testing.\nTo take a look at available devices you can use (for Microsoft Edge) edge://bluetooth-internals.\nYou can query devices using a ServiceId or by name, you also have to specify all the services that you want to access in ```OptionalServices```\n\nTo connect to an Andersson (SenSun) scale you need to do the following (check Pages/AnderssonScaleDemo for more info)\nSpecify the ServiceId and CharacteristicId you want to communicate with.\n\n``` cs\nvar serviceId = \"0000ffb0-0000-1000-8000-00805f9b34fb\";\nvar characteristicId = \"0000ffb2-0000-1000-8000-00805f9b34fb\";\n```\n\nCreate a filter\n\n``` cs\nvar q = new RequestDeviceQuery();\nq.Filters.Add(new Filter() { Services = { serviceId } });\n```\n\nRequest a device\n\n``` cs\nvar device = await navigator.RequestDeviceAsync(q);\n```\n\nThis will return a device and it contains an id that you can use to read, write, or set up notifications.\nCall the ```SetupNotifyAsync``` to get notifications when the value changes.\n\n``` cs\nawait device.SetupNotifyAsync(serviceid, characteristics);\ndevice.Notification += Value_Notification;\n``` \n\nand add an event listener that parses the data from the notification.\n\n``` cs\nprivate void Value_Notification(object sender, CharacteristicEventArgs e)\n{\n    var data = e.Value.ToArray();\n    \n    // Do something with the data\n\n    StateHasChanged();\n}\n```\n\nThe same thing goes for read and write\n``` cs\n//Write\nawait device.WriteValueAsync(serviceid,characteristicsid,value);\n\n//Read\nvar bytes = await device.ReadValueAsync(serviceid, characteristicId);\n```\n\nThere is still many scenarios to implement but this should cover the basics.\n\nPlease feel free to add ideas /problems/needs you might have or make a PR.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FEngstromJimmy%2FBlazm.Bluetooth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FEngstromJimmy%2FBlazm.Bluetooth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FEngstromJimmy%2FBlazm.Bluetooth/lists"}