https://github.com/nordicsemiconductor/ios-memfault-library
nRF Memfault Library + Example App
https://github.com/nordicsemiconductor/ios-memfault-library
ble bluetooth bluetooth-low-energy ios macos memfault nordic nordic-bluetooth nordic-semiconductor nordicsemi
Last synced: about 1 month ago
JSON representation
nRF Memfault Library + Example App
- Host: GitHub
- URL: https://github.com/nordicsemiconductor/ios-memfault-library
- Owner: NordicSemiconductor
- Created: 2022-08-02T12:43:37.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-12-15T12:00:33.000Z (over 1 year ago)
- Last Synced: 2025-04-05T13:51:23.975Z (2 months ago)
- Topics: ble, bluetooth, bluetooth-low-energy, ios, macos, memfault, nordic, nordic-bluetooth, nordic-semiconductor, nordicsemi
- Language: Swift
- Homepage:
- Size: 2.82 MB
- Stars: 9
- Watchers: 4
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# iOS nRF Memfault Library + Example App
A Swift-based library for iOS/iPadOS/macOS can connects to a Bluetooth LE device supporting the Memfault Diagnostic Service, downloads data Chunks and uploads them to [the Memfault Console](https://docs.memfault.com).
The device is expected to support the Memfault Diagnostic Service, [as defined here](https://memfault.notion.site/Memfault-Diagnostic-GATT-Service-MDS-ffd5a430062649cd9bf6edbf64e2563b).
# Library
## Minimum OS Requirements
* iOS: 15.0
* macOS: 12.0In all cases, **the Library requires an active Internet connection**. If an Error is encountered when uploading a Chunk of Data, **the BLE connection to the device will be dropped immediately** to ensure the least amount of Chunks of Data are lost.
## Basic Usage
```swift
let memfaultManager = MemfaultManager()
// Connects to the Device and begins automagically streaming / uploading data.
await memfaultManager.connect(to: device)// To stop / disconnect.
await memfaultManager.disconnect(from: device)
```Memfault's APIs take a `BluetoothDevice`, which is a very simple protocol requiring only the UUID String of a Device. A `CBPeripheral` extension is provided as part of the library, so you're free to pass-in your scanned `CBPeripheral` with no issues.
## Advanced Usage
It is possible to listen to all state changes & errors as they occur from the Memfault Library, like so:
```swift
let memfaultManager = MemfaultManager()
let connectionStream = await memfaultManager.connect(to: device)
do {
for try await newEvent in connectionStream {
switch newEvent.event {
// Logic for each Event.
}
}
} catch {
// Error handling.
}// Disconnect when needed.
await memfaultManager.disconnect(from: device)
```Furthermore, it's also possible to manually ask the framework to upload a specific Chunk if an error were to happen:
```swift
try await memfaultManager.upload(chunk, with: chunkAuth)
```This requires passing-in the `MemfaultChunkAuth` struct, which is received through an autentication event from the connection stream (`AsyncSequence`).
# Example App
The aforementioned Advanced Usage is what enables a UI-based app to inform the user of what the underlying Memfault Library is doing, as well as providing manual control of connection / disconnection and forcing a Memfault Chunk of Data to be uploaded in case an error occurs.