mtrudel / hap Goto Github PK
View Code? Open in Web Editor NEWA HomeKit Accessory Protocol (HAP) Implementation for Elixir
License: MIT License
A HomeKit Accessory Protocol (HAP) Implementation for Elixir
License: MIT License
Hi,
I updated my dependencies in a Nerves project where I am using HAP successfully.
With the update it also upgraded 'ThousandIlands
and Bandit
, now in my nerves device Bandit
crashes with
05:39:15.703 [error] GenServer #PID<0.2062.0> terminating
** (KeyError) key :opts not found in: %{plug: {HAP.HTTPServer, []}}
(bandit 0.7.5) lib/bandit/http1/handler.ex:18: Bandit.HTTP1.Handler.handle_data/3
(hap 0.4.7) /Users/herman/Projects/garage/deps/thousand_island/lib/thousand_island/handler.ex:343: HAP.HAPSessionHandler.handle_info/2
(stdlib 4.3) gen_server.erl:1123: :gen_server.try_dispatch/4
(stdlib 4.3) gen_server.erl:1200: :gen_server.handle_msg/6
(stdlib 4.3) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
Last message: {:tcp, #Port<0.307>, <<80, 79, 83, 84, 32, 47, 112, 97, 105, 114, 45, 118, 101, 114, 105, 102, 121, 32, 72, 84, 84, 80, 47, 49, 46, 49, 13, 10, 72, 111, 115, 116, 58, 32, 72, 101, 114, 109, 97, 110, 39, 115, 92, 48, 51, 50, 71, ...>>}
State: {%ThousandIsland.Socket{socket: #Port<0.307>, transport_module: HAP.HAPSessionTransport, read_timeout: 60000, span: %ThousandIsland.Telemetry{span_name: :connection, telemetry_span_context: #Reference<0.3405112061.268435457.195241>, start_time: 1779255243708, start_metadata: %{parent_telemetry_span_context: #Reference<0.3405112061.268435457.182629>, remote_address:
{192, 168, 17, 65}, remote_port: 60529, telemetry_span_context: #Reference<0.3405112061.268435457.195241>}}}, %{plug: {HAP.HTTPServer, []}}}
I tried with the current master version, where I noticed you updated the child spec for Bandit, and that works.
Could you please release a new version?
Thanks,
Herman
This is a long term issue tracking which services are implemented:
(the number in parenthesis is a quick count of the characteristics used by the service)
The Outlet service has a required on
characteristic which is labelled as type bool
.
In my testing it received all of these values, 0
1
false
to the put_value/2
on my accessory.
I have a simple implementation of an outlet which here
Steps
CEC_ADDRESS=0 iex -S mix
put_value(0 | 1, :on)
put_value(false, :on)
will be called.Hi,
I am trying to use this library, but I am unable to pair with the Apple Home app on the iPhone. I followed the demo code. First, if I use the latest hex.pm package (0.4.8), ThousandIsland refuses to start because HAP.HAPSessionTransport.sockname/1 is undefined or private
. I noticed this was fixed in the recent commits, so I used the git repo in mix.exs
instead.
Now, when I try to pair, Apple Home does request details (as visible in the console), but the HAP.PairSetup
GenServer crashes due to bad IV length.
Here are the logs:
12:42:54.688 [info] POST /pair-setup
12:42:54.698 [info] Sent 200 in 9ms
12:42:54.751 [info] POST /pair-setup
12:42:54.752 [info] Sent 200 in 1ms
12:42:54.758 [info] POST /pair-setup
12:42:54.761 [error] GenServer HAP.PairSetup terminating
** (stop) {:badarg, {~c"aead.c", 111}, ~c"Bad IV length"}
(crypto 5.2) crypto.erl:1023: :crypto.crypto_one_time_aead(:chacha20_poly1305, <<140, 134, 89, 123, 121, 178, 138, 33, 27, 220, 164, 31, 200, 248, 154, 52, 178, 117, 38, 128, 158, 119, 53, 41, 228, 79, 0, 123, 2, 90, 19, 142>>, "PS-Msg05", <<142, 52, 148, 112, 87, 220, 56, 54, 225, 232, 91, 209, 194, 240, 6, 138, 18, 142, 101, 140, 36, 61, 108, 156, 5, 170, 90, 213, 64, 203, 101, 216, 34, 224, 19, 185, 58, 129, 84, 154, 58, 171, 121, 190, 205, 111, 10, 141, 32, 5, ...>>, "", <<151, 111, 233, 169, 209, 103, 60, 53, 218, 80, 101, 129, 96, 93, 141, 149>>, false)
(hap 0.4.8) lib/hap/crypto/cha_cha_20.ex:24: HAP.Crypto.ChaCha20.decrypt_and_verify/4
(hap 0.4.8) lib/hap/pair_setup.ex:97: HAP.PairSetup.handle_call/3
(stdlib 5.0.2) gen_server.erl:1113: :gen_server.try_handle_call/4
(stdlib 5.0.2) gen_server.erl:1142: :gen_server.handle_msg/6
(stdlib 5.0.2) proc_lib.erl:241: :proc_lib.init_p_do_apply/3
I tried experimenting with the :crypto.crypto_one_time_aead
function, but every variation I try gives me the same Bad IV Length error, even though the lengths described in the Erlang manual are what I'm using.
I am using a Mac with Elixir installed from brew. I also tried it in a ARM Alpine Linux VM, and it gave the same error.
Erlang/OTP 26 [erts-14.0.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit] [dtrace]
Elixir 1.15.7 (compiled with Erlang/OTP 26)
OpenSSL 3.1.4 24 Oct 2023 (Library: OpenSSL 3.1.4 24 Oct 2023)
I'm guessing I'm doing something wrong, or there's some recent bug?
Also, slightly off-topic, but I cannot find the HomeKit Accessory Protocol Specification PDF anywhere. Did Apple remove it? Their help pages say it's available for hobbyists, but I can't find it anywhere on their website.
There has been an update to ThousandIsland, I have 0.6.7 and the recent Phoenix update brought in 1.2.0 which causes the HAPSessionTransport to fail to start with:
** (Mix) Could not start application home_hub: HomeHub.Application.start(:normal, []) returned an error: shutdown: failed to start child: HomeHub.HAP.Supervisor
** (EXIT) shutdown: failed to start child: HAP
** (EXIT) shutdown: failed to start child: {Bandit, #Reference<0.1159261075.658505729.90071>}
** (EXIT) shutdown: failed to start child: :listener
** (EXIT) an exception was raised:
** (UndefinedFunctionError) function HAP.HAPSessionTransport.sockname/1 is undefined or private
(hap 0.4.8) HAP.HAPSessionTransport.sockname(#Port<0.19>)
(thousand_island 1.2.0) lib/thousand_island/listener.ex:34: ThousandIsland.Listener.init/1
(stdlib 5.1.1) gen_server.erl:962: :gen_server.init_it/2
(stdlib 5.1.1) gen_server.erl:917: :gen_server.init_it/6
(stdlib 5.1.1) proc_lib.erl:241: :proc_lib.init_p_do_apply/3
Hi,
I am very impressed with your HAP library.
I added it to an existing nerves project and I can turn on/off my light with my iPhone. Nice!
But I also have another way to turn on the light.
I would like to reflect the current state of the light in my Home app.
Can you tell me how I can do this?
eg, If I turn on the light using put_value
from the console, do I then need to send something, somewhere, somehow?
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.