{"id":1189,"url":"https://github.com/LGBluetooth/LGBluetooth","last_synced_at":"2025-07-30T20:32:44.445Z","repository":{"id":30377632,"uuid":"33930255","full_name":"LGBluetooth/LGBluetooth","owner":"LGBluetooth","description":"Simple, block-based, lightweight library over CoreBluetooth. Will clean up your Core Bluetooth related code.","archived":false,"fork":false,"pushed_at":"2019-01-23T17:55:45.000Z","size":763,"stargazers_count":175,"open_issues_count":12,"forks_count":55,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-11-22T06:02:45.355Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LGBluetooth.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-14T12:27:25.000Z","updated_at":"2024-06-11T02:38:05.000Z","dependencies_parsed_at":"2022-09-08T08:50:46.104Z","dependency_job_id":null,"html_url":"https://github.com/LGBluetooth/LGBluetooth","commit_stats":null,"previous_names":["l0gg3r/lgbluetooth"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LGBluetooth%2FLGBluetooth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LGBluetooth%2FLGBluetooth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LGBluetooth%2FLGBluetooth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LGBluetooth%2FLGBluetooth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LGBluetooth","download_url":"https://codeload.github.com/LGBluetooth/LGBluetooth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228187565,"owners_count":17882326,"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":[],"created_at":"2024-01-05T20:15:40.868Z","updated_at":"2024-12-04T20:31:05.741Z","avatar_url":"https://github.com/LGBluetooth.png","language":"Objective-C","funding_links":[],"categories":["Hardware"],"sub_categories":["Bluetooth","Other free courses"],"readme":"LGBluetooth\n===========\n\nSimple, block-based, lightweight library over CoreBluetooth.\n\n\u003ch2\u003eSteps to start using\u003c/h2\u003e\n\n1. Drag and Drop it into your project\n\n2. Import \"LGBluetooth.h\"\n\n3. You are ready to go!\n\n\u003ch2\u003eUsage\u003c/h2\u003e\n\nFor example we have a peripheral which has \"5ec0\" service, with 3 characteristics\n\u003cimg src=\"https://raw.github.com/l0gg3r/LGBluetooth/master/Screenshots/1.PNG\" width=\"320\" height=\"480\"\u003e\u003cbr\u003e\n\n* \"cef9\" characteristic is writable\n* \"f045\" characteristic is readable\n* \"8fdb\" characteristic is readable\n\n\u003cpre\u003e\n- (IBAction)testPressed:(UIButton *)sender\n{\n    [[LGCentralManager sharedInstance] scanForPeripheralsByInterval:4\n                                                         completion:^(NSArray *peripherals)\n     {\n         if (peripherals.count) {\n             [self testPeripheral:peripherals[0]];\n         }\n     }];\n}\n\n- (void)testPeripheral:(LGPeripheral *)peripheral\n{   \n    // First of all, opening connection\n    [peripheral connectWithCompletion:^(NSError *error) {\n        // Discovering services of peripheral\n        [peripheral discoverServicesWithCompletion:^(NSArray *services, NSError *error) {\n            // Searching in all services, our - 5ec0 service\n            for (LGService *service in services) {\n                if ([service.UUIDString isEqualToString:@\"5ec0\"]) {\n                    // Discovering characteristics of 5ec0 service\n                    [service discoverCharacteristicsWithCompletion:^(NSArray *characteristics, NSError *error) {\n                        __block int i = 0;\n                        // Searching writable characteristic - cef9\n                        for (LGCharacteristic *charact in characteristics) {\n                            if ([charact.UUIDString isEqualToString:@\"cef9\"]) {\n                                [charact writeByte:0xFF completion:^(NSError *error) {\n                                    if (++i == 3) {\n                                        [peripheral disconnectWithCompletion:nil];\n                                    }\n                                }];\n                            } else {\n                                // Otherwise reading value\n                                [charact readValueWithBlock:^(NSData *data, NSError *error) {\n                                    if (++i == 3) {\n                                        [peripheral disconnectWithCompletion:nil];\n                                    }\n                                }];\n                            }\n                        }\n                    }];\n                }\n            }\n        }];\n    }];\n}\n\u003c/pre\u003e\n\nAfter running code we can see the result.\n\n\u003cimg src=\"https://raw.github.com/l0gg3r/LGBluetooth/master/Screenshots/5.PNG\" width=\"320\" height=\"480\"\u003e\u003cbr\u003e\n\nIn this example I'm scanning peripherals for 4 seconds.\nAfter which I am passing first peripheral to test method.\n\nTest method connects to peripheral, discoveres services, discoveres characteristics of \"5ec0\" service.\nAfter which reads \"f045\", \"8fdb\", and writes 0xFF to \"cef9\" and disconnects from peripheral.\n\nHere is the log from console \n\u003cpre\u003e\nConnection with error - (null)\nService discovered - Battery\nService discovered - Current Time\nService discovered - Unknown (5ec0)\nCharacteristic discovered - Unknown (cef9)\nCharacteristic discovered - Unknown (f045)\nCharacteristic discovered - Unknown (8fdb)\nCharacteristic - Unknown (cef9) wrote with error - (null)\nCharacteristic - Unknown (f045) value - 1234567890 error - \nCharacteristic - Unknown (8fdb) value - 11111111111 error - (null)\nDisconnect with error - (null)\n\u003c/pre\u003e\n\n\u003ch2\u003eAlternative use\u003c/h2\u003e\n\nYou can make basic read/write via LGUtils class.\nNote : This methods do NOT need active connection to peripheral,\nthey will open a connection if it doesn't exists.\n\nRead example\n\u003cpre\u003e\n        [LGUtils readDataFromCharactUUID:@\"f045\"\n                             serviceUUID:@\"5ec0\"\n                              peripheral:peripheral\n                              completion:^(NSData *data, NSError *error) {\n                                  NSLog(@\"Data : %s Error : %@\", (char *)[data bytes], error);\n                              }];\n\u003c/pre\u003e\n\nWrite example\n\u003cpre\u003e\n        int8_t dataToWrite = 0xFF;\n        [LGUtils writeData:[NSData dataWithBytes:\u0026dataToWrite length:sizeof(dataToWrite)]\n               charactUUID:@\"cef9\"\n               serviceUUID:@\"5ec0\"\n                peripheral:peripheral completion:^(NSError *error) {\n                    NSLog(@\"Error : %@\", error);\n                }];\n\n\u003c/pre\u003e\n\n\u003ch2\u003eReasons of using LGBluetooth\u003c/h2\u003e\nAs we know CoreBluetooth is very hard to use - \nThe methods of objects in Core bluetooth are messy\n\nFor example connectPeripheral:options: is written in CBCentralManager,\ndiscoverCharacteristics:forService is written in Peripheral,\nwriteValue:forCharacteristic:type, readValueForCharacteristic are also in Peripheral\n\nThis messy code makes CoreBluetooth development really painfull.\nFor example if you need to read characteristic value, you need to call \"connect\" on central object, wait for Central delegate callback,\nAfter that call \"discover services\", wait peripheral delegate callback, \"discover characteristic\" which you planned and wait for delegate callback, \"readValue\" and again wait for delegate callback.\nWhat will happen if your program will make 2 connections at once?\nHandling such cases makes messy code, and raises hundred of bugs.\n\nDon't worry, now you can forgot about that hell - LGBluetooth uses blocks for callbacks, you can start using modern code and hierarchical calls.\n\n\n### Installation with CocoaPods\n\n[CocoaPods](http://cocoapods.org) is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries installation in your projects.\n\n#### Podfile\n\n```ruby\npod \"LGBluetooth\", \"~\u003e 1.1.5\"\n```\n\n\u003ch2\u003eLICENSE\u003c/h2\u003e\nLGBluetooth is under MIT License (see LICENSE file)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLGBluetooth%2FLGBluetooth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FLGBluetooth%2FLGBluetooth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLGBluetooth%2FLGBluetooth/lists"}