Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Owntracks webhooks iOS getting 400 response #18927

Closed
w1ll1am23 opened this issue Dec 2, 2018 · 22 comments · Fixed by #19220
Closed

Owntracks webhooks iOS getting 400 response #18927

w1ll1am23 opened this issue Dec 2, 2018 · 22 comments · Fixed by #19220

Comments

@w1ll1am23
Copy link
Contributor

Home Assistant release with the issue:

0.83.2

Last working Home Assistant release (if known):
0.82 (Pre integration setup)

Operating environment (Hass.io/Docker/Windows/etc.):

Docker on Ubuntu 18.04

Component/platform:

https://www.home-assistant.io/components/owntracks/

Description of problem:
Owntracks not reporting location for iOS devices. The follow error is reported in the owntracks app

error The operation couldn't be completed (HTTP Response error 400.) {}

Problem-relevant configuration.yaml entries and (fill out even if it seems unimportant):

owntracks:

Traceback (if applicable):

2018-12-02 11:30:42 WARNING (MainThread) [homeassistant.components.owntracks] Set a username in Connection -> Identification
2018-12-02 11:30:44 INFO (MainThread) [homeassistant.components.http.view] Serving /api/webhook/[REDACTED] to 192.168.X.X (auth: False)

Additional information:
Currently being discussed by multiple users here https://community.home-assistant.io/t/owntracks-http-error-400/82202

I am also using Android and it is working perfectly.

@montagp
Copy link

montagp commented Dec 2, 2018

I'm seeing the exact same problem.

@montagp
Copy link

montagp commented Dec 2, 2018

I should add that when I go into Configuration -> Integration -> Owntracks: Owntracks it tells me that "This integration has no devices.". This is after running the Owntracks "Setting up a new integration". Not sure if this has something to do with it and I should be seeing a device here.

@montagp
Copy link

montagp commented Dec 2, 2018

I played around with it and I put my username at the end of the URL after the @ symbol. This seemed to work:

https://my IP address:8123/api/webhook/my key@paul

@ryannazaretian
Copy link
Contributor

Same issue here. Dug into the Python, and might have some clues for the code owner.

This is what is being supplied in header:
<CIMultiDictProxy('Host': '<redacted>', 'X-Forwarded-For': '192.168.1.1', 'Connection': 'close', 'Content-Length': '439', 'Content-Type': 'application/json', 'User-Agent': 'OwnTracks/9.9.3 CFNetwork/975.0.3 Darwin/18.2.0', 'Accept': '*/*', 'Accept-Language': 'en-us', 'Accept-Encoding': 'br, gzip, deflate', 'Authorization': 'Basic <redacted>==')>

This header is in response to some other data not being present:
if 'topic' not in message:

Sure enough, 'topic' is not in message:
{'_type': 'encrypted', 'data': '<redacted>'}

@mwegner
Copy link
Contributor

mwegner commented Dec 3, 2018

I hit this same issue. Looks like the OwnTracks component is expecting to find the X-Limit-U and X-Limit-D headers: https://github.com/home-assistant/home-assistant/blob/9aeb4892823ca95a2518dcabc915fc61582f96df/homeassistant/components/owntracks/__init__.py#L128

My Home Assistant install sits behind an nginx reverse proxy, so those headers weren't coming in. The nginx example config for the OwnTracks Recorder project has this pointer:

# Optionally force Recorder to use username from Basic
# authentication user. Whether or not client sets
# X-Limit-U and/or uses ?u= parameter, the user will
# be set to $remote_user.
proxy_set_header        X-Limit-U $remote_user;

That's enough to work here, but then I just get device_tracker.matthew_matthew, since the OwnTracks HA component falls back to user for device name.

