Skip to content

Commit

Permalink
Reorganise readme and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Bouke committed Jun 7, 2020
1 parent 9996ec4 commit 0fb2987
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 120 deletions.
18 changes: 17 additions & 1 deletion .jazzy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,30 @@ module: HAP
author: Bouke Haarsma
author_url: https://boukehaarsma.nl
theme: fullwidth
clean: true
output: .docs
clean: yes
github_url: https://github.com/Bouke/HAP
github_file_prefix: https://github.com/Bouke/HAP/tree/master
dash_url: http://boukehaarsma.nl/HAP/HAP.xml
documentation: docs/*.md
abstract: docs/api/*.md
swift_build_tool: spm
hide_documentation_coverage: yes
hide_unlisted_documentation: yes
custom_categories:
- name: Documentation
children:
- Getting Started
- Usage
- Create an Accessory
- Design
- Development
- name: Server
children:
- Device
- DeviceDelegate
- PairingState
- PairingStateError
- Server
- QRCode
- name: Accessory
Expand All @@ -30,6 +45,7 @@ custom_categories:
- CharacteristicType
- CharacteristicUnit
- CharacteristicValueType
- PredefinedCharacteristic
- name: Characteristic Enums
children:
- Enums
Expand Down
125 changes: 6 additions & 119 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,126 +23,13 @@ Remember that this is not a commercial product, but the result of free labor.
- If you found a bug, open an issue here on GitHub. The more detail the better!
- If you want to contribute, submit a pull request.

## Getting Started
## Contents

### MacOS

Install libsodium (used for Curve25519 and Ed25519):

brew install libsodium

And then build and run the project itself, specifying a release build for good performance:

swift run -c release hap-server

### Linux

Install dependencies:

sudo apt install openssl libssl-dev libsodium-dev libcurl4-openssl-dev libavahi-compat-libdnssd-dev

Make sure you have libsodium 1.0.9 or above. Ubuntu 16.10 or later suffices. Otherwise you have to compile and install libsodium from source:

wget https://download.libsodium.org/libsodium/releases/libsodium-1.0.12.tar.gz
tar xzf libsodium-1.0.12.tar.gz
cd libsodium-1.0.12
./configure
make && make check
sudo make install
sudo ldconfig

And then build the project itself, specifying a release build for good performance:

swift run -c release hap-server

## Raspberry Pi (Raspbian Stretch)

There are currently no official binaries from swift.org targetting ARM / Raspbian, however there's an active community working on Swift on ARM. You can [install binaries from their repository][1]:

curl -s https://packagecloud.io/install/repositories/swift-arm/release/script.deb.sh | sudo bash
sudo apt install swift5

## Usage

Modify `Sources/hap-server/main.swift` to include your own accessories, or import the _HAP_ library into your own project.

On Mac OS, you can debug using XCode by running the command `swift package generate-xcodeproj` and the opening the resulting `HAP.xcodeproj` project. Select and run the `hap-server` target.

## Extensibility

The following code snippet how you would model a fictious accessory
representing a mobile power bank.

```swift
class PowerBankAccessory: Accessory {
let service = PowerBankService()
init(info: Service.Info) {
super.init(info: info, type: .outlet, services: [service])
}
}
class PowerBankService: Service {
public let on = GenericCharacteristic<Bool>(
type: .on,
value: false)
public let inUse = GenericCharacteristic<Bool>(
type: .outletInUse,
value: true,
permissions: [.read, .events])
public let batteryLevel = GenericCharacteristic<Double>(
type: .batteryLevel,
value: 100,
permissions: [.read, .events])

init() {
super.init(type: .outlet, characteristics: [
AnyCharacteristic(on),
AnyCharacteristic(inUse),
AnyCharacteristic(batteryLevel)
])
}
}
```

- See also: [My Home](https://github.com/Bouke/My-Home/tree/master/Sources)

## Object-Oriented Design

A high-level overview of the objects involved are shown in the diagram below.
The terminology of HAP (Device, Accessory, Service, Characteristic) is
followed for ease of understanding.

+------------+
| NetService |
+------------+
|
| delegate
v
+--------+ 1 0…1 +--------+ * * +---------------------+
| Device |-----------| Server |-------| Controller (iPhone) |
+--------+ +--------+ +---------------------+
| 1 * /
| * /
+-----------+ /
| Accessory | /
+-----------+ /
| 1 / > read, events
| * / < write, subscribe
+---------+ /
| Service | /
+---------+ /
| 1 /
| * * /
+----------------+
| Characteristic |
+----------------+

## Development

### Running tests

Certain tests involve crypto, which can be a bit slow in debug builds. Best to run the tests with a release build, like this:

swift test -c release -Xswiftc -enable-testing
- [Getting Started](https://boukehaarsma.nl/HAP/getting-started.html)
- [Usage](https://boukehaarsma.nl/HAP/usage.html)
- [Create an Accessory](https://boukehaarsma.nl/HAP/create-an-accessory.html)
- [Design](https://boukehaarsma.nl/HAP/design.html)
- [Development](https://boukehaarsma.nl/HAP/development.html)

## Credits

Expand Down
35 changes: 35 additions & 0 deletions docs/Create an Accessory.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Create an Accessory
===================

The following code snippet how you would model a fictious accessory
representing a mobile power bank.

```swift
class PowerBankAccessory: Accessory {
let service = PowerBankService()
init(info: Service.Info) {
super.init(info: info, type: .outlet, services: [service])
}
}
class PowerBankService: Service {
public let on = GenericCharacteristic<Bool>(
type: .on,
value: false)
public let inUse = GenericCharacteristic<Bool>(
type: .outletInUse,
value: true,
permissions: [.read, .events])
public let batteryLevel = GenericCharacteristic<Double>(
type: .batteryLevel,
value: 100,
permissions: [.read, .events])

init() {
super.init(type: .outlet, characteristics: [
AnyCharacteristic(on),
AnyCharacteristic(inUse),
AnyCharacteristic(batteryLevel)
])
}
}
```
35 changes: 35 additions & 0 deletions docs/Design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Design
======

## Object-Oriented Design

A high-level overview of the objects involved are shown in the diagram below.
The terminology of HAP (Device, Accessory, Service, Characteristic) is
followed for ease of understanding.

```
+------------+
| NetService |
+------------+
|
| delegate
v
+--------+ 1 0…1 +--------+ * * +---------------------+
| Device |-----------| Server |-------| Controller (iPhone) |
+--------+ +--------+ +---------------------+
| 1 * /
| * /
+-----------+ /
| Accessory | /
+-----------+ /
| 1 / > read, events
| * / < write, subscribe
+---------+ /
| Service | /
+---------+ /
| 1 /
| * * /
+----------------+
| Characteristic |
+----------------+
```
10 changes: 10 additions & 0 deletions docs/Development.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Development
===========

## Running tests

Certain tests involve crypto, which can be a bit slow in debug builds. Best to run the tests with a release build, like this:

```
swift test -c release -Xswiftc -enable-testing
```
41 changes: 41 additions & 0 deletions docs/Getting Started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Getting Started
===============

## Installing dependencies

### macOS
On macOS this package depends on libsodium to provide certain crypto algorithms. Install it using homebrew:
```
brew install libsodium
```

### Linux
On Debian based Linux distributions you need a few packages. Install them using apt:
```
sudo apt install openssl libssl-dev libsodium-dev libcurl4-openssl-dev libavahi-compat-libdnssd-dev
```

If your package manager doesn't provide libsodium 1.0.9 or higher, install it from source:
```
wget https://download.libsodium.org/libsodium/releases/libsodium-1.0.12.tar.gz
tar xzf libsodium-1.0.12.tar.gz
cd libsodium-1.0.12
./configure
make && make check
sudo make install
sudo ldconfig
```

### Linux ARM / Raspberry Pi (Raspbian Stretch)
There are currently no official binaries from swift.org targetting ARM / Raspbian, however there's an active community working on Swift on ARM. You can [install binaries from their repository][1]:

```
curl -s https://packagecloud.io/install/repositories/swift-arm/release/script.deb.sh | sudo bash
sudo apt install swift5
```

## First run
Now that you have all the dependencies installed, you should be able to build and run the project. For optimal performance, use a release build:
```
swift run -c release hap-server
```
8 changes: 8 additions & 0 deletions docs/Usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Usage
=====

Modify `Sources/hap-server/main.swift` to include your own accessories, or import the _HAP_ library into your own project.

On Mac OS, you can debug using XCode by running the command `swift package generate-xcodeproj` and the opening the resulting `HAP.xcodeproj` project. Select and run the `hap-server` target.

- See also: [My Home](https://github.com/Bouke/My-Home/tree/master/Sources)
1 change: 1 addition & 0 deletions docs/api/Server.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use the `Device` instance to manage the setup code, accessories and controller pairings. You can assign a delegate to be notified of certain events. The `Server` manages IP connectivity and network discovery advertisements.

0 comments on commit 0fb2987

Please sign in to comment.