Bluetooth mesh messaging SDK for apps
Berkanan SDK enables Bluetooth mesh messaging between nearby apps. It’s the framework used by Berkanan Messenger (Product Hunt, TechCrunch) and Berkanan Messenger Lite (GitHub).
The goal is to create a decentralized mesh network for the people, powered by their device’s Bluetooth antenna. People could rely on this network for texting in situations, like emergencies, when there’s no other connectivity available — it could literally save lives.
With Berkanan SDK, apps can discover nearby apps, which also have the SDK integrated and Bluetooth turned on, and send them small messages. The range for these messages is about 70 meters, but they can reach further because the SDK automatically resends them upon receiving. The more apps use Berkanan SDK, the further the reach of the messages gets.
Berkanan SDK does not send the messages to any central server or company.
To integrate Berkanan SDK into your iOS app, use Xcode 11 or later. Open the .xcodeproj or .xcworkspace file of your app and follow these steps.
Select your app target and then go to Editor
/ Add Capability
/ Background Modes
. Check both Uses Bluetooth LE accessories
and Acts as a Bluetooth LE accessory
.
Go to Signing & Capabilities
/ App Sandbox
and check the Bluetooth
checkbox.
Add NSBluetoothAlwaysUsageDescription
and NSBluetoothPeripheralUsageDescription
to the Info.plist with the value:
Allow access to the Berkanan Bluetooth Service to be able to communicate even while offline.
Go to File
/ Swift Packages
/ Add Package Dependency...
and enter https://github.com/zssz/BerkananSDK.git
Add @import BerkananSDK
to your source files where needed.
let configuration = Configuration(
// The identifier is used to identify what kind of configuration the service has.
// It should be the same across app runs.
identifier: UUID(uuidString: "3749ED8E-DBA0-4095-822B-1DC61762CCF3")!,
userInfo: "My User Info".data(using: .utf8)!
)
// Throws if the configuration is too big or invalid.
let localService = try BerkananBluetoothService(configuration: configuration)
localService.start()
let discoverServiceCanceller = localService.discoverServiceSubject
.receive(on: RunLoop.main)
.sink { remoteService in
print("Discovered \(remoteService) with \(remoteService.getConfiguration())")
}
let message = Message(
// The payloadType is used to identify what kind of payload the message carries.
payloadType: UUID(uuidString: "E268F3C1-5ADB-4412-BE04-F4A04F9B3D1A")!,
payload: "Hello, World!".data(using: .utf8)
)
// Throws if the message is too big or invalid.
try localService.send(message)
let receiveMessageCanceller = localService.receiveMessageSubject
.receive(on: RunLoop.main)
.sink { message in
print("Received \(message.payloadType) \(message.payload)")
}
localService.stop()
To see how Berkanan Messenger Lite app integrates Berkanan SDK, check out its source code.