The Recorder documentation expects this for their own stuff (this isn't integrated with Home Assistant, but it's how they're handling their own HTTP communication):

The OwnTracks Recorder supports HTTP mode out of the box, as long as it is built with HTTP support and a --http-port is configured. When using the Recorder, the URL you specify in the app's configuration must include parameters for username and devicename (?u=user&d=device), alternatively using the X-Limit-U and X-Limit-D headers respectively. You can also force username using a proxy as described in the Recorder's documentation.

So I ended up mimicking that, with this in my nginx config:

proxy_set_header        X-Limit-U $arg_u;
proxy_set_header	X-Limit-D $arg_d;

And then appending ?u=matthew&d=myphonename to my webhook URL. This shows up fine.

But the recent changes do seem to be missing some piping. I'm not very familiar with the configuration/integration internals, but I kind of expect I would generate a unique webhook per name/device pair I wanted to track, and simply paste that in along with the libsodium key.

Failing that, changing away from basic authentication for username to the OwnTracks convention of username/device in the GET string is probably more resilient to reverse proxy setups.

@raccettura
Copy link
Contributor

I think I'm having the same issues as this ticket. I added

proxy_set_header        X-Limit-U $arg_u;
proxy_set_header	X-Limit-D $arg_d;

Then ?u=raccettura&d=iphone

That resulted in a 200 response code from the webhook (improvement!) however I'm still not seeing HomeAssistant see a device, going into the integration shows no device and I don't see any device being tracked.

@JPM-git
Copy link

JPM-git commented Dec 3, 2018

After a few tries i got it working with the help of the android app.

How to get it to work? trackerID=UserID

Works like a charm (but you only have 2 letters)

PS: But none of the devices (IOS or Android) show up on integration or report the position to one another

@filikun
Copy link

filikun commented Dec 6, 2018

How did you get it to work just by having the same two letters in trackerID and UserID? Mine still just error 400 and in HA "Set a username in Connection -> Identification"

@balloob
Copy link
Member

balloob commented Dec 7, 2018

During testing, iOS did report topic as part of the message payload. The headers are sent by the Android app.

@balloob
Copy link
Member

balloob commented Dec 7, 2018

Could people report if setting tracker ID will result in the topic being set ? Note that making any changes won't flush the old messages that iOS has queued up, so you might not see results right away.

@balloob
Copy link
Member

balloob commented Dec 7, 2018

OwnTracks 9.5.7, Release date 2017-06-17:

  • [NEW] topic in HTTP json payload

https://github.com/owntracks/ios/blob/master/CHANGELOG.md#owntracks-957

@arsaboo
Copy link
Contributor

arsaboo commented Dec 7, 2018

I do have tracker ID set on my OT app.

@raccettura
Copy link
Contributor

I've got it set as well. Is there a way to dump/debug the payload?

@balloob
Copy link
Member

balloob commented Dec 8, 2018

Nothing built in but you can add a print(message) inside handle_webhook

@raccettura
Copy link
Contributor

@balloob I was able to intercept communications through nginx... turned off encryption and here's what i got:

{"batt":98,"lon":-00.0000,"acc":65,"p":1.12345,"vac":10,"lat":99.999,"topic":"owntracks\/raccettura\/XXXXXXXX-XXXX-XXXXX-XXXX-XXXXXXXXXX","t":"u","conn":"w","tst":1544374907,"alt":6,"_type":"location","tid":"1"}

@balloob
Copy link
Member

balloob commented Dec 10, 2018

@raccettura yeah, so you have a topic set, so yours works :) the integration tab does indeed not show any devices yet, that's for the future. You should see the device in known_devices.yaml.

@balloob
Copy link
Member

balloob commented Dec 10, 2018

In 0.84 I've made a change that we report to OwnTracks message processed correctly if it was incorrect. That will cause OwnTracks to drop it from their queue, giving room for new messages with topic to be correct.

@balloob
Copy link
Member

balloob commented Dec 10, 2018

84 beta 3 will include this fix.

@raccettura
Copy link
Contributor

There's no new device in known_devices.yaml, and I don't see anything in MQTT, so I don't think it's working. MQTT is setup. I'm using it for temp/humidity via rtl433, so I know it's working.

@balloob
Copy link
Member

balloob commented Dec 10, 2018

Okay @raccettura, looks like you are in the wrong issue. This is an OwnTracks issue about using it via HTTP and webhooks.

@raccettura

This comment has been minimized.

@raccettura

This comment has been minimized.

@ghost ghost removed the in progress label Dec 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